shared/exit-status: add exit_status_from_string()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-07-29 15:54:53 +02:00
parent e1714f0250
commit f0d67dcddd
3 changed files with 33 additions and 0 deletions
+15
View File
@@ -14,13 +14,28 @@ static void test_exit_status_to_string(void) {
log_info("%d: %s%s%s%s",
i, s ?: "-",
class ? " (" : "", class ?: "", class ? ")" : "");
if (s)
assert_se(exit_status_from_string(s) == i);
}
}
static void test_exit_status_from_string(void) {
log_info("/* %s */", __func__);
assert_se(exit_status_from_string("11") == 11);
assert_se(exit_status_from_string("-1") == -ERANGE);
assert_se(exit_status_from_string("256") == -ERANGE);
assert_se(exit_status_from_string("foo") == -EINVAL);
assert_se(exit_status_from_string("SUCCESS") == 0);
assert_se(exit_status_from_string("FAILURE") == 1);
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
test_exit_status_to_string();
test_exit_status_from_string();
return 0;
}