-
Notifications
You must be signed in to change notification settings - Fork 7
/
run_test.sh
executable file
·132 lines (111 loc) · 3.48 KB
/
run_test.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/sh
# Run from the "tests" folder and pass the instance name as an argument
test="wasi_components/$1"
# create the instance folder if it doesn't exist
mkdir -p instance
# copy the "wasi_components" skeleton
cp -r skeletons/wasi_components/guest instance
cp -r skeletons/wasi_components/host_sys instance
cp -r skeletons/wasi_components/host_js instance
# copy the protocol
cp $test/protocol.wit instance/protocol.wit
if [ $? -ne 0 ]; then
echo "Non-existing test: $test"
exit 1
fi
# copy the guest code
cp $test/guest.rs instance/guest/src/lib.rs
# build the guest
cd instance/guest && cargo component build && cd ../..
if [ $? -ne 0 ]; then
echo
echo "Oh no, there is an error in the $test guest."
echo "Inspect the instance folder for more detail."
exit 1
fi
# copy the host code
cp $test/host.rs instance/host_sys/src/host.rs
cp $test/host.rs instance/host_js/src/host.rs
if [ "$test" = "wasi_components/io_redirect" ]; then
# run test and capture its output
# run the sys host test
cd instance/host_sys && cargo test --lib -- --nocapture > out.txt 2> err.txt && cd ../..
if [ $? -ne 0 ]; then
cat *.txt
echo
echo "Oh no, there is an error in the $test sys host."
echo "Inspect the instance folder for more detail."
exit 1
fi
cat instance/host_sys/*.txt
# test the files for output
print1=$(grep PRINT_OUT_1 instance/host_sys/out.txt)
print2=$(grep PRINT_ERR_1 instance/host_sys/err.txt)
no_print1=$(grep NO_PRINT instance/host_sys/out.txt)
no_print2=$(grep NO_PRINT instance/host_sys/err.txt)
if [ "$print1" = "" ]; then
echo "Sys host should have printed PRINT_OUT_1 to stdout"
exit 1
fi
if [ "$print2" = "" ]; then
echo "Sys host should have printed PRINT_ERR_1 to stderr"
exit 1
fi
if [ "$no_print1" != "" ]; then
echo "Sys host should NOT have printed NO_PRINT to stdout"
exit 1
fi
if [ "$no_print2" != "" ]; then
echo "Sys host should NOT have printed NO_PRINT to stderr"
exit 1
fi
# run the js host test
cd instance/host_js && wasm-pack test --node > out.txt 2> err.txt && cd ../..
if [ $? -ne 0 ]; then
cat *.txt
echo
echo "Oh no, there is an error in the $test js host."
echo "Inspect the instance folder for more detail."
exit 1
fi
cat instance/host_js/*.txt
# test the files for output
print1=$(grep PRINT_OUT_1 instance/host_js/out.txt)
print2=$(grep PRINT_ERR_1 instance/host_js/err.txt)
no_print1=$(grep NO_PRINT instance/host_js/out.txt)
no_print2=$(grep NO_PRINT instance/host_js/err.txt)
if [ "$print1" = "" ]; then
echo "Js host should have printed PRINT_OUT_1 to stdout"
exit 1
fi
if [ "$print2" = "" ]; then
echo "Js host should have printed PRINT_ERR_1 to stderr"
exit 1
fi
if [ "$no_print1" != "" ]; then
echo "Js host should NOT have printed NO_PRINT to stdout"
exit 1
fi
if [ "$no_print2" != "" ]; then
echo "Js host should NOT have printed NO_PRINT to stderr"
exit 1
fi
else
# run test normally
# run the sys host test
cd instance/host_sys && cargo test --lib -- --nocapture && cd ../..
if [ $? -ne 0 ]; then
echo
echo "Oh no, there is an error in the $test sys host."
echo "Inspect the instance folder for more detail."
exit 1
fi
# run the js host test
cd instance/host_js && wasm-pack test --node && cd ../..
if [ $? -ne 0 ]; then
echo
echo "Oh no, there is an error in the $test js host."
echo "Inspect the instance folder for more detail."
exit 1
fi
fi