-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtesting.sh
114 lines (80 loc) · 2.4 KB
/
testing.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
## SPDX-FileCopyrightText: 2022 Buoyant, Inc.
## SPDX-License-Identifier: Apache-2.0
## This is a hidden comment.
clear
echo "This will run like a normal script."
# We can import things from other files.
#@import macros.sh
# We can define hooks too.
#@hook show_browser BROWSER
#@hook nonexistant NONEXISTANT
## The #@SHOW and #@HIDE tags control whether we're showing commands, waiting
## for the user to confirm proceeding, etc., or just running things like a
## normal script.
#@SHOW
# Welcome to our demo. Isn't it awesome?
# You can use the `@print` directive to produce colorized output:
#@print This will be ordinary black text.
#@print # This will be red like a comment.
# Next, let's check for hooks. If you've set DEMO_HOOK_BROWSER to a nonempty
# value, you should see "we have a browser hook!" here.
#@ifhook show_browser
#@immed
echo "We have a browser hook!"
#@endif
# As long as you haven't set DEMO_HOOK_NONEXISTANT to a nonempty
# value, you should not see "we have a nonexistant hook?" here.
#@ifhook nonexistant
#@immed
echo 'We have a nonexistant hook?'
#@endif
## Hit RETURN to continue (this is the wait directive).
#@wait
# Let's try an assignment.
FOO="Hello world"
echo "$FOO"
# exported assignments work too. (The word export itself is a noop in demosh,
# to be clear: variables are always exported.)
export BAR="Exported hello world"
echo "$BAR"
# The $SHELL environment variable should be overwritten to be demosh itself.
echo "SHELL is $SHELL"
# Here's a function definition with the "function" keyword...
function hello() {
echo "Hello, $1!"
}
# ...and here's one without it.
hello2 () {
echo "Hello again, $1!"
}
# Can we run the functions?
hello "world"
hello2 "world"
# Assignments persist across blocks, of course.
echo $FOO
echo $BAR
# cd is handled internally, so this should work.
cd /tmp
pwd
# Let's test a macro.
wait_clear
# How about an immediate macro call?
#@wait_then_date
# Here, we'll need to hit RETURN to run our command.
echo "Waiting only before"
# This is an immediate command: no waiting at all.
#@immed
echo "No waiting."
# Here we wait before and after.
#@waitafter
echo "Waiting before and after"
#@waitafter
#@nowaitbefore
echo "Waiting only after"
# Let's try the function again.
hello "world again"
# Let's test signal handling. You should be able to hit
# Ctrl-C to interrupt the sleep.
sleep 120
# And that's the whole `demosh` shell-script demo!!