forked from jpillora/jxcore-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-examples.sh
executable file
·85 lines (70 loc) · 1.65 KB
/
run-examples.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
#!/bin/bash
FILTER=$1
BASE=`pwd`
TMP=$BASE/tmp
DIRS=`ls -d */`
finish() {
#remove tmp
rm -r $TMP &> /dev/null
exit
}
runtest() {
#clear tmp contents
mkdir -p $TMP
rm -rf $TMP/* &> /dev/null
TEST=$1
cd $BASE/$TEST
#skip if it has no 'test.js'
if ! [ -e test.js ]; then
return
fi
#if example has a setup.sh, run it
if [ -e $BASE/$TEST/setup.sh ]; then
echo "== Setup '$TEST' ==="
if ! sh $BASE/$TEST/setup.sh &> $TMP/setup.txt; then
cat $TMP/setup.txt
finish
return
fi
fi
#npm install if this example has a package.json
if [ -e $BASE/$TEST/package.json ] && ! [ -e $BASE/$TEST/node_modules ]; then
echo "== npm install '$TEST' ==="
npm install
fi
# native modules: only works if we also copy node_modules
# if [ -e $BASE/$TEST/node_modules ]; then
# cp -r $BASE/$TEST/node_modules $TMP/node_modules
# fi
#run example with jx
echo "== Running '$TEST' ==="
jx test.js &> $TMP/unpackaged.txt
#compile example using .jxp
if [ -e package.jxp ]; then
jx compile package.jxp &> $TMP/compile.txt
else #compile example using auto-package
jx package test.js $TMP/test &> $TMP/compile.txt
fi
if ! [ -e $TMP/test.jx ]; then
echo "FAIL: packaging error:\n`cat $TMP/compile.txt`"
return
fi
#run compiled example
cd $TMP
jx test.jx &> $TMP/packaged.txt
#compare both
if ! diff -q $TMP/unpackaged.txt $TMP/packaged.txt &> /dev/null; then
echo "FAIL"
diff $TMP/unpackaged.txt $TMP/packaged.txt
else
echo "PASS"
fi
echo
}
for DIR in $DIRS; do
#filter tests that match $1
if [[ $DIR == *$FILTER* ]]; then
runtest $DIR
fi
done
finish