diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0efce80..fd421d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,10 +7,15 @@ on: jobs: build-and-test: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install cmake + if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install -y cmake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd3c55b..70409c4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,11 +9,19 @@ permissions: contents: write jobs: - release: - runs-on: ubuntu-latest + build: + strategy: + matrix: + include: + - os: ubuntu-latest + asset: trigger-linux-x86_64 + - os: macos-latest + asset: trigger-macos-arm64 + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install cmake + if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install -y cmake @@ -21,8 +29,24 @@ jobs: run: | cmake -B build -S . -DCMAKE_BUILD_TYPE=Release cmake --build build --target shell + cp build/shell ${{ matrix.asset }} + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.asset }} + path: ${{ matrix.asset }} + + # One publishing job so the matrix builds don't race to create the release + release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + merge-multiple: true - name: Create release uses: softprops/action-gh-release@v2 with: - files: build/shell + files: | + trigger-linux-x86_64 + trigger-macos-arm64 generate_release_notes: true diff --git a/CLAUDE.md b/CLAUDE.md index 0ac4f50..69e0779 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -33,12 +33,16 @@ Lint (also enforced in CI as a separate `lint` job, see below): cmake -B cmake-build-debug -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON clang-tidy -p cmake-build-debug -warnings-as-errors=* $(find src include -name '*.c') -CI (`.github/workflows/ci.yml`) runs on every PR and push to `main` with two jobs: -`build-and-test` (`./run_tests.sh`) and `lint` (clang-format + clang-tidy, both -warnings-as-errors). Formatting follows `.clang-format` (LLVM base, 4-space indent, -100 col limit); tidy checks are configured in `.clang-tidy`. A tag matching `v*.*.*` -triggers `.github/workflows/release.yml`, which builds a Release binary and attaches -it to a GitHub release. +CI (`.github/workflows/ci.yml`) runs on every PR and push to `main` with three jobs: +`build-and-test` (`./run_tests.sh` on both `ubuntu-latest` and `macos-latest`), +`sanitize` (ASan/UBSan, Linux only) and `lint` (clang-format + clang-tidy, both +warnings-as-errors). Tests must stay portable across Linux and macOS: don't hardcode +binaries that differ between them (e.g. use `true`, not `/bin/true`), and remember that +`/tmp` resolves to `/private/tmp` on macOS. Formatting follows `.clang-format` (LLVM +base, 4-space indent, 100 col limit); tidy checks are configured in `.clang-tidy`. A tag matching `v*.*.*` +triggers `.github/workflows/release.yml`, which builds Release binaries on Linux and +macOS and attaches them to a GitHub release as `trigger-linux-x86_64` and +`trigger-macos-arm64`. ## Architecture diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bfc1a8..756d0ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ set(LIB_SOURCES src/builtins.c src/pipeline.c src/glob.c - src/nepeta.c ) set(UTIL_SOURCES @@ -24,7 +23,6 @@ set(HEADERS include/builtins.h include/pipeline.h include/glob_expand.h - include/nepeta.h ) add_library(trigger_core STATIC ${LIB_SOURCES} ${UTIL_SOURCES}) @@ -69,13 +67,8 @@ target_link_libraries(test_glob trigger_core) target_compile_options(test_glob PRIVATE -Wall -Wextra -Werror) add_test(NAME GlobTests COMMAND test_glob) -add_executable(test_nepeta tests/test_nepeta.c) -target_link_libraries(test_nepeta trigger_core) -target_compile_options(test_nepeta PRIVATE -Wall -Wextra -Werror) -add_test(NAME NepetaTests COMMAND test_nepeta) - add_custom_target(run_tests COMMAND ${CMAKE_CTEST_COMMAND} --verbose - DEPENDS test_input test_builtins test_execute test_pipeline test_glob test_nepeta + DEPENDS test_input test_builtins test_execute test_pipeline test_glob WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) diff --git a/README.md b/README.md index 4019209..ed9f536 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,13 @@ This project aims to create a clean, efficient shell. +## Platforms + +Trigger targets POSIX systems: Linux and macOS are built and tested in CI, and tagged +releases ship `trigger-linux-x86_64` and `trigger-macos-arm64` binaries. Windows is not +supported natively (the shell relies on `fork`, `execvp`, `pipe` and `glob`); use WSL, +MSYS2 or Cygwin there. + ## Building ```bash diff --git a/include/builtins.h b/include/builtins.h index 264b22a..120525b 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -13,7 +13,6 @@ int trigger_pwd(char **args); int trigger_echo(char **args); int trigger_export(char **args); int trigger_unset(char **args); -int trigger_nepeta(char **args); int trigger_num_builtins(void); const Builtin *find_builtin(const char *name); diff --git a/include/nepeta.h b/include/nepeta.h deleted file mode 100644 index c3fc706..0000000 --- a/include/nepeta.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NEPETA_H -#define NEPETA_H - -#include -#include - -bool trigger_nepeta_is_enabled(void); -void trigger_nepeta_set_enabled(bool enabled); -void trigger_nepeta_init_from_env(void); -const char *trigger_nepeta_prompt(void); -void trigger_nepeta_print_banner(void); -char *trigger_nepeta_translate(const char *plain_text); -void trigger_nepeta_say(FILE *stream, const char *plain_text); -const char *trigger_nepeta_random_quote(void); - -#endif diff --git a/src/builtins.c b/src/builtins.c index 9b4255e..3fc650f 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1,5 +1,4 @@ #include "builtins.h" -#include "nepeta.h" #include "utils/utils.h" #include #include @@ -7,9 +6,9 @@ #include static const Builtin builtins[] = { - {"cd", trigger_cd}, {"help", trigger_help}, {"exit", trigger_exit}, - {"pwd", trigger_pwd}, {"echo", trigger_echo}, {"export", trigger_export}, - {"unset", trigger_unset}, {"nepeta", trigger_nepeta}, + {"cd", trigger_cd}, {"help", trigger_help}, {"exit", trigger_exit}, + {"pwd", trigger_pwd}, {"echo", trigger_echo}, {"export", trigger_export}, + {"unset", trigger_unset}, }; static const int builtin_count = sizeof(builtins) / sizeof(builtins[0]); @@ -27,7 +26,7 @@ const Builtin *find_builtin(const char *name) { int trigger_cd(char **args) { if (args[1] == NULL) { - trigger_nepeta_say(stderr, "trigger: expected argument to \"cd\"\n"); + fprintf(stderr, "trigger: expected argument to \"cd\"\n"); return 1; } if (chdir(args[1]) != 0) { @@ -39,15 +38,15 @@ int trigger_cd(char **args) { } int trigger_help(char **args __attribute__((unused))) { - trigger_nepeta_say(stdout, "Trigger: A simple shell written in C\n"); - trigger_nepeta_say(stdout, "Type program names and arguments, and hit enter.\n"); - trigger_nepeta_say(stdout, "The following are built in:\n"); + printf("Trigger: A simple shell written in C\n"); + printf("Type program names and arguments, and hit enter.\n"); + printf("The following are built in:\n"); for (int i = 0; i < builtin_count; i++) { printf(" %s\n", builtins[i].name); } - trigger_nepeta_say(stdout, "Use the man command for information on other programs.\n"); + printf("Use the man command for information on other programs.\n"); return 0; } @@ -58,9 +57,7 @@ int trigger_exit(char **args) { if (*endptr == '\0' && n >= 0 && n <= 255) { return (int) n; } - char buf[256]; - snprintf(buf, sizeof(buf), "trigger: exit: %s: numeric argument required\n", args[1]); - trigger_nepeta_say(stderr, buf); + fprintf(stderr, "trigger: exit: %s: numeric argument required\n", args[1]); return 2; } return EXIT_SUCCESS; @@ -117,35 +114,3 @@ int trigger_unset(char **args) { } return 0; } - -int trigger_nepeta(char **args) { - if (args[1] == NULL) { - trigger_nepeta_set_enabled(!trigger_nepeta_is_enabled()); - trigger_nepeta_say(stdout, "Nepeta mode toggled.\n"); - return 0; - } - - if (strcmp(args[1], "on") == 0) { - trigger_nepeta_set_enabled(true); - trigger_nepeta_say(stdout, "Nepeta mode enabled.\n"); - return 0; - } - - if (strcmp(args[1], "off") == 0) { - trigger_nepeta_set_enabled(false); - trigger_nepeta_say(stdout, "Nepeta mode disabled.\n"); - return 0; - } - - if (strcmp(args[1], "status") == 0) { - if (trigger_nepeta_is_enabled()) { - trigger_nepeta_say(stdout, "Nepeta mode is enabled.\n"); - } else { - trigger_nepeta_say(stdout, "Nepeta mode is disabled.\n"); - } - return 0; - } - - trigger_nepeta_say(stderr, "usage: nepeta [on|off|status]\n"); - return 1; -} diff --git a/src/main.c b/src/main.c index cfa045c..3e05a73 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,5 @@ #include "execute.h" #include "input.h" -#include "nepeta.h" #include "utils/utils.h" #include #include @@ -11,7 +10,7 @@ void trigger_loop(void) { int last_status = 0; for (;;) { - printf("%s", trigger_nepeta_prompt()); + printf("> "); fflush(stdout); char *line = trigger_read_line(); TokenList *tl = parse_line_with_quotes(line); @@ -39,9 +38,6 @@ int main(void) { signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - trigger_nepeta_init_from_env(); - trigger_nepeta_print_banner(); - trigger_loop(); return EXIT_SUCCESS; diff --git a/src/nepeta.c b/src/nepeta.c deleted file mode 100644 index 0650861..0000000 --- a/src/nepeta.c +++ /dev/null @@ -1,166 +0,0 @@ -#include "nepeta.h" -#include "utils/utils.h" -#include -#include -#include -#include -#include - -static bool nepeta_enabled = false; - -bool trigger_nepeta_is_enabled(void) { return nepeta_enabled; } - -void trigger_nepeta_set_enabled(bool enabled) { nepeta_enabled = enabled; } - -void trigger_nepeta_init_from_env(void) { - const char *val = getenv("TRIGGER_NEPETA"); - if (val != NULL && val[0] != '\0' && strcmp(val, "0") != 0) { - nepeta_enabled = true; - } -} - -const char *trigger_nepeta_prompt(void) { - if (nepeta_enabled) { - return ":33 < "; - } - return "> "; -} - -typedef struct { - const char *from; - const char *to; -} PunEntry; - -static const PunEntry pun_dict[] = { - {"for", "fur"}, {"perfect", "purrfect"}, {"great", "clawesome"}, {"awesome", "pawsome"}, - {"friend", "furriend"}, {"now", "meow"}, {"help", "halp"}, -}; - -static const size_t pun_count = sizeof(pun_dict) / sizeof(pun_dict[0]); - -static int alpha_run_len(const char *s) { - int n = 0; - while (s[n] != '\0' && isalpha((unsigned char) s[n])) { - n++; - } - return n; -} - -static bool alpha_run_equals(const char *s, int slen, const char *dict_word) { - size_t dwlen = strlen(dict_word); - if ((size_t) slen != dwlen) { - return false; - } - for (size_t i = 0; i < dwlen; i++) { - if (tolower((unsigned char) s[i]) != tolower((unsigned char) dict_word[i])) { - return false; - } - } - return true; -} - -static const char *find_pun(const char *s, int slen) { - for (size_t i = 0; i < pun_count; i++) { - if (alpha_run_equals(s, slen, pun_dict[i].from)) { - return pun_dict[i].to; - } - } - return NULL; -} - -static void append_char(char **buf, size_t *cap, size_t *len, char c) { - if (*len + 1 >= *cap) { - *cap = *cap == 0 ? 64 : *cap * 2; - *buf = xrealloc(*buf, *cap); - } - (*buf)[*len] = c; - (*len)++; -} - -static void append_str(char **buf, size_t *cap, size_t *len, const char *s) { - for (const char *p = s; *p != '\0'; p++) { - append_char(buf, cap, len, *p); - } -} - -char *trigger_nepeta_translate(const char *plain_text) { - if (plain_text == NULL) { - char *empty = xmalloc(1); - empty[0] = '\0'; - return empty; - } - - char *result = NULL; - size_t cap = 0; - size_t len = 0; - - const char *p = plain_text; - - while (*p != '\0') { - if (isalpha((unsigned char) *p)) { - int run = alpha_run_len(p); - const char *pun = find_pun(p, run); - - if (pun != NULL) { - char first = p[0]; - if (isupper((unsigned char) first)) { - append_char(&result, &cap, &len, (char) toupper((unsigned char) pun[0])); - append_str(&result, &cap, &len, pun + 1); - } else { - append_char(&result, &cap, &len, (char) tolower((unsigned char) pun[0])); - append_str(&result, &cap, &len, pun + 1); - } - } else { - for (int i = 0; i < run; i++) { - append_char(&result, &cap, &len, p[i]); - } - } - p += run; - } else { - append_char(&result, &cap, &len, *p); - p++; - } - } - - append_char(&result, &cap, &len, '\0'); - return result; -} - -void trigger_nepeta_say(FILE *stream, const char *plain_text) { - if (!nepeta_enabled) { - fputs(plain_text, stream); - return; - } - - char *translated = trigger_nepeta_translate(plain_text); - fprintf(stream, ":33 < %s", translated); - free(translated); -} - -static const char *quotes[] = { - ":33 < *ac scratches at the terminal prompt*", ":33 < purractice makes purrfect! hehe", - ":33 < *pounces on the enter key* rawr!", ":33 < this shell is the cat's pajamas!", - ":33 < *curls up on the keyboard* warm~", ":33 < fur the glory of the hunt!", - ":33 < *chases the cursor with big kitty eyes*", ":33 < all your base are belong to Nepeta!", - ":33 < *batbatbat* at the command line", ":33 < meow is the time fur action!", -}; - -static const size_t quote_count = sizeof(quotes) / sizeof(quotes[0]); - -const char *trigger_nepeta_random_quote(void) { - static int seeded = 0; - if (!seeded) { - srand((unsigned) time(NULL)); - seeded = 1; - } - return quotes[rand() % quote_count]; -} - -void trigger_nepeta_print_banner(void) { - if (!nepeta_enabled) { - return; - } - - printf(":33 < *Nepeta Leijon has entered the terminal* "); - printf("purrfect mode activated, %s, fur great justice!\n", trigger_nepeta_random_quote()); -} diff --git a/tests/test_builtins.c b/tests/test_builtins.c index f2fe3c2..c1a3cd6 100644 --- a/tests/test_builtins.c +++ b/tests/test_builtins.c @@ -1,5 +1,4 @@ #include "../include/builtins.h" -#include "../include/nepeta.h" #include "test_framework.h" #include #include @@ -9,7 +8,7 @@ void test_builtin_arrays_match() { int count = trigger_num_builtins(); - ASSERT_TRUE(count == 8, "Should have 8 built-in commands"); + ASSERT_TRUE(count == 7, "Should have 7 built-in commands"); ASSERT_NOT_NULL(find_builtin("cd"), "Should find 'cd' built-in"); ASSERT_NOT_NULL(find_builtin("help"), "Should find 'help' built-in"); @@ -18,17 +17,12 @@ void test_builtin_arrays_match() { ASSERT_NOT_NULL(find_builtin("echo"), "Should find 'echo' built-in"); ASSERT_NOT_NULL(find_builtin("export"), "Should find 'export' built-in"); ASSERT_NOT_NULL(find_builtin("unset"), "Should find 'unset' built-in"); - ASSERT_NOT_NULL(find_builtin("nepeta"), "Should find 'nepeta' built-in"); ASSERT_NULL(find_builtin("nonexistent"), "Should not find unknown built-in"); const Builtin *cd_b = find_builtin("cd"); ASSERT_NOT_NULL(cd_b, "cd Builtin* should not be NULL"); ASSERT_TRUE(cd_b->fn == trigger_cd, "cd Builtin should point to trigger_cd"); - - const Builtin *nepeta_b = find_builtin("nepeta"); - ASSERT_NOT_NULL(nepeta_b, "nepeta Builtin* should not be NULL"); - ASSERT_TRUE(nepeta_b->fn == trigger_nepeta, "nepeta Builtin should point to trigger_nepeta"); } void test_cd_no_args() { @@ -50,7 +44,11 @@ void test_cd_to_tmp() { ASSERT_NOT_NULL(getcwd(cwd_after, sizeof(cwd_after)), "getcwd after"); ASSERT_EQUAL(0, result, "cd to /tmp should return 0"); - ASSERT_STR_EQUAL("/tmp", cwd_after, "Should be in /tmp directory"); + // /tmp is a symlink on macOS (/private/tmp), so compare against its resolved path + char *tmp_real = realpath("/tmp", NULL); + ASSERT_NOT_NULL(tmp_real, "realpath /tmp"); + ASSERT_STR_EQUAL(tmp_real, cwd_after, "Should be in /tmp directory"); + free(tmp_real); ASSERT_EQUAL(0, chdir(cwd_before), "chdir back"); } @@ -124,50 +122,6 @@ void test_unset_command() { ASSERT_NULL(getenv("UNSET_VAR"), "unset variable should not be available"); } -void test_nepeta_on() { - trigger_nepeta_set_enabled(false); - char *args[] = {"nepeta", "on", NULL}; - int result = trigger_nepeta(args); - ASSERT_EQUAL(0, result, "nepeta on should return 0"); - ASSERT_TRUE(trigger_nepeta_is_enabled(), "Nepeta should be enabled after 'nepeta on'"); - trigger_nepeta_set_enabled(false); -} - -void test_nepeta_off() { - trigger_nepeta_set_enabled(true); - char *args[] = {"nepeta", "off", NULL}; - int result = trigger_nepeta(args); - ASSERT_EQUAL(0, result, "nepeta off should return 0"); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Nepeta should be disabled after 'nepeta off'"); - trigger_nepeta_set_enabled(false); -} - -void test_nepeta_status() { - trigger_nepeta_set_enabled(false); - char *args[] = {"nepeta", "status", NULL}; - int result = trigger_nepeta(args); - ASSERT_EQUAL(0, result, "nepeta status should return 0"); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Nepeta should still be disabled after status"); - trigger_nepeta_set_enabled(false); -} - -void test_nepeta_bare_toggle() { - trigger_nepeta_set_enabled(false); - char *args[] = {"nepeta", NULL}; - int result = trigger_nepeta(args); - ASSERT_EQUAL(0, result, "nepeta bare should return 0"); - ASSERT_TRUE(trigger_nepeta_is_enabled(), "Nepeta should be enabled after bare toggle"); - trigger_nepeta_set_enabled(false); -} - -void test_nepeta_unknown_arg() { - trigger_nepeta_set_enabled(false); - char *args[] = {"nepeta", "meow", NULL}; - int result = trigger_nepeta(args); - ASSERT_EQUAL(1, result, "nepeta with unknown arg should return 1"); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Nepeta should stay disabled after unknown arg"); -} - int main() { TEST_SUITE_START("Built-ins Module Tests"); @@ -183,11 +137,6 @@ int main() { test_export_command(); test_export_no_value(); test_unset_command(); - test_nepeta_on(); - test_nepeta_off(); - test_nepeta_status(); - test_nepeta_bare_toggle(); - test_nepeta_unknown_arg(); TEST_SUITE_END(); } diff --git a/tests/test_execute.c b/tests/test_execute.c index e7be31f..b91793a 100644 --- a/tests/test_execute.c +++ b/tests/test_execute.c @@ -57,12 +57,13 @@ void test_execute_builtin_exit() { } void test_execute_external_command() { - char *words[] = {"/bin/true", NULL}; + char *words[] = {"true", NULL}; TokenList *tl = make_tokenlist(1, words); ExecuteResult r = trigger_execute(tl); free_tokenlist(tl); - ASSERT_FALSE(r.should_exit, "Execute '/bin/true' should not exit"); + ASSERT_FALSE(r.should_exit, "Execute 'true' should not exit"); + ASSERT_EQUAL(0, r.status, "Execute 'true' should return status 0"); } void test_launch_simple_command() { diff --git a/tests/test_nepeta.c b/tests/test_nepeta.c deleted file mode 100644 index 339c7d9..0000000 --- a/tests/test_nepeta.c +++ /dev/null @@ -1,173 +0,0 @@ -#include "../include/nepeta.h" -#include "test_framework.h" -#include -#include -#include - -static void reset_nepeta(void) { trigger_nepeta_set_enabled(false); } - -void test_default_disabled() { - reset_nepeta(); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Nepeta mode should be disabled by default"); -} - -void test_set_get_roundtrip() { - reset_nepeta(); - trigger_nepeta_set_enabled(true); - ASSERT_TRUE(trigger_nepeta_is_enabled(), "Should be enabled after set(true)"); - trigger_nepeta_set_enabled(false); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Should be disabled after set(false)"); -} - -void test_prompt_disabled() { - reset_nepeta(); - ASSERT_STR_EQUAL("> ", trigger_nepeta_prompt(), "Prompt should be default when disabled"); -} - -void test_prompt_enabled() { - reset_nepeta(); - trigger_nepeta_set_enabled(true); - ASSERT_STR_EQUAL(":33 < ", trigger_nepeta_prompt(), "Prompt should be :33 < when enabled"); -} - -void test_translate_known_word() { - reset_nepeta(); - char *t = trigger_nepeta_translate("for"); - ASSERT_STR_EQUAL("fur", t, "\"for\" should translate to \"fur\""); - free(t); -} - -void test_translate_case_preserving() { - reset_nepeta(); - char *t = trigger_nepeta_translate("For"); - ASSERT_STR_EQUAL("Fur", t, "\"For\" should translate to \"Fur\""); - free(t); -} - -void test_translate_no_substring_match() { - reset_nepeta(); - char *t = trigger_nepeta_translate("information"); - ASSERT_STR_EQUAL("information", t, "\"information\" should not match \"for\" substring"); - free(t); -} - -void test_translate_no_match_passthrough() { - reset_nepeta(); - char *t = trigger_nepeta_translate("hello world"); - ASSERT_STR_EQUAL("hello world", t, "Unmatched text should pass through unchanged"); - free(t); -} - -void test_translate_multiple_words() { - reset_nepeta(); - char *t = trigger_nepeta_translate("this is great for a friend"); - ASSERT_STR_EQUAL("this is clawesome fur a furriend", t, "Multiple words should all translate"); - free(t); -} - -void test_translate_null() { - reset_nepeta(); - char *t = trigger_nepeta_translate(NULL); - ASSERT_NOT_NULL(t, "NULL input should return allocated empty string"); - ASSERT_STR_EQUAL("", t, "NULL input should return empty string"); - free(t); -} - -void test_translate_empty() { - reset_nepeta(); - char *t = trigger_nepeta_translate(""); - ASSERT_STR_EQUAL("", t, "Empty input should return empty string"); - free(t); -} - -static char *capture_say(const char *text) { - char *buf; - size_t sz; - FILE *f = open_memstream(&buf, &sz); - if (f == NULL) - return NULL; - trigger_nepeta_say(f, text); - fclose(f); - return buf; -} - -void test_say_disabled() { - reset_nepeta(); - char *buf = capture_say("hello"); - ASSERT_NOT_NULL(buf, "capture_say should not return NULL when disabled"); - ASSERT_STR_EQUAL("hello", buf, "say should pass through unchanged when disabled"); - free(buf); -} - -void test_say_enabled() { - reset_nepeta(); - trigger_nepeta_set_enabled(true); - char *buf = capture_say("this is for you"); - ASSERT_NOT_NULL(buf, "capture_say should not return NULL when enabled"); - ASSERT_STR_EQUAL(":33 < this is fur you", buf, - "say should prefix with :33 < and translate when enabled"); - free(buf); -} - -void test_random_quote_not_null() { - reset_nepeta(); - const char *q = trigger_nepeta_random_quote(); - ASSERT_NOT_NULL(q, "Random quote should not be NULL"); - ASSERT_TRUE(strlen(q) > 0, "Random quote should not be empty"); -} - -void test_init_from_env_enabled() { - reset_nepeta(); - setenv("TRIGGER_NEPETA", "1", 1); - trigger_nepeta_init_from_env(); - ASSERT_TRUE(trigger_nepeta_is_enabled(), "Should enable when TRIGGER_NEPETA=1"); - unsetenv("TRIGGER_NEPETA"); -} - -void test_init_from_env_disabled_zero() { - reset_nepeta(); - setenv("TRIGGER_NEPETA", "0", 1); - trigger_nepeta_init_from_env(); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Should stay disabled when TRIGGER_NEPETA=0"); - unsetenv("TRIGGER_NEPETA"); -} - -void test_init_from_env_disabled_unset() { - reset_nepeta(); - unsetenv("TRIGGER_NEPETA"); - trigger_nepeta_init_from_env(); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Should stay disabled when TRIGGER_NEPETA unset"); -} - -void test_init_from_env_disabled_empty() { - reset_nepeta(); - setenv("TRIGGER_NEPETA", "", 1); - trigger_nepeta_init_from_env(); - ASSERT_FALSE(trigger_nepeta_is_enabled(), "Should stay disabled when TRIGGER_NEPETA=\"\""); - unsetenv("TRIGGER_NEPETA"); -} - -int main() { - TEST_SUITE_START("Nepeta Module Tests"); - - test_default_disabled(); - test_set_get_roundtrip(); - test_prompt_disabled(); - test_prompt_enabled(); - test_translate_known_word(); - test_translate_case_preserving(); - test_translate_no_substring_match(); - test_translate_no_match_passthrough(); - test_translate_multiple_words(); - test_translate_null(); - test_translate_empty(); - test_say_disabled(); - test_say_enabled(); - test_random_quote_not_null(); - test_init_from_env_enabled(); - test_init_from_env_disabled_zero(); - test_init_from_env_disabled_unset(); - test_init_from_env_disabled_empty(); - - TEST_SUITE_END(); -} diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c index bee3168..39b0e5b 100644 --- a/tests/test_pipeline.c +++ b/tests/test_pipeline.c @@ -172,7 +172,7 @@ void test_e2e_builtin_in_pipeline() { char cwd_before[4096]; ASSERT_NOT_NULL(getcwd(cwd_before, sizeof(cwd_before)), "getcwd should succeed"); - int result = run_command("cd /tmp | /bin/true"); + int result = run_command("cd /tmp | true"); ASSERT_TRUE(result, "cd in pipe should succeed"); char cwd_after[4096];