From c469d9b3ff6cbd57abc2c29393ce173fd6353f1d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 14 Feb 2024 22:36:52 +0200 Subject: [PATCH] Shell: Add builtin test for strtol `test-strtol` --- userspace/Shell/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index 0ee1f4ff..6adaed11 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -448,6 +448,27 @@ BAN::Optional execute_builtin(BAN::Vector& args, int fd_in, in 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 { return {};