commit b750b7e759d4aff23ce46a07c9b64ca469154f84
parent 0deb33cfc66ec619f9e4ef668a1b6e67677bc0d5
Author: Kyle Milz <kyle@0x30.net>
Date: Wed, 27 Jul 2016 00:43:21 -0600
src: hard fail on instrumentation fail and add test
Diffstat:
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -219,9 +219,8 @@ main(int argc, char *argv[])
if (instrument(argc, argv, source_files)) {
restore_original_src(temp_file_map);
- warnx("Instrumentation failed, compiling unmodified code.");
- if (execvp(argv[0], argv))
- err(1, "execvp");
+ warnx("Instrumentation failed!");
+ errx(1, "If this code compiles natively, I want to know about it.");
}
bool linking = false;
diff --git a/t/inst_fail.t b/t/inst_fail.t
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+echo 1..2
+
+tmpfile=`mktemp`.c
+logfile=`mktemp`
+
+echo "int main(void) { return 0; " > $tmpfile
+
+export PATH="`pwd`/src:${PATH}"
+gcc -c $tmpfile 2> $logfile
+
+if [ $? -eq 1 ]; then
+ echo ok 1
+fi
+
+if grep -q "Instrumentation failed!" $logfile; then
+ echo ok 2
+fi
+
+rm $tmpfile
+rm $logfile