Added some examples on how to specify estap tests.
authorStanislaw Klekot <dozzie@jarowit.net>
Mon, 15 Jun 2015 23:19:41 +0000 (01:19 +0200)
committerStanislaw Klekot <dozzie@jarowit.net>
Mon, 15 Jun 2015 23:19:41 +0000 (01:19 +0200)
examples/00_running.t [new file with mode: 0644]
examples/01_planned.t [new file with mode: 0644]
examples/02_unplanned.t [new file with mode: 0644]
examples/03_subtests.t [new file with mode: 0644]

diff --git a/examples/00_running.t b/examples/00_running.t
new file mode 100644 (file)
index 0000000..ca5c7f8
--- /dev/null
@@ -0,0 +1,8 @@
+#!bin/estap
+
+%% this test will succeed
+-test("test runs as a shee-bang script").
+shee_bang_run() ->
+  ok.
+
+%% vim:ft=erlang
diff --git a/examples/01_planned.t b/examples/01_planned.t
new file mode 100644 (file)
index 0000000..6389191
--- /dev/null
@@ -0,0 +1,21 @@
+#!bin/estap
+
+-plan(4).
+
+-test("first: success").
+first() ->
+  ok.
+
+-test("second: success").
+second() ->
+  ok.
+
+-test("third: failure").
+third() ->
+  error.
+
+-test("fourth: success").
+fourth() ->
+  ok.
+
+%% vim:ft=erlang
diff --git a/examples/02_unplanned.t b/examples/02_unplanned.t
new file mode 100644 (file)
index 0000000..1f206db
--- /dev/null
@@ -0,0 +1,25 @@
+#!bin/estap
+
+-test("first: success").
+first() ->
+  ok.
+
+-test("second: failure").
+second() ->
+  {error, nabla}.
+
+-test("third: success").
+third() ->
+  true.
+
+-test("fourth: success (throw)").
+fourth() ->
+  throw(ok).
+
+-test("fifth: failure (error)").
+fifth() ->
+  A = 1,
+  B = two,
+  A = B.
+
+%% vim:ft=erlang
diff --git a/examples/03_subtests.t b/examples/03_subtests.t
new file mode 100644 (file)
index 0000000..02685ff
--- /dev/null
@@ -0,0 +1,33 @@
+#!bin/estap
+
+-plan(3).
+
+-test("test with sub-plan in advance (some subtests will fail)").
+plan_test() ->
+  estap:plan(10),
+  estap:ok(true, "hardcoded success"),
+  estap:is(true, false, "hardcoded failure"),
+  estap:isnt(true, false, "another success"),
+  estap:eq({1.0, 2.0}, {1, 2}, "cmp (==)"),
+  estap:ne({1.0, 2.1}, {1, 2}, "cmp (/=)"),
+  estap:cmp("foo", '=<', "bar", "=< (not really)"),
+  estap:like("foo", "^f", "regexp match"),
+  estap:unlike("foo", "^[A-Z]+$", "regexp negated match"),
+  estap:matches("foo", fun("foo") -> ok end, "match test (success)"),
+  estap:matches("bar", fun("foo") -> ok end, "match test (failure)"),
+  estap:all_ok().
+
+-test("test with sub-plan in advance (some subtests will fail)").
+no_plan_test() ->
+  estap:ok(true, "hardcoded success"),
+  estap:is(true, false, "hardcoded failure"),
+  estap:all_ok().
+
+-test("test with all successes").
+all_successes() ->
+  estap:ok(ok, "first"),
+  estap:ok({ok, nabla}, "second"),
+  estap:ok(true, "third"),
+  estap:all_ok().
+
+%% vim:ft=erlang