aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/testing_spec.moon
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-02-05 10:11:13 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commitc484cce5ab1f6acd14ecad30adb586a6d5fa0fd1 (patch)
treea45c702a83e150fea5b14b279e5f0cab9b65bc3e /spec/lib/testing_spec.moon
parentexamples: more smoothing in love example :) (diff)
downloadalive-c484cce5ab1f6acd14ecad30adb586a6d5fa0fd1.tar.gz
alive-c484cce5ab1f6acd14ecad30adb586a6d5fa0fd1.zip
rearrange spec, fix for Lua 5.1
Diffstat (limited to 'spec/lib/testing_spec.moon')
-rw-r--r--spec/lib/testing_spec.moon80
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/lib/testing_spec.moon b/spec/lib/testing_spec.moon
new file mode 100644
index 0000000..5be7848
--- /dev/null
+++ b/spec/lib/testing_spec.moon
@@ -0,0 +1,80 @@
+import TestPilot from require 'spec.test_setup'
+import T, Array, Constant from require 'alv'
+
+describe "testing", ->
+ test = TestPilot '', '(import* testing logic)\n'
+
+ describe "assert", ->
+ it "ignores true", ->
+ with COPILOT\eval_once '(assert true)'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ with COPILOT\eval_once '(assert true "with message")'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ it "throws on false", ->
+ assert.has.error -> COPILOT\eval_once '(assert false)'
+
+ it "shows failing expression", ->
+ err = assert.has.error -> COPILOT\eval_once '(assert false)'
+ assert.matches "assertion failed: false", err
+
+ err = assert.has.error -> COPILOT\eval_once '(assert (== 1 2))'
+ assert.matches "assertion failed: %(== 1 2%)", err
+
+ it "supports custom error messages", ->
+ err = assert.has.error -> COPILOT\eval_once '(assert (== "green" "red") "duck isnt green")'
+ assert.matches "duck isnt green", err
+
+ describe "expect=", ->
+ it "passes equal params", ->
+ with COPILOT\eval_once '(expect= 1 1 1)'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ with COPILOT\eval_once '(expect= 2 2 2)'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ with COPILOT\eval_once '(expect= true true)'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ with COPILOT\eval_once '(expect= "hello" "hello")'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ with COPILOT\eval_once '(expect= (array 1 2) (array 1 2))'
+ assert.is.true \is_const!
+ assert.is.nil .result
+
+ it "fails different values", ->
+ assert.has.error -> COPILOT\eval_once '(expect= 1 2)'
+ assert.has.error -> COPILOT\eval_once '(expect= 1 1 2)'
+ assert.has.error -> COPILOT\eval_once '(expect= 2 1 1)'
+
+ assert.has.error -> COPILOT\eval_once '(expect= true false)'
+
+ assert.has.error -> COPILOT\eval_once '(expect= "asdf" "bsdf")'
+ assert.has.error -> COPILOT\eval_once '(expect= (array 1 2) (array 1 3))'
+
+ it "fails different types", ->
+ assert.has.error -> COPILOT\eval_once '(expect= true 2)'
+ assert.has.error -> COPILOT\eval_once '(expect= true true 1)'
+ assert.has.error -> COPILOT\eval_once '(expect= true false "str")'
+
+ it "reports first failing arguments", ->
+ err = assert.has.error -> COPILOT\eval_once '(expect= 1 2)'
+ assert.matches "assertion error: Expected 2 to equal <num= 1> %(got <num= 2>%)", err
+
+ err = assert.has.error -> COPILOT\eval_once '(expect= 1 1 2 4)'
+ assert.matches "assertion error: Expected 2 to equal <num= 1> %(got <num= 2>%)", err
+
+ err = assert.has.error -> COPILOT\eval_once '(expect= true 2 3)'
+ assert.matches "assertion error: Expected 2 to equal <bool= true> %(got <num= 2>%)", err
+
+ it "reports full expressions", ->
+ err = assert.has.error -> COPILOT\eval_once '(import* math) (expect= 1 (+ 1 1))'
+ assert.matches "assertion error: Expected %(%+ 1 1%) to equal <num= 1> %(got <num= 2>%)", err