-
Notifications
You must be signed in to change notification settings - Fork 1
/
jskonoha.sh
74 lines (61 loc) · 1.37 KB
/
jskonoha.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
#!/bin/bash
###
# jskonoha runtime for gjstest
###
PROGRAM=`basename $0`
while getopts j:k:o:x OPT
do
case $OPT in
"j" ) FLG_J="TRUE" ; VALUE_J="$OPTARG" ;;
"k" ) FLG_K="TRUE" ; VALUE_K="$OPTARG" ;;
"o" ) FLG_O="TRUE" ; VALUE_O="$OPTARG" ;;
"x" ) FLG_X="TRUE" ;;
* ) OPT_ERROR=1; break;;
esac
done
# set runtime
if [ "$FLG_J" = "TRUE" ]; then
JSKONOHA=$VALUE_J
else
OPT_ERROR=1
fi
# set imput file
if [ "$FLG_K" = "TRUE" ]; then
SCRIPT=$VALUE_K
else
OPT_ERROR=1
fi
if [ $OPT_ERROR ]; then
echo "Usage: $PROGRAM [-x] [-o output] -j jskonoha.js -k script.k"
exit 1
fi
# set type
if [ "$FLG_X" = "TRUE" ]; then
EXPORT="xml"
else
EXPORT="html"
fi
# set output
if [ "$FLG_O" = "TRUE" ]; then
OUTPUT=${VALUE_O}
else
OUTPUT=${SCRIPT}.${EXPORT}
fi
TMPFILE=`mktemp /tmp/${PROGRAM}.XXXXXX` || exit 1
TESTNAME=`echo $SCRIPT | sed -e 's/.*[^\/]*[\/]\([^\/]*\)$/\1/g' | sed -e 's/\./_/g'`
cat << _EOT_ > $TMPFILE
function ${TESTNAME}_test() {}
registerTestSuite(${TESTNAME}_test);
${TESTNAME}_test.prototype.RunKonohaTest = function() {
var script = "\\
_EOT_
while read line; do
echo "${line}" ' \\n \\' | sed -e 's/"/\\"/g' >> $TMPFILE
done <${SCRIPT}
cat << _EOT_ >> $TMPFILE
";
var ret = konoha.eval(script);
}
_EOT_
echo "gjstest --js_files=${JSKONOHA},${TMPFILE} --${EXPORT}_output_file=${OUTPUT}"
gjstest --js_files=${JSKONOHA},${TMPFILE} --${EXPORT}_output_file=${OUTPUT}