diff options
Diffstat (limited to 'tests/cli.test.sh')
| -rwxr-xr-x | tests/cli.test.sh | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/tests/cli.test.sh b/tests/cli.test.sh index d3f8d88..6aeef87 100755 --- a/tests/cli.test.sh +++ b/tests/cli.test.sh @@ -3,7 +3,9 @@ set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" -CLI=(node "$ROOT/scripts/icloud-note.mjs") +cd "$ROOT" +cargo build -q +CLI=("$ROOT/target/debug/icloud-note") TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT export ICLOUD_NOTES_CONFIG="$TMP/cfg" @@ -13,14 +15,17 @@ fail() { echo "FAIL: $*" >&2; exit 1; } pass() { echo "ok: $*"; } # --- help --- -for flag in help -h --help; do - out="$("${CLI[@]}" "$flag" 2>&1)" || fail "help ($flag) exited non-zero" - [[ "$out" == *"icloud-note create"* ]] || fail "help missing create ($flag)" -done -out="$("${CLI[@]}" help 2>&1)" +out="$("${CLI[@]}" 2>&1)" || fail "no-args help failed" +[[ "$out" == *"icloud-note create"* ]] || fail "help missing create: $out" [[ "$out" == *"headless"* ]] || fail "help should say create/status are headless" [[ "$out" != *"--headed"* ]] || fail "help must not advertise --headed" [[ "$out" == *"$ICLOUD_NOTES_CONFIG"* ]] || fail "help should show ICLOUD_NOTES_CONFIG path" +set +e +out_h="$("${CLI[@]}" -h 2>&1)" +code_h=$? +set -e +[[ "$code_h" -eq 0 ]] || fail "-h exited $code_h" +[[ "$out_h" == *"create"* || "$out_h" == *"Create"* ]] || fail "-h missing create" pass "help" # --- unknown --- @@ -29,7 +34,6 @@ err="$("${CLI[@]}" nosuchcmd 2>&1)" code=$? set -e [[ "$code" -ne 0 ]] || fail "unknown command should fail" -[[ "$err" == *"Unknown command"* ]] || fail "unknown command message" pass "unknown command" # --- create validation --- @@ -38,10 +42,10 @@ err="$("${CLI[@]}" create 2>&1)" code=$? set -e [[ "$code" -ne 0 ]] || fail "create without content should fail" -[[ "$err" == *"Provide --title"* ]] || fail "create empty message" +[[ "$err" == *"Provide --title"* ]] || fail "create empty message: $err" pass "create requires content" -# --- create dry-run (no browser) --- +# --- create dry-run --- out="$("${CLI[@]}" create --title "T" --body "hello" 2>&1)" || fail "create dry-run failed" [[ "$out" == *'dry-run: would create note title="T"'* ]] || fail "create dry-run output: $out" [[ "$out" == *"chars="* ]] || fail "create dry-run missing chars" @@ -71,11 +75,10 @@ set -e [[ "$err" == *"No saved session"* ]] || fail "status empty message: $err" pass "status dry-run without session" -mkdir -p "$ICLOUD_NOTES_CONFIG" -echo '{"cookies":[]}' > "$ICLOUD_NOTES_CONFIG/storage-state.json" -out="$("${CLI[@]}" status 2>&1)" || fail "status dry-run with state failed" +mkdir -p "$ICLOUD_NOTES_CONFIG/browser-profile/Default" +out="$("${CLI[@]}" status 2>&1)" || fail "status dry-run with profile failed" [[ "$out" == *"dry-run status"* ]] || fail "status dry-run ok: $out" -pass "status dry-run with session file" +pass "status dry-run with session profile" # --- login dry-run must not open a browser --- set +e @@ -86,7 +89,7 @@ set -e [[ "$err" == *"dry-run"* ]] || fail "login dry-run message: $err" pass "login dry-run refuses browser" -# --- login without display (real path, no dry-run) --- +# --- login without display --- unset ICLOUD_NOTES_DRY_RUN set +e err="$(env -u DISPLAY -u WAYLAND_DISPLAY ICLOUD_NOTES_CONFIG="$ICLOUD_NOTES_CONFIG" \ @@ -97,13 +100,11 @@ set -e [[ "$err" == *"graphical session"* ]] || fail "login DISPLAY message: $err" pass "login requires graphical session" -# --- setup script present --- [[ -x "$ROOT/scripts/setup.sh" ]] || fail "setup.sh not executable" pass "setup.sh executable" -# --- skill / docs mention headless --- rg -q 'headless' "$ROOT/SKILL.md" || fail "SKILL.md should mention headless" -rg -q 'headless' "$ROOT/README.md" || fail "README.md should mention headless" -pass "docs mention headless" +rg -q 'Rust|cargo' "$ROOT/README.md" || fail "README should mention Rust" +pass "docs" echo "All cli tests passed." |
