Skip to content

Commit c2fc081

Browse files
committed
Allow SAFE_RUN to correctly run and check results
This shell function had several issues that prevented it from living up to its name: 1. It used `$1` to run commands, which fails to handle e.g. `;` 1. It assigned using `local`, which would mask any errors 3. It was invoked with command expansions, so anything it was supposed to run was already finished *before* it ran.
1 parent 2751a86 commit c2fc081

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test/native-tests/test_native.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ FIND_CLANG() {
2828
}
2929

3030
SAFE_RUN() {
31-
local SF_RETURN_VALUE=$($1 2>&1)
31+
local SF_OUTPUT
32+
SF_OUTPUT=$(eval "( $1 )" 2>&1)
3233

3334
if [[ $? != 0 ]]; then
34-
>&2 echo $SF_RETURN_VALUE
35+
>&2 echo "$SF_OUTPUT"
3536
exit 1
3637
fi
3738
}
@@ -57,24 +58,24 @@ fi
5758
RUN () {
5859
TEST_PATH=$1
5960
echo "Testing $TEST_PATH"
60-
SAFE_RUN `cd $TEST_PATH; ${CH_DIR} Platform.js > Makefile`
61+
SAFE_RUN "cd $TEST_PATH && ${CH_DIR} Platform.js > Makefile"
6162
RES=$(cd $TEST_PATH; cat Makefile)
6263

6364
if [[ $RES =~ "# IGNORE_THIS_TEST" ]]; then
6465
echo "Ignoring $TEST_PATH"
6566
else
66-
SAFE_RUN `cd $TEST_PATH; make CC=${CC} CXX=${CXX}`
67+
SAFE_RUN "cd $TEST_PATH && make CC=${CC} CXX=${CXX}"
6768
RES=$(cd $TEST_PATH; ./sample.o)
6869
TEST "SUCCESS"
69-
SAFE_RUN `cd $TEST_PATH; rm -rf ./sample.o`
70+
SAFE_RUN "cd $TEST_PATH && rm -rf ./sample.o"
7071
fi
7172
}
7273

7374
RUN_CMD () {
7475
TEST_PATH=$1
7576
CMD=$2
7677
echo "Testing $TEST_PATH"
77-
SAFE_RUN `cd $TEST_PATH; $CMD`
78+
SAFE_RUN "cd $TEST_PATH && $CMD"
7879
}
7980

8081
# static lib tests
@@ -100,4 +101,4 @@ RUN "test-shared-basic"
100101
# test python
101102
RUN_CMD "test-python" "python helloWorld.py ${BUILD_TYPE}"
102103

103-
SAFE_RUN `rm -rf Makefile`
104+
SAFE_RUN "rm -rf Makefile"

0 commit comments

Comments
 (0)