OILS / spec / ysh-method-io.test.sh View on Github | oilshell.org

81 lines, 33 significant
1## our_shell: ysh
2## oils_failures_allowed: 0
3
4#### captureStdout() is like $()
5
6var c = ^(echo one; echo two)
7
8var y = io.captureStdout(c)
9pp test_ (y)
10
11## STDOUT:
12(Str) "one\ntwo"
13## END
14
15#### captureStdout() failure
16
17var c = ^(echo one; false; echo two)
18
19# Hm this prints a message, but no stack trace
20# Should make it fail I think
21
22try {
23 var x = io.captureStdout(c)
24}
25# This has {"code": 3} because it's an expression error. Should probably
26pp test_ (_error)
27
28var x = io.captureStdout(c)
29
30## status: 4
31## STDOUT:
32(Dict) {"status":1,"code":4,"message":"captureStdout(): command failed with status 1"}
33## END
34
35#### io->eval() is like eval builtin
36
37var c = ^(echo one; echo two)
38var status = io->eval(c)
39
40# doesn't return anything
41echo status=$status
42
43## STDOUT:
44one
45two
46status=null
47## END
48
49#### io->eval() with failing command - caller must handle
50
51var c = ^(echo one; false; echo two)
52
53try {
54 call io->eval(c)
55}
56pp test_ (_error)
57
58call io->eval(c)
59
60## status: 1
61## STDOUT:
62one
63(Dict) {"code":1}
64one
65## END
66
67#### io->eval() with exit
68
69var c = ^(echo one; exit; echo two)
70
71try {
72 call io->eval(c)
73}
74echo 'we do not get here'
75pp test_ (_error)
76
77
78## STDOUT:
79one
80## END
81