OILS / spec / ysh-stdlib-testing.test.sh View on Github | oilshell.org

125 lines, 49 significant
1## our_shell: ysh
2## oils_failures_allowed: 5
3
4#### value.Expr test - positional test
5
6source --builtin testing.ysh
7
8echo 'parens'
9test-expr (42 + 1)
10echo
11
12echo 'brackets'
13test-expr [42 + 1]
14echo
15
16echo 'expr in parens'
17test-expr (^[42 + 1])
18echo
19
20## STDOUT:
21## END
22
23#### value.Expr test - named test
24
25source --builtin testing.ysh
26
27echo 'parens'
28test-named (n=42 + 1)
29echo
30
31echo 'brackets'
32test-named [n=42 + 1]
33echo
34
35echo 'expr in parens'
36test-named (n=^[42 + 1])
37echo
38
39echo 'no value'
40test-named
41echo
42
43## STDOUT:
44## END
45
46#### assert builtin
47
48source --builtin testing.ysh # get rid of this line later?
49
50var x = 42
51
52# how do you get the code string here?
53
54assert [42 === x]
55
56assert [42 < x]
57
58#assert [42 < x; fail_message='message']
59
60#assert (^[(42 < x)], fail_message='passed message')
61
62# BUG
63assert [42 < x, fail_message='passed message']
64
65## STDOUT:
66## END
67
68#### ysh --tool test file
69
70cat >mytest.ysh <<EOF
71echo hi
72EOF
73
74# which ysh
75
76# the test framework sets $SH to bin/ysh
77# but ysh is already installed on this machine
78
79$SH --tool test mytest.ysh
80
81## STDOUT:
82## END
83
84# Hm can we do this entirely in user code, not as a builtin?
85
86#### Describe Prototype
87
88source --builtin testing.ysh
89
90proc p {
91 echo STDOUT
92 echo STDERR >& 2
93 return 42
94}
95
96describe p {
97 # each case changes to a clean directory?
98 #
99 # and each one is numbered?
100
101 it 'prints to stdout and stderr' {
102 try {
103 p > out 2>& err
104 }
105 assert (_status === 42)
106
107 cat out
108 cat err
109
110 # Oh man the here docs are still useful here because of 'diff' interface
111 # Multiline strings don't quite do it
112
113 diff out - <<< '''
114 STDOUT
115 '''
116
117 diff err - <<< '''
118 STDERR
119 '''
120 }
121}
122
123## STDOUT:
124TODO
125## END