#!/usr/bin/env bash set -euo pipefail # Run integration tests for merged-repl-plugin # Usage: ./tests/run_tests.sh # This script creates two test git repositories under the project directory, # runs headless Neovim to exercise the plugin (sync and run), and verifies # expected results (branch creation, repl output capture, auto-commit). REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd) MAIN="$REPO_ROOT/test_main_repo" REPL="$REPO_ROOT/test_repl_repo" LUA_TMP="$REPO_ROOT/tests/_headless_test.lua" SYNC_OUT="$REPO_ROOT/tests/sync_result.txt" REPL_OUT="$REPO_ROOT/tests/repl_output_captured.log" echo "Running tests in: $REPO_ROOT" # Prepare test repos rm -rf "$MAIN" "$REPL" "$REPL_OUT" "$SYNC_OUT" mkdir -p "$MAIN" "$REPL" "$REPO_ROOT/tests" git -C "$MAIN" init || true # create initial commit in main if [ -z "$(git -C "$MAIN" rev-parse --verify HEAD 2>/dev/null || true)" ]; then touch "$MAIN/README" git -C "$MAIN" add README git -C "$MAIN" -c user.name='CI' -c user.email='ci@example.com' commit -m "init" fi git -C "$REPL" init || true if [ -z "$(git -C "$REPL" rev-parse --verify HEAD 2>/dev/null || true)" ]; then touch "$REPL/README" git -C "$REPL" add README git -C "$REPL" -c user.name='CI' -c user.email='ci@example.com' commit -m "init" fi # Ensure template branch exists in repl repo git -C "$REPL" checkout -B template || true # Write a simple repl.pl cat > "$REPL/repl.pl" <<'EOF' print "Hello from REPL\n"; EOF # commit repl.pl git -C "$REPL" add repl.pl || true git -C "$REPL" -c user.name='CI' -c user.email='ci@example.com' commit -m "add repl" || true # Compose headless lua test file cat > "$LUA_TMP" < 0 end, 50) local bufnr = vim.fn.bufnr(bufname) if bufnr > 0 then local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) local f = io.open(repl_out, 'w') f:write(table.concat(lines, '\n')) f:close() end -- exit vim.cmd('qa!') LUALIB # Run headless Neovim with the test lua file nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?.lua;./lua/?/init.lua'" -c "luafile ${LUA_TMP}" # Check results echo "--- Sync result ---" if [ -f "$SYNC_OUT" ]; then cat "$SYNC_OUT" else echo "No sync output file found" fi echo "--- Repl output ---" if [ -f "$REPL_OUT" ]; then cat "$REPL_OUT" else echo "No repl output captured" fi # Verify repl repo got branch created if main branch changed # create a new branch in main to test branch mirroring git -C "$MAIN" checkout -B feature-test # run sync_once again nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?.lua;./lua/?/init.lua'" -c "lua require('merged-repl-plugin').setup{ main_repo_path = '${MAIN}', repl_repo_path = '${REPL}', repl_file = '${REPL}/repl.pl', auto_start = false } require('merged-repl-plugin').sync_once()" -c "qa!" echo "--- Branches in repl repo ---" git -C "$REPL" branch --list # Test auto-commit: modify repl.pl and run sync_once to ensure commit echo 'print "Modified\n";' >> "$REPL/repl.pl" nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?.lua;./lua/?/init.lua'" -c "lua require('merged-repl-plugin').setup{ main_repo_path = '${MAIN}', repl_repo_path = '${REPL}', repl_file = '${REPL}/repl.pl', auto_start = false } require('merged-repl-plugin').sync_once()" -c "qa!" echo "--- Latest commit message in repl repo ---" git -C "$REPL" log -1 --pretty=%B echo "Tests finished."