Shell: Add builtin test for strtol `test-strtol`

This commit is contained in:
Bananymous 2024-02-14 22:36:52 +02:00
parent 373d166076
commit c469d9b3ff
1 changed files with 21 additions and 0 deletions

View File

@ -448,6 +448,27 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
return ret; return ret;
} }
else if (args.front() == "test-strtol")
{
#define TEST(num, base) do { errno = 0; printf("strtol(\"" num "\", nullptr, " #base ") = %ld ", strtol(num, nullptr, base)); puts(errno ? strerrorname_np(errno) : ""); } while (false)
TEST("0", 10);
TEST("", 10);
TEST("+", 10);
TEST("123", 10);
TEST("-123", 10);
TEST("7fffffffffffffff", 10);
TEST("7fffffffffffffff", 16);
TEST("8000000000000000", 16);
TEST("-8000000000000000", 16);
TEST("-8000000000000001", 16);
TEST("123", 0);
TEST("0123", 0);
TEST("0x123", 0);
TEST("123", 1);
TEST("hello", 10);
TEST("hello", 36);
#undef TEST
}
else else
{ {
return {}; return {};