From 7c2e9b9abf2bcc4bf34587f0261059d557d1470d Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Thu, 22 Jan 2026 18:53:42 -0500 Subject: [PATCH] update tests --- bb.edn | 9 ++- test/e2e.clj | 131 ++++++++++++++++++++++++++++++++++ test/e2e/run-all.sh | 55 -------------- test/e2e/setup-cursor-test.sh | 26 ------- test/e2e/setup-test-repo.sh | 37 ---------- 5 files changed, 138 insertions(+), 120 deletions(-) create mode 100644 test/e2e.clj delete mode 100755 test/e2e/run-all.sh delete mode 100755 test/e2e/setup-cursor-test.sh delete mode 100755 test/e2e/setup-test-repo.sh diff --git a/bb.edn b/bb.edn index 3b55277..b12b41e 100644 --- a/bb.edn +++ b/bb.edn @@ -1,10 +1,15 @@ {:paths ["src" "test"] :deps {io.github.ajet/clojure-tui {:local/root "../clojure-tui"}} - :tasks {start {:doc "Run lazygitclj" + :tasks {:requires ([e2e]) + start {:doc "Run lazygitclj" :task (exec 'lazygitclj.core/-main)} test {:doc "Run unit tests" :task (load-file "test/run-tests.clj")} test:unit {:doc "Run unit tests" :task (load-file "test/run-tests.clj")} test:e2e {:doc "Run e2e VHS tests" - :task (shell "test/e2e/run-all.sh")}}} + :task (e2e/run-all)} + e2e:setup {:doc "Setup standard e2e test repo" + :task (e2e/setup-test-repo)} + e2e:setup-cursor {:doc "Setup cursor navigation test repo" + :task (e2e/setup-cursor-test-repo)}}} diff --git a/test/e2e.clj b/test/e2e.clj new file mode 100644 index 0000000..0e5b30f --- /dev/null +++ b/test/e2e.clj @@ -0,0 +1,131 @@ +(ns e2e + "E2E test utilities and runner for VHS tape tests." + (:require [babashka.fs :as fs] + [babashka.process :refer [shell]] + [clojure.string :as str])) + +(defn sh + "Run shell command, return exit code." + [& args] + (:exit (apply shell {:continue true :out :inherit :err :inherit} args))) + +(defn sh-quiet + "Run shell command quietly, return exit code." + [& args] + (:exit (apply shell {:continue true :out nil :err nil} args))) + +(defn setup-test-repo + "Setup a test git repository for e2e tests. + Usage: (setup-test-repo) or (setup-test-repo \"/tmp/my-repo\")" + ([] (setup-test-repo "/tmp/lazygitclj-e2e-test")) + ([repo-dir] + (fs/delete-tree repo-dir) + (fs/create-dirs repo-dir) + + ;; Initialize repo + (shell {:dir repo-dir} "git" "init" "-b" "main") + (shell {:dir repo-dir} "git" "config" "user.email" "test@example.com") + (shell {:dir repo-dir} "git" "config" "user.name" "Test User") + + ;; Create initial files + (spit (fs/file repo-dir "README.md") "# Test Project\n") + (spit (fs/file repo-dir "file1.txt") "line1\n") + (spit (fs/file repo-dir "file2.txt") "line2\n") + (shell {:dir repo-dir} "git" "add" ".") + (shell {:dir repo-dir} "git" "commit" "-m" "Initial commit") + + ;; Create feature branch with changes + (shell {:dir repo-dir} "git" "checkout" "-b" "feature-branch") + (spit (fs/file repo-dir "feature.txt") "feature content\n") + (shell {:dir repo-dir} "git" "add" ".") + (shell {:dir repo-dir} "git" "commit" "-m" "Add feature") + + ;; Go back to main and make uncommitted changes + (shell {:dir repo-dir} "git" "checkout" "main") + (spit (fs/file repo-dir "file1.txt") "line1\nmodified\n") + (spit (fs/file repo-dir "new-file.txt") "new file\n") + + (println "Test repo created at" repo-dir) + repo-dir)) + +(defn setup-cursor-test-repo + "Setup test repo with many files for cursor navigation tests." + ([] (setup-cursor-test-repo "/tmp/lazygitclj-e2e-cursor")) + ([repo-dir] + (fs/delete-tree repo-dir) + (fs/create-dirs repo-dir) + + ;; Initialize repo + (shell {:dir repo-dir} "git" "init" "-b" "main") + (shell {:dir repo-dir} "git" "config" "user.email" "test@test.com") + (shell {:dir repo-dir} "git" "config" "user.name" "Test") + + ;; Create 20 files + (doseq [i (range 1 21)] + (spit (fs/file repo-dir (str "file" i ".txt")) (str "content " i "\n"))) + + (shell {:dir repo-dir} "git" "add" ".") + (shell {:dir repo-dir} "git" "commit" "-m" "Initial") + + ;; Modify all files to create unstaged changes + (doseq [i (range 1 21)] + (spit (fs/file repo-dir (str "file" i ".txt")) + (str "content " i "\nmodified " i "\n"))) + + (println "Cursor test repo created at" repo-dir) + repo-dir)) + +(def tests + "List of e2e test tapes." + ["test/e2e/navigation.tape" + "test/e2e/cursor-navigation.tape" + "test/e2e/staging.tape" + "test/e2e/commit.tape" + "test/e2e/commit-verify.tape" + "test/e2e/branches.tape" + "test/e2e/branch-operations.tape" + "test/e2e/branches-tabs.tape" + "test/e2e/commits-tabs.tape" + "test/e2e/stash-operations.tape" + "test/e2e/stash-menu.tape" + "test/e2e/help-panel.tape" + "test/e2e/reset-menu.tape" + "test/e2e/undo-redo.tape"]) + +(defn run-tape + "Run a single VHS tape, return true if passed." + [tape] + (println) + (println "Running:" tape) + (println "---") + (let [exit-code (sh-quiet "timeout" "60" "vhs" tape)] + (if (zero? exit-code) + (do (println "PASSED:" tape) true) + (do (println "FAILED:" tape) false)))) + +(defn run-all + "Run all VHS e2e tests." + [] + (println "Running lazygitclj VHS e2e tests...") + (println "=================================") + + (let [results (map run-tape tests) + passed (count (filter true? results)) + failed (count (filter false? results))] + + (println) + (println "=================================") + (println (str "Results: " passed " passed, " failed " failed")) + (println "=================================") + + (when (pos? failed) + (System/exit 1)))) + +;; Allow running from command line +(when (= *file* (System/getProperty "babashka.file")) + (let [args *command-line-args*] + (case (first args) + "setup" (setup-test-repo (or (second args) "/tmp/lazygitclj-e2e-test")) + "setup-cursor" (setup-cursor-test-repo (or (second args) "/tmp/lazygitclj-e2e-cursor")) + "run" (run-all) + (run-all)))) diff --git a/test/e2e/run-all.sh b/test/e2e/run-all.sh deleted file mode 100755 index de97cae..0000000 --- a/test/e2e/run-all.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# Run all VHS e2e tests - -set -e - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" -cd "$REPO_ROOT" - -echo "Running lazygitclj VHS e2e tests..." -echo "=================================" - -# List of test tapes (relative to repo root) -TESTS=( - "test/e2e/navigation.tape" - "test/e2e/cursor-navigation.tape" - "test/e2e/staging.tape" - "test/e2e/commit.tape" - "test/e2e/commit-verify.tape" - "test/e2e/branches.tape" - "test/e2e/branch-operations.tape" - "test/e2e/branches-tabs.tape" - "test/e2e/commits-tabs.tape" - "test/e2e/stash-operations.tape" - "test/e2e/stash-menu.tape" - "test/e2e/help-panel.tape" - "test/e2e/reset-menu.tape" - "test/e2e/undo-redo.tape" -) - -PASSED=0 -FAILED=0 - -for tape in "${TESTS[@]}"; do - echo "" - echo "Running: $tape" - echo "---" - - if timeout 60 vhs "$tape" 2>&1; then - echo "PASSED: $tape" - ((PASSED++)) - else - echo "FAILED: $tape" - ((FAILED++)) - fi -done - -echo "" -echo "=================================" -echo "Results: $PASSED passed, $FAILED failed" -echo "=================================" - -if [ $FAILED -gt 0 ]; then - exit 1 -fi diff --git a/test/e2e/setup-cursor-test.sh b/test/e2e/setup-cursor-test.sh deleted file mode 100755 index 5726946..0000000 --- a/test/e2e/setup-cursor-test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Setup test repo with many files for cursor navigation tests - -REPO=/tmp/lazygitclj-e2e-cursor -rm -rf "$REPO" -mkdir -p "$REPO" -cd "$REPO" - -git init -b main -git config user.email 'test@test.com' -git config user.name 'Test' - -# Create 20 files -for i in $(seq 1 20); do - echo "content $i" > "file$i.txt" -done - -git add . -git commit -m 'Initial' - -# Modify all files to create unstaged changes -for i in $(seq 1 20); do - echo "modified $i" >> "file$i.txt" -done - -echo "Cursor test repo created at $REPO" diff --git a/test/e2e/setup-test-repo.sh b/test/e2e/setup-test-repo.sh deleted file mode 100755 index 7c21af4..0000000 --- a/test/e2e/setup-test-repo.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# Setup a test git repository for e2e tests -# Usage: ./setup-test-repo.sh /tmp/test-repo - -REPO_DIR="${1:-/tmp/lazygitclj-e2e-test}" - -# Remove existing repo if present -rm -rf "$REPO_DIR" - -# Create and initialize repo -mkdir -p "$REPO_DIR" -cd "$REPO_DIR" -git init -b main - -# Configure git -git config user.email "test@example.com" -git config user.name "Test User" - -# Create initial files -echo "# Test Project" > README.md -echo "line1" > file1.txt -echo "line2" > file2.txt -git add . -git commit -m "Initial commit" - -# Create feature branch with changes -git checkout -b feature-branch -echo "feature content" > feature.txt -git add . -git commit -m "Add feature" - -# Go back to main and make some uncommitted changes -git checkout main -echo "modified" >> file1.txt -echo "new file" > new-file.txt - -echo "Test repo created at $REPO_DIR"