diff --git a/contrib/atf/atf-sh/atf-check.cpp b/contrib/atf/atf-sh/atf-check.cpp --- a/contrib/atf/atf-sh/atf-check.cpp +++ b/contrib/atf/atf-sh/atf-check.cpp @@ -74,12 +74,14 @@ status_check_t type; bool negated; int value; + bool empty; status_check(const status_check_t& p_type, const bool p_negated, - const int p_value) : + const int p_value, const bool p_empty) : type(p_type), negated(p_negated), - value(p_value) + value(p_value), + empty(p_empty) { } }; @@ -267,6 +269,7 @@ const std::string value_str = ( delimiter == std::string::npos ? "" : arg.substr(delimiter + 1)); int value; + bool empty = false; status_check_t type; if (action == "eq") { @@ -278,9 +281,10 @@ value = parse_exit_code(value_str); } else if (action == "exit") { type = sc_exit; - if (value_str.empty()) + if (value_str.empty()) { value = INT_MIN; - else + empty = true; + } else value = parse_exit_code(value_str); } else if (action == "ignore") { if (negated) @@ -296,14 +300,15 @@ value = parse_exit_code(value_str); } else if (action == "signal") { type = sc_signal; - if (value_str.empty()) + if (value_str.empty()) { value = INT_MIN; - else + empty = true; + } else value = parse_signal(value_str); } else throw atf::application::usage_error("Invalid status checker"); - return status_check(type, negated, value); + return status_check(type, negated, value, empty); } static @@ -599,7 +604,7 @@ bool result; if (sc.type == sc_exit) { - if (cr.exited() && sc.value != INT_MIN) { + if (cr.exited() && !sc.empty) { const int status = cr.exitcode(); if (!sc.negated && sc.value != status) { @@ -614,7 +619,7 @@ result = false; } else result = true; - } else if (cr.exited() && sc.value == INT_MIN) { + } else if (cr.exited() && sc.empty) { result = true; } else { std::cerr << "Fail: program did not exit cleanly\n"; @@ -623,7 +628,7 @@ } else if (sc.type == sc_ignore) { result = true; } else if (sc.type == sc_signal) { - if (cr.signaled() && sc.value != INT_MIN) { + if (cr.signaled() && !sc.empty) { const int status = cr.termsig(); if (!sc.negated && sc.value != status) { @@ -637,7 +642,7 @@ result = false; } else result = true; - } else if (cr.signaled() && sc.value == INT_MIN) { + } else if (cr.signaled() && sc.empty) { result = true; } else { std::cerr << "Fail: program did not receive a signal\n"; @@ -903,9 +908,10 @@ int status = EXIT_FAILURE; - if (m_status_checks.empty()) - m_status_checks.push_back(status_check(sc_exit, false, EXIT_SUCCESS)); - else if (m_status_checks.size() > 1) { + if (m_status_checks.empty()) { + m_status_checks.push_back(status_check(sc_exit, false, EXIT_SUCCESS, + false)); + } else if (m_status_checks.size() > 1) { // TODO: Remove this restriction. throw atf::application::usage_error("Cannot specify -s more than once"); }