From 47a6489f2b03a0b95abff5bf6a153de10a22029b Mon Sep 17 00:00:00 2001 From: Karina Moreira Date: Thu, 12 Dec 2024 17:13:22 -0300 Subject: [PATCH 1/2] Defflow to report mismatches --- samples/tutorial.clj | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/samples/tutorial.clj b/samples/tutorial.clj index de59faf..30d1c66 100644 --- a/samples/tutorial.clj +++ b/samples/tutorial.clj @@ -1,5 +1,5 @@ (ns state-flow.presentation - (:require [state-flow.api :as api :refer [flow match?]])) + (:require [state-flow.api :as api :refer [flow match? defflow]])) """ The primitive steps @@ -58,17 +58,50 @@ Bindings Tests (match? ) + +(defflow [parameters] ) """ -(def with-assertions - (flow "with assertions" - inc-value - [value get-value] - (match? 5 value) +(def with-matching-assertion + (flow "truthy assertion" + inc-value + [value get-value] + (match? 5 value))) + (api/run with-matching-assertion {:value 4}) +; => [{:match/result :match ...}] + +(def with-mismatched-assertion + (flow "falsy assertion" + inc-value + [value get-value] + (match? 6 value))) + (api/run with-mismatched-assertion {:value 4}) +; => [{:match/result :mismatch ...}] + +(def with-matching-and-mismatched-assertions + (flow "falsy assertion before truthy ones" + inc-value + [value get-value] + (match? 0 value) ; mismatch + + inc-value + [value get-value] + (match? 6 value) ; match + + inc-value + [world (api/get-state identity)] + (match? {:value 7} world))) ; match +(api/run with-matching-and-mismatched-assertions {:value 4}) +; => [{:match/result :match ...}] + +(defflow my-test + {:init (constantly {:value 4})} + with-matching-and-mismatched-assertions) + +(comment + (my-test) + ; actual: (mismatch (expected 0) (actual 5)) + ) - inc-value - [world (api/get-state identity)] - (match? 7 get-value))) -(api/run with-assertions {:value 4}) """ Asynchronous tests From d39dfe324a5c1689a305a4fef172a085eed38fd2 Mon Sep 17 00:00:00 2001 From: Karina Moreira Date: Thu, 12 Dec 2024 18:50:29 -0300 Subject: [PATCH 2/2] Links to learning materials --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1a2132a..3bba392 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ StateFlow is a testing framework designed to support the composition and reuse of individual test steps. +## Learning Materials +- [Tutorial](./samples/tutorial.clj) +- [Walkthrough](./doc/walkthrough.repl) + ## Definitions * A [*flow*](#flows) is a sequence of steps or bindings.