1
0
mirror of https://github.com/janet-lang/janet synced 2026-05-22 13:22:20 +00:00

Add shorthand for os test.

This commit is contained in:
Calvin Rose
2026-01-17 10:11:56 -06:00
parent d5a014baff
commit 4575cefb7e
2 changed files with 12 additions and 5 deletions
+8 -5
View File
@@ -142,8 +142,8 @@ static void janet_unlock_environ(void) {
#define janet_stringify(x) janet_stringify1(x)
JANET_CORE_FN(os_which,
"(os/which)",
"Check the current operating system. Returns one of:\n\n"
"(os/which &opt test)",
"Check the current operating system. If `test` is nil or unset, Returns one of:\n\n"
"* :windows\n\n"
"* :mingw\n\n"
"* :cygwin\n\n"
@@ -156,9 +156,12 @@ JANET_CORE_FN(os_which,
"* :dragonfly\n\n"
"* :bsd\n\n"
"* :posix - A POSIX compatible system (default)\n\n"
"May also return a custom keyword specified at build time.") {
janet_fixarity(argc, 0);
(void) argv;
"May also return a custom keyword specified at build time. Is `test` is truthy, will check if the current operating system equals `test` and return true if they are the same, false otherwise.") {
janet_arity(argc, 0, 1);
if (argc == 1 && janet_truthy(argv[0])) {
janet_getkeyword(argv, 0); /* Constrain to keywords */
return janet_wrap_boolean(janet_equals(argv[0], os_which(0, NULL)));
}
#if defined(JANET_OS_NAME)
return janet_ckeywordv(janet_stringify(JANET_OS_NAME));
#elif defined(JANET_MINGW)
+4
View File
@@ -178,4 +178,8 @@
(assert-error "os/realpath errors when path does not exist"
(os/realpath "abc123def456"))
# os/which changes
(assert (os/which (os/which)) "os/which 1 arg")
(assert (not (os/which :gobbledegook)) "os/which 2")
(end-suite)