1 |
## our_shell: ysh
|
2 |
|
3 |
|
4 |
|
5 |
source --builtin testing.ysh
|
6 |
setglobal _test_use_color = false
|
7 |
|
8 |
test-suite "three bad tests" {
|
9 |
test-case "the assertion is false" {
|
10 |
assert [1 > 0]
|
11 |
assert [1 > 1]
|
12 |
assert [1 > 2]
|
13 |
}
|
14 |
|
15 |
test-case "there is an exception while evaluating the assertion" {
|
16 |
assert ["Superman" > "Batman"]
|
17 |
}
|
18 |
|
19 |
test-case "there is an exception outside of any assertion" {
|
20 |
error "oops!"
|
21 |
}
|
22 |
}
|
23 |
|
24 |
test-case "one good test case" {
|
25 |
assert [1 === 1]
|
26 |
assert [2 === 2]
|
27 |
}
|
28 |
|
29 |
run-tests
|
30 |
|
31 |
## STDOUT:
|
32 |
begin three bad tests
|
33 |
test the assertion is false ...
|
34 |
assertion FAILED
|
35 |
test there is an exception while evaluating the assertion ...
|
36 |
assertion ERRORED: 10
|
37 |
test there is an exception outside of any assertion ...
|
38 |
ERROR: 10
|
39 |
end
|
40 |
test one good test case ... ok
|
41 |
3 / 4 tests failed
|
42 |
## END
|
43 |
|
44 |
|
45 |
|
46 |
source --builtin testing.ysh
|
47 |
setglobal _test_use_color = false
|
48 |
|
49 |
test-case "A" { : }
|
50 |
test-suite "outer test suite" {
|
51 |
test-case "B" { : }
|
52 |
test-suite "first inner test suite" {
|
53 |
test-case "C" { : }
|
54 |
}
|
55 |
test-case "D" { : }
|
56 |
test-suite "second inner test suite" {
|
57 |
test-case "E" { : }
|
58 |
}
|
59 |
test-case "F" { : }
|
60 |
}
|
61 |
test-case "G" { : }
|
62 |
|
63 |
run-tests
|
64 |
|
65 |
## STDOUT:
|
66 |
test A ... ok
|
67 |
begin outer test suite
|
68 |
test B ... ok
|
69 |
begin first inner test suite
|
70 |
test C ... ok
|
71 |
end
|
72 |
test D ... ok
|
73 |
begin second inner test suite
|
74 |
test E ... ok
|
75 |
end
|
76 |
test F ... ok
|
77 |
end
|
78 |
test G ... ok
|
79 |
7 tests succeeded
|
80 |
## END
|
81 |
|
82 |
|
83 |
|
84 |
source --builtin testing.ysh
|
85 |
setglobal _test_use_color = false
|
86 |
|
87 |
proc p {
|
88 |
echo STDOUT
|
89 |
echo STDERR >& 2
|
90 |
return 42
|
91 |
}
|
92 |
|
93 |
test-case "that it prints to stdout and stderr" {
|
94 |
# each case changes to a clean directory?
|
95 |
#
|
96 |
# and each one is numbered?
|
97 |
|
98 |
try {
|
99 |
p > out 2> err
|
100 |
}
|
101 |
|
102 |
assert [_status === 42]
|
103 |
assert [$(<out) === "STDOUT"]
|
104 |
assert [$(<err) === "STDERR"]
|
105 |
}
|
106 |
|
107 |
run-tests
|
108 |
|
109 |
## STDOUT:
|
110 |
test that it prints to stdout and stderr ... ok
|
111 |
1 tests succeeded
|
112 |
## END
|
113 |
|
114 |
# #### ysh --tool test file
|
115 |
#
|
116 |
# cat >mytest.ysh <<EOF
|
117 |
# echo hi
|
118 |
# EOF
|
119 |
#
|
120 |
# # which ysh
|
121 |
#
|
122 |
# # the test framework sets $SH to bin/ysh
|
123 |
# # but ysh is already installed on this machine
|
124 |
#
|
125 |
# $SH --tool test mytest.ysh
|
126 |
#
|
127 |
# ## STDOUT:
|
128 |
# ## END
|
129 |
#
|
130 |
# # Hm can we do this entirely in user code, not as a builtin?
|