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