OILS / spec / ysh-builtin-trap.test.sh View on Github | oils.pub

72 lines, 32 significant
1## our_shell: ysh
2
3#### trap --remove INT EXIT
4
5trap --add INT EXIT HUP {
6 echo one
7 echo two
8}
9trap -p > traps.txt
10wc -l traps.txt
11echo ---
12
13trap --remove INT EXIT
14trap -p > traps.txt
15wc -l traps.txt
16echo ---
17
18trap --add EXIT { echo 'exit' }
19
20## STDOUT:
213 traps.txt
22---
231 traps.txt
24---
25exit
26## END
27
28#### trap block arg is a not a closure - like cd and other builtins
29
30# e.g. We're not using ctx_EnclosedFrame in RunTrapsOnExit() and in the signal
31# handlers. It's more similar to OSH.
32
33var x = 'global'
34
35proc register {
36 var x = 'local'
37 trap --add EXIT {
38 echo "x = $x"
39 }
40}
41
42register
43
44## STDOUT:
45x = global
46## END
47
48#### trap --ignore INT USR1
49
50trap --ignore INT USR1
51trap -p
52
53## STDOUT:
54trap -- '' SIGINT
55trap -- '' SIGUSR1
56## END
57
58#### trap --ignore rejects hooks
59
60trap --ignore EXIT
61
62## STDOUT:
63## END
64## status: 2
65
66#### trap --ignore rejects STOP
67
68trap --ignore STOP
69
70## STDOUT:
71## END
72## status: 2