commit 1cc51c2ac7e5a55d89eee67826fb5c31e1d8b98c
parent 63f5ef97029c445e9edd9cd4ac84e354f500507f
Author: Kyle Milz <kyle@0x30.net>
Date: Tue, 30 Aug 2016 23:21:19 -0600
src: error to console when PATH is bad
Diffstat:
2 files changed, 13 insertions(+), 35 deletions(-)
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -25,14 +25,12 @@
#include <sstream> // stringstream
-int
+void
clean_PATH(InstrumentLogger &llog)
{
char *path;
- if ((path = std::getenv("PATH")) == NULL) {
- llog << "Error: PATH is not set.\n";
- return 1;
- }
+ if ((path = std::getenv("PATH")) == NULL)
+ errx(1, "Error: PATH is not set.");
llog << "PATH='" << path << "'\n";
@@ -57,16 +55,11 @@ clean_PATH(InstrumentLogger &llog)
first_component = 0;
}
- if (!found_citrun_path) {
- llog << "Error: '" << CITRUN_SHARE << "' not in PATH.\n";
- return 1;
- }
+ if (!found_citrun_path)
+ errx(1, "Error: '%s' not in PATH.", CITRUN_SHARE);
- // Set new $PATH
if (setenv("PATH", new_path.str().c_str(), 1))
err(1, "setenv");
-
- return 0;
}
void
@@ -116,9 +109,7 @@ main(int argc, char *argv[])
llog << ".\n";
setprogname("citrun-inst");
- if (clean_PATH(llog) != 0)
- // PATH cleaning failed, exiting is advisable.
- return 1;
+ clean_PATH(llog);
}
InstrumentFrontend main(argc, argv, &llog, is_citruninst);
diff --git a/t/inst_path.sh b/t/inst_path.sh
@@ -5,34 +5,21 @@
# - not having CITRUN_SHARE in PATH when using transparent compile mode errors
#
. test/utils.sh
-plan 3
+plan 2
-# Save the PATH to restore later.
-OLDPATH="${PATH}"
-
-cat <<EOF > citrun.log.good
-citrun-inst 0.0 () ''
-Tool called as ''.
-PATH is not set.
-citrun-inst 0.0 () ''
-Tool called as ''.
-PATH=''
-'' not in PATH.
-EOF
+OLDPATH=${PATH}
# Hang onto an absolute reference to 'expr' for libtap.sh
alias expr=`which expr`
unset PATH
-ok_program "run citrun-inst as cc with no PATH" 1 "" \
+output_good='citrun-inst: Error: PATH is not set.'
+ok_program "run citrun-inst as cc with no PATH" 1 "$output_good" \
$CITRUN_TOOLS/cc -c nomatter.c
export PATH=""
-ok_program "run citrun-inst as cc with empty PATH" 1 "" \
+output_good="citrun-inst: Error: '/home/kyle/citrun/src' not in PATH."
+ok_program "run citrun-inst as cc with empty PATH" 1 "$output_good" \
$CITRUN_TOOLS/cc -c nomatter.c 2> /dev/null
-# Restore the path so the commands below work.
-PATH="${OLDPATH}"
-
-strip_log citrun.log
-ok "citrun.log diff" diff -u citrun.log.good citrun.log.stripped
+PATH=${OLDPATH}