-
Notifications
You must be signed in to change notification settings - Fork 7
/
entrypoint.sh
172 lines (145 loc) · 3.49 KB
/
entrypoint.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh -l
# Read inputs
TESTS=$1
SRC=$2
LOG_FILE=$3
DOC_TESTS=$4
WITH_COVERAGE=$5
COVER_XML_FILE=$6
COVER_HTML_DIR=$7
COVER_JUNIT_XML_FILE=$8
COVER_JSON_FILE=$9
DATA=$10
PKG=$11
EXT=$12
WDIR=$13
####################
# Switch directory #
####################
if [ -z $WDIR ] ; then
WDIR="."
fi
cd $WDIR
###########################
# Prepare Octave commands #
###########################
# Create an Octave expression to set up the environment
SETUP=""
# Add MOxUnit, MOdox and MOcov to the Octave search path
SETUP="$SETUP addpath(\"/home/MOxUnit/MOxUnit\");"
SETUP="$SETUP addpath(\"/home/MOdox/MOdox\");"
SETUP="$SETUP addpath(\"/home/MOcov/MOcov\");"
SETUP="$SETUP setenv(\"PLATFORM\",\"GITHUB_ACTIONS\");"
SETUP="$SETUP moxunit_set_path();"
# add src directories to the path
if ! [ -z $SRC ] ; then
SRC_DIRS=""
for dir in $SRC
do
SRC_DIRS="$SRC_DIRS'$PWD/$dir',"
done
# remove trailing comma
SRC_DIRS=${SRC_DIRS%?}
SETUP="$SETUP addpath($SRC_DIRS);"
else
# This is used for coverage and documentation tests
SRC_DIRS="'.'"
fi
# add external directories to the path
if ! [ -z $EXT ] ; then
for dir in $EXT
do
SETUP="$SETUP addpath(genpath('$PWD/$dir'));"
done
else
EXT_DIRS=""
fi
if [ -z $DATA ] ; then
DATA=""
else
SETUP="$SETUP addpath(\"$PWD/$DATA\");"
echo "TEST DATA DIR: $PWD/$DATA"
ls $PWD/$DATA
fi
# Load Octave packages
if [ -z $PKG ] ; then
DATA=""
else
PKG_LIST=""
for pkg_name in $PKG
do
PKG_LIST="$PKG_LIST pkg load $pkg_name;"
done
SETUP="$SETUP $PKG_LIST pkg list;"
fi
##################
# Run unit tests #
##################
# prepare test case argument
if [ -z $TESTS ] ; then
TEST_CASES="'.'"
else
TEST_CASES=""
for dir in $TESTS
do
TEST_CASES="$TEST_CASES'$PWD/$dir',"
done
# remove trailing comma
TEST_CASES=${TEST_CASES%?}
fi
RUNTESTS_ARGS="$TEST_CASES, '-verbose', '-recursive'"
# write to log file
if ! [ -z $LOG_FILE ] ; then
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-logfile', '$PWD/$LOG_FILE'"
fi
# with code coverage
if [ "$WITH_COVERAGE" = "true" ] \
|| ! [ -z $COVER_XML_FILE ] \
|| ! [ -z $COVER_HTML_DIR ] \
|| ! [ -z $COVER_JUNIT_XML_FILE ] \
|| ! [ -z $COVER_JSON_FILE ] ; then
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-with_coverage', '-cover', $SRC_DIRS"
# write to xml file
if ! [ -z $COVER_XML_FILE ] ; then
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-cover_xml_file','$PWD/$COVER_XML_FILE'"
fi
# write to html dir
if ! [ -z $COVER_HTML_DIR ] ; then
mkdir -p $COVER_HTML_DIR
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-cover_html_dir','$PWD/$COVER_HTML_DIR'"
fi
# write to junix file
if ! [ -z $COVER_JUNIT_XML_FILE ] ; then
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-junit_xml_file','$PWD/$COVER_JUNIT_XML_FILE'"
fi
# write to json file
if ! [ -z $COVER_JSON_FILE ] ; then
RUNTESTS_ARGS="$RUNTESTS_ARGS, '-cover_json_file','$PWD/$COVER_JSON_FILE'"
fi
fi
# Run the tests
COMMAND="exit(~moxunit_runtests($RUNTESTS_ARGS));"
# Print Info
echo "RUNNING UNIT TESTS"
echo "SETUP: $SETUP"
echo "COMMAND: $COMMAND"
octave --no-gui --eval "$SETUP $COMMAND"
RESULT=$?
###########################
# Run documentation tests #
###########################
if [ "$DOC_TESTS" = "true" ] ; then
COMMAND="exit(~modox_runtests($SRC_DIRS));"
# Print Info
echo "RUNNING DOCUMENTATION TESTS"
echo "SETUP: $SETUP"
echo "COMMAND: $COMMAND"
octave --no-gui --eval "$SETUP $COMMAND"
RESULT=$(($RESULT + $?))
fi
if [ $RESULT -eq 0 ] ; then
echo "Unit tests succeeded."
else
echo "Unit tests failed!"
exit 1
fi