summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/asset/run-fail/bool.et3
-rw-r--r--test/asset/run-success/bool.et7
-rw-r--r--test/asset/run-success/command-ignore.et39
-rw-r--r--test/asset/run/callstack.et23
-rw-r--r--test/asset/run/sysinfo.et12
-rwxr-xr-xtest/asset/run/tools/sysinfo.sh9
-rw-r--r--test/asset/shell/echo.et25
-rw-r--r--test/asset/shell/pipe.et25
-rw-r--r--test/asset/shell/spawn.et13
-rw-r--r--test/script/run.et126
-rw-r--r--test/script/shell.et100
11 files changed, 372 insertions, 10 deletions
diff --git a/test/asset/run-fail/bool.et b/test/asset/run-fail/bool.et
new file mode 100644
index 0000000..1608a08
--- /dev/null
+++ b/test/asset/run-fail/bool.et
@@ -0,0 +1,3 @@
+test Test:
+ node n
+ guard (True == False)
diff --git a/test/asset/run-success/bool.et b/test/asset/run-success/bool.et
new file mode 100644
index 0000000..7121cc0
--- /dev/null
+++ b/test/asset/run-success/bool.et
@@ -0,0 +1,7 @@
+test Test:
+ node n
+ guard (True == True)
+ guard (False == False)
+ guard (False /= True)
+ guard ((1 == 1) == True)
+ guard ((1 == 0) == False)
diff --git a/test/asset/run-success/command-ignore.et b/test/asset/run-success/command-ignore.et
new file mode 100644
index 0000000..dc950d1
--- /dev/null
+++ b/test/asset/run-success/command-ignore.et
@@ -0,0 +1,39 @@
+def expect_next from p (str):
+ expect /(.*)/ from p capture line
+ guard (line == str)
+
+test Test:
+ node n
+ shell on n as p:
+ cat
+
+ send "a" to p
+ send "b" to p
+ send "x" to p
+ expect /x/ from p
+
+ ignore from p matching /a/
+ send "a" to p
+ send "c" to p
+
+ expect_next "b" from p
+ expect_next "c" from p
+
+ send "a" to p
+ send "b" to p
+ with p:
+ send "c"
+ ignore matching /[bcd]/
+ send "d"
+ send "e"
+ expect_next "e" from p
+
+ send "a" to p
+ send "b" to p
+ local:
+ send "c" to p
+ send "d" to p
+
+ expect_next "b" from p
+ expect_next "c" from p
+ expect_next "d" from p
diff --git a/test/asset/run/callstack.et b/test/asset/run/callstack.et
new file mode 100644
index 0000000..9e8123b
--- /dev/null
+++ b/test/asset/run/callstack.et
@@ -0,0 +1,23 @@
+test AG:
+ let x = 1
+ guard (x == 0)
+
+test AE:
+ spawn as p
+ let x = 2
+ expect /$x/ from p timeout 0.0
+
+def fg:
+ let x = 1
+ guard (x == 0)
+
+test BG:
+ fg
+
+def gg (x):
+ let y = 2
+ guard (x == y)
+
+test CG:
+ let z = 3
+ gg (z)
diff --git a/test/asset/run/sysinfo.et b/test/asset/run/sysinfo.et
new file mode 100644
index 0000000..1b9f6aa
--- /dev/null
+++ b/test/asset/run/sysinfo.et
@@ -0,0 +1,12 @@
+test SysInfo:
+ node n
+ spawn on n as p1
+ with p1:
+ send "network-info"
+ expect /ip ${n.ifname} ${n.ip}/
+
+ spawn as p2
+ guard (p2.node.ip /= p1.node.ip)
+ with p2:
+ send "network-info"
+ expect /ip ${n.ifname} ${p2.node.ip}/
diff --git a/test/asset/run/tools/sysinfo.sh b/test/asset/run/tools/sysinfo.sh
new file mode 100755
index 0000000..38591f4
--- /dev/null
+++ b/test/asset/run/tools/sysinfo.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+while read cmd; do
+ case "$cmd" in
+ network-info)
+ ip -o addr show | sed -e 's/[0-9]*: \([a-z0-9]*\).*inet6\? \([0-9a-f:.]*\).*/ip \1 \2/'
+ ;;
+ esac
+done
diff --git a/test/asset/shell/echo.et b/test/asset/shell/echo.et
new file mode 100644
index 0000000..1e48cac
--- /dev/null
+++ b/test/asset/shell/echo.et
@@ -0,0 +1,25 @@
+test Echo:
+ node n
+ let echo_str = "echo"
+ let space_str = "a b"
+
+ shell on n as sh:
+ echo a b c
+ echo "a b c"
+ echo 'a b d'
+ echo a b " c d"
+
+ /bin/echo "abcd" xyz
+ "echo" a"a" "b"c d
+ $echo_str b $echo_str c
+
+ echo "$space_str"
+ echo $space_str
+ echo '$space_str'
+
+ echo \$ \" \\
+ echo "\""\""a"
+ echo "'" '"' '\\\' "\\"
+ echo a\ b\ \ c
+
+ echo \" \' \\ \$ \# \| \> \< \; \[ \] \{ \} \( \) \* \? \~ \& \!
diff --git a/test/asset/shell/pipe.et b/test/asset/shell/pipe.et
new file mode 100644
index 0000000..a00360a
--- /dev/null
+++ b/test/asset/shell/pipe.et
@@ -0,0 +1,25 @@
+test Pipe:
+ node n
+ shell on n as sh:
+ echo abcd | grep -o '[bc]*'
+ echo abcd | grep -o '[bcd]*' | grep -o '[ab]*'
+
+
+test Redirect:
+ node n
+ shell on n as sh:
+ echo a > file
+ echo b > file
+ echo c >> file
+ echo x
+ cat file
+ echo y
+ cat < file
+ echo z
+
+test PipeRedirect:
+ node n
+ shell on n as sh:
+ echo abcdefghi | grep -o '[b-h]*' | grep -o '[a-g]*' > file
+ cat < file | grep -o '[acegi]' | cat > file2
+ cat file2 - < file
diff --git a/test/asset/shell/spawn.et b/test/asset/shell/spawn.et
new file mode 100644
index 0000000..9d48e72
--- /dev/null
+++ b/test/asset/shell/spawn.et
@@ -0,0 +1,13 @@
+test ShellTrue:
+ node n
+ shell on n:
+ true
+
+ shell on n as sh:
+ true
+
+
+test ShellFalse:
+ node n
+ shell on n as sh:
+ false
diff --git a/test/script/run.et b/test/script/run.et
index 103a3e1..dfccab5 100644
--- a/test/script/run.et
+++ b/test/script/run.et
@@ -3,6 +3,13 @@ module run
asset scripts:
path: ../asset/run
+asset scripts_success:
+ path: ../asset/run-success
+
+asset scripts_fail:
+ path: ../asset/run-fail
+
+
test TrivialRun:
spawn as p
with p:
@@ -21,16 +28,49 @@ test TrivialRun:
guard (done == "run-failed")
+test SimpleRun:
+ let should_succeed = [ "bool", "command-ignore" ]
+ let should_fail = [ "bool" ]
+ spawn as p
+
+ with p:
+ for file in should_succeed:
+ send "load ${scripts_success.path}/$file.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run Test"
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-done")
+ flush
+
+ for file in should_fail:
+ send "load ${scripts_fail.path}/$file.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run Test"
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-failed")
+ flush
+
+
test RunConfig:
node n
- shell on n:
- cp ${scripts.path}/erebos-tester.yaml .
- mkdir tools
- cp ${scripts.path}/tools/echo.sh ./tools/tool
- mkdir scripts
- # TODO: it seems that namespaces are not properly cleaned up after the failed test
- #cp ${scripts.path}/trivial.et ./scripts/
- cp ${scripts.path}/echo.et ./scripts/
+ local:
+ shell on n:
+ cp ${scripts.path}/erebos-tester.yaml .
+ mkdir tools
+ cp ${scripts.path}/tools/echo.sh ./tools/tool
+ mkdir scripts
+ cp ${scripts.path}/trivial.et ./scripts/
+ cp ${scripts.path}/echo.et ./scripts/
spawn as p on n
@@ -38,10 +78,76 @@ test RunConfig:
send "load-config"
expect /load-config-done/
send "run-all"
- #expect /run-test-result AlwaysSucceeds done/
- #expect /run-test-result AlwaysFails failed/
+ expect /run-test-result AlwaysSucceeds done/
+ expect /run-test-result AlwaysFails failed/
expect /child-stdin p abcdef/
expect /child-stdout p abcdef/
expect /match p abcdef/
expect /run-test-result ExpectEcho done/
expect /run-all-done/
+
+
+test GetSysInfo:
+ node n
+ local:
+ shell on n:
+ cp ${scripts.path}/erebos-tester.yaml .
+ mkdir tools
+ cp ${scripts.path}/tools/sysinfo.sh ./tools/tool
+ mkdir scripts
+ cp ${scripts.path}/sysinfo.et ./scripts/
+
+ spawn as p on n
+
+ with p:
+ send "load-config"
+ expect /load-config-done/
+ send "run SysInfo"
+ expect /run-done/
+
+
+test CallStack:
+ spawn as p
+ with p:
+ send "load ${scripts.path}/callstack.et"
+ expect /load-done/
+
+ send "run AG"
+ expect /match-fail guard failed/
+ expect /match-fail-line .*\/callstack.et:3:5: .*/
+ expect /match-fail-var x 1/
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-failed")
+ flush
+
+ send "run AE"
+ expect /match-fail expect failed/
+ expect /match-fail-line .*\/callstack.et:8:5: .*/
+ expect /match-fail-var x 2/
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-failed")
+ flush
+
+ send "run BG"
+ expect /match-fail guard failed/
+ expect /match-fail-line .*\/callstack.et:12:5: .*/
+ expect /match-fail-var x 1/
+ expect /match-fail-line .*\/callstack.et:15:5: .*/
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-failed")
+ flush
+
+ send "run CG"
+ expect /match-fail guard failed/
+ expect /match-fail-line .*\/callstack.et:19:5: .*/
+ expect /match-fail-var x 3/
+ expect /match-fail-var y 2/
+ expect /match-fail-line .*\/callstack.et:23:5: .*/
+ expect /match-fail-var z 3/
+ local:
+ expect /(run-.*)/ capture done
+ guard (done == "run-failed")
+ flush
diff --git a/test/script/shell.et b/test/script/shell.et
new file mode 100644
index 0000000..282df37
--- /dev/null
+++ b/test/script/shell.et
@@ -0,0 +1,100 @@
+asset scripts:
+ path: ../asset/shell
+
+
+test ShellSpawn:
+ spawn as p
+ with p:
+ send "load ${scripts.path}/spawn.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run-all"
+ expect /run-test-result ShellTrue done/
+ expect /child-fail sh failed at: .*: false/
+ expect /child-fail sh exit code: 1/
+ expect /run-test-result ShellFalse failed/
+ expect /run-all-done/
+
+
+def expect_next_stdout from p (expected):
+ expect from p /child-stdout sh (.*)/ capture line
+ guard (line == expected)
+
+test ShellEcho:
+ spawn as p
+ with p:
+ send "load ${scripts.path}/echo.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run-all"
+
+ expect_next_stdout from p:
+ "a b c"
+ "a b c"
+ "a b d"
+ "a b c d"
+
+ "abcd xyz"
+ "aa bc d"
+ "b echo c"
+
+ "a b"
+ "a b"
+ "\$space_str"
+
+ "\$ \" \\"
+ "\"\"a"
+ "' \" \\\\\\ \\"
+ "a b c"
+
+ "\" ' \\ \$ # | > < ; [ ] { } ( ) * ? ~ & !"
+
+ with p:
+ expect /run-test-result Echo done/
+ expect /run-all-done/
+
+
+test ShellPipe:
+ spawn as p
+ with p:
+ send "load ${scripts.path}/pipe.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run-all"
+
+ expect_next_stdout from p:
+ "bc"
+ "b"
+ with p:
+ expect /run-test-result Pipe done/
+
+ expect_next_stdout from p:
+ "x"
+ "b"
+ "c"
+ "y"
+ "b"
+ "c"
+ "z"
+ with p:
+ expect /run-test-result Redirect done/
+
+ expect_next_stdout from p:
+ "c"
+ "e"
+ "g"
+ "bcdefg"
+ with p:
+ expect /run-test-result PipeRedirect done/
+
+ with p:
+ expect /run-all-done/