Make test error when number is invalid nicer

This would print the default "Argument is invalid" error string, which
is *true* but not super obvious, because `test` doesn't always perform
numeric conversion, and that's the bit that failed here.
This commit is contained in:
Fabian Homborg
2021-04-24 11:18:58 +02:00
parent fc0dd49842
commit 3cccb77b52
2 changed files with 3 additions and 1 deletions

View File

@@ -716,6 +716,8 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t
errors.push_back(_(L"Not a number"));
} else if (std::isinf(floating)) {
errors.push_back(_(L"Number is infinite"));
} else if (errno == EINVAL) {
errors.push_back(format_string(L"Argument is not a number: '%ls'", argcs));
} else {
errors.push_back(format_string(L"%s: '%ls'", std::strerror(errno), argcs));
}

View File

@@ -37,7 +37,7 @@ function t
end
t foo
# CHECKERR: Invalid argument: 'foo'
# CHECKERR: Argument is not a number: 'foo'
# CHECKERR: {{.*}}test.fish (line {{\d+}}):
# CHECKERR: test $argv[1] -eq 5
# CHECKERR: ^