forked from rumd3x/go-mutesting
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-mutated-package.sh
executable file
·77 lines (59 loc) · 1.73 KB
/
test-mutated-package.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
#!/bin/bash
# This exec script implements
# - the replacement of the original file with the mutation,
# - the execution of all tests originating from the package of the mutated file,
# - and the reporting if the mutation was killed.
if [ -z ${MUTATE_CHANGED+x} ]; then echo "MUTATE_CHANGED is not set"; exit 1; fi
if [ -z ${MUTATE_ORIGINAL+x} ]; then echo "MUTATE_ORIGINAL is not set"; exit 1; fi
if [ -z ${MUTATE_PACKAGE+x} ]; then echo "MUTATE_PACKAGE is not set"; exit 1; fi
function clean_up {
if [ -f "$MUTATE_ORIGINAL".tmp ];
then
mv "$MUTATE_ORIGINAL".tmp "$MUTATE_ORIGINAL"
fi
}
function sig_handler {
clean_up
exit "$GOMUTESTING_RESULT"
}
trap sig_handler SIGHUP SIGINT SIGTERM
export GOMUTESTING_DIFF=$(diff -u "$MUTATE_ORIGINAL" "$MUTATE_CHANGED")
mv "$MUTATE_ORIGINAL" "$MUTATE_ORIGINAL".tmp
cp "$MUTATE_CHANGED" "$MUTATE_ORIGINAL"
export MUTATE_TIMEOUT=${MUTATE_TIMEOUT:-10}
export MUTATE_BUILD_TAGS=${MUTATE_BUILD_TAGS}
if [ -n "$TEST_RECURSIVE" ]; then
TEST_RECURSIVE="/..."
fi
GOMUTESTING_TEST=$(go test -timeout "$(printf '%ds' "$MUTATE_TIMEOUT")" -tags="$MUTATE_BUILD_TAGS" "$MUTATE_PACKAGE""$TEST_RECURSIVE" 2>&1)
export GOMUTESTING_RESULT=$?
if [ "$MUTATE_DEBUG" = true ] ; then
echo "$GOMUTESTING_TEST"
fi
clean_up
case $GOMUTESTING_RESULT in
0) # tests passed -> FAIL
echo "$GOMUTESTING_DIFF"
exit 1
;;
1) # tests failed -> PASS
if [ "$MUTATE_DEBUG" = true ] ; then
echo "$GOMUTESTING_DIFF"
fi
exit 0
;;
2) # did not compile -> SKIP
if [ "$MUTATE_VERBOSE" = true ] ; then
echo "Mutation did not compile"
fi
if [ "$MUTATE_DEBUG" = true ] ; then
echo "$GOMUTESTING_DIFF"
fi
exit 2
;;
*) # Unkown exit code -> SKIP
echo "Unknown exit code"
echo "$GOMUTESTING_DIFF"
exit "$GOMUTESTING_RESULT"
;;
esac