Skip to content

Commit 275c476

Browse files
authored
Merge pull request #35 from krishna-bala/krishna.fix-test-runner
fix: handle NVIM environment variable in test script
2 parents d7f55c7 + da46677 commit 275c476

3 files changed

Lines changed: 91 additions & 6 deletions

File tree

DEVELOPMENT.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ make test-basic
183183
make test-config
184184
```
185185

186+
### Running Tests from Within Neovim/Claude Code
187+
188+
When running tests from within a Neovim instance (such as when using Claude Code via claude-code.nvim), the test script automatically handles the `$NVIM` environment variable which normally points to a socket file instead of the nvim executable.
189+
190+
The test script will:
191+
192+
- Use the `$NVIM` variable if it points to a valid executable file
193+
- Fall back to finding `nvim` in `$PATH` if `$NVIM` points to a socket or invalid path
194+
- Display which nvim binary is being used for transparency
195+
196+
To verify the NVIM detection logic works correctly, you can run:
197+
198+
```bash
199+
./scripts/test_nvim_detection.sh
200+
```
201+
186202
### Writing Tests
187203

188204
Tests are written in Lua using a simple BDD-style API:

scripts/test.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ cd "$PLUGIN_DIR"
1212
# Print current directory for debugging
1313
echo "Running tests from: $(pwd)"
1414

15-
# Find nvim
16-
NVIM=${NVIM:-$(which nvim)}
17-
18-
if [ -z "$NVIM" ]; then
19-
echo "Error: nvim not found in PATH"
20-
exit 1
15+
# Find nvim - ignore NVIM env var if it points to a socket
16+
if [ -n "$NVIM" ] && [ -x "$NVIM" ] && [ ! -S "$NVIM" ]; then
17+
# NVIM is set and is an executable file (not a socket)
18+
echo "Using NVIM from environment: $NVIM"
19+
else
20+
# Find nvim in PATH
21+
if ! NVIM=$(command -v nvim); then
22+
echo "Error: nvim not found in PATH"
23+
exit 1
24+
fi
2125
fi
2226

2327
echo "Running tests with $NVIM"

scripts/test_nvim_detection.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Test script to verify NVIM environment variable detection logic
5+
# This script tests the fix for handling NVIM variable when running inside Neovim
6+
7+
# Get the absolute directory path of this script
8+
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
9+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
10+
11+
echo "Testing NVIM environment variable detection..."
12+
13+
# Save original NVIM value
14+
ORIGINAL_NVIM="$NVIM"
15+
16+
# Test 1: NVIM points to a socket (simulating inside Neovim)
17+
echo "Test 1: NVIM points to a socket"
18+
export NVIM="/tmp/test_socket"
19+
mkfifo "$NVIM" 2>/dev/null || true # Create a named pipe (similar to socket)
20+
if timeout 5 bash -c "cd '$PROJECT_DIR' && ./scripts/test.sh" 2>&1 | head -10 | grep -q "Running tests with.*nvim"; then
21+
echo "✓ Fallback to PATH works"
22+
else
23+
echo "✗ Fallback failed"
24+
fi
25+
rm -f "$NVIM"
26+
27+
# Test 2: NVIM points to valid executable
28+
echo "Test 2: NVIM points to valid executable"
29+
if ! NVIM=$(command -v nvim); then
30+
echo "Error: nvim not found in PATH"
31+
exit 1
32+
fi
33+
export NVIM
34+
if timeout 5 bash -c "cd '$PROJECT_DIR' && ./scripts/test.sh" 2>&1 | head -10 | grep -q "Using NVIM from environment"; then
35+
echo "✓ Using provided NVIM works"
36+
else
37+
echo "✗ Using provided NVIM failed"
38+
fi
39+
40+
# Test 3: NVIM points to non-existent path
41+
echo "Test 3: NVIM points to non-existent path"
42+
export NVIM="/nonexistent/nvim"
43+
if timeout 5 bash -c "cd '$PROJECT_DIR' && ./scripts/test.sh" 2>&1 | head -10 | grep -q "Running tests with.*nvim"; then
44+
echo "✓ Fallback from invalid path works"
45+
else
46+
echo "✗ Fallback from invalid path failed"
47+
fi
48+
49+
# Test 4: NVIM is unset
50+
echo "Test 4: NVIM is unset"
51+
unset NVIM
52+
if timeout 5 bash -c "cd '$PROJECT_DIR' && ./scripts/test.sh" 2>&1 | head -10 | grep -q "Running tests with.*nvim"; then
53+
echo "✓ Unset NVIM works"
54+
else
55+
echo "✗ Unset NVIM failed"
56+
fi
57+
58+
# Restore original NVIM value
59+
if [ -n "$ORIGINAL_NVIM" ]; then
60+
export NVIM="$ORIGINAL_NVIM"
61+
else
62+
unset NVIM
63+
fi
64+
65+
echo "All NVIM detection tests completed!"

0 commit comments

Comments
 (0)