Skip to content

Fix basic tests #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
vim:
- nightly
- v9.0.0000
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]

steps:
- name: Setup Python
Expand Down Expand Up @@ -37,3 +37,41 @@ jobs:
$VIMPRG --version
cd test
source ./run_tests.sh 1


unit_test_windows:
name: unit_test_windows
runs-on: windows-latest
strategy:
matrix:
vim:
- nightly
- v9.0.0000

steps:
- name: Setup Python
uses: actions/setup-python@v5.0.0
with:
python-version: '3.12'

- name: Install jupyter_console
run: |
pip install jupyter_console

- name: Setup Vim
uses: rhysd/action-setup-vim@v1
id: vim
with:
version: ${{ matrix.vim }}

- name: Checkout vim-replica plugin code
uses: actions/checkout@v4

- name: Run Tests
run: |
systeminfo
echo "Vim command setup."
$Env:VIMPRG = "${{ steps.vim.outputs.executable }}"
& $Env:VIMPRG --version
cd test
.\run_tests.cmd
2 changes: 1 addition & 1 deletion lib/repl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def ConsoleClose()
if IsFiletypeSupported()
for win in ConsoleWinID()
SaveConsoleWindowSize(win)
win_execute(win, "close")
win_execute(win, "close!")
endfor
endif
enddef
Expand Down
52 changes: 44 additions & 8 deletions test/run_tests.cmd
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
@echo off

REM Script to run the unit-tests for the TERMDEBUG Vim plugin on MS-Windows
REM Script to run the unit-tests for the REPLICA Vim plugin on MS-Windows

SETLOCAL
SET VIMPRG="vim.exe"
SET VIM_CMD=%VIMPRG% -u NONE -U NONE -i NONE --noplugin -N --not-a-term
REM Define the paths and files
SET "VIMPRG=vim.exe"
SET "VIMRC=vimrc_for_tests"
SET "VIM_CMD=%VIMPRG% -u %VIMRC% -U NONE -i NONE -N --not-a-term"

%VIM_CMD% -c "vim9cmd g:TestName='test_termdebug.vim'" -S runner.vim
REM Create or overwrite the vimrc file with the initial setting
echo set runtimepath+=.. > "%VIMRC%"
echo filetype plugin on >> "%VIMRC%"

echo TERMDEBUG unit test results
REM Check if the vimrc file was created successfully
if NOT EXIST "%VIMRC%" (
echo "ERROR: Failed to create %VIMRC%"
exit /b 1
)

REM Display the contents of VIMRC (for debugging purposes)
type "%VIMRC%"

REM Run Vim with the specified configuration and additional commands
%VIM_CMD% -c "vim9cmd g:TestName='test_replica.vim'" -S "runner.vim"

REM Check the exit code of Vim command
if %ERRORLEVEL% EQU 0 (
echo Vim command executed successfully.
) else (
echo ERROR: Vim command failed with exit code %ERRORLEVEL%.
del %VIMRC%
exit /b 1
)

REM Check test results
echo REPLICA unit test results
type results.txt

findstr /I FAIL results.txt > nul 2>&1
if %ERRORLEVEL% EQU 0 echo ERROR: Some test failed.
if %ERRORLEVEL% NEQ 0 echo SUCCESS: All the tests passed.
REM Check for FAIL in results.txt
findstr /I "FAIL" results.txt > nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo ERROR: Some test failed.
del %VIMRC%
exit /b 1
) else (
echo All tests passed.
)

REM Exit script with success
del %VIMRC%
exit /b 0
15 changes: 11 additions & 4 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ if [ -z "$VIM_PRG" ]; then
fi
fi

VIMRC="vimrc_for_tests"
# Setup dummy VIMRC file
VIMRC="VIMRC"
echo "set runtimepath+=.." > "$VIMRC"
echo "filetype plugin on" >> "$VIMRC"

# VIM_CMD='$VIM_PRG -u $VIMRC -U NONE -i NONE --noplugin -N --not-a-term'
VIM_CMD='$VIM_PRG -u $VIMRC -U NONE -i NONE -N --not-a-term'
# Construct the VIM_CMD with correct variable substitution and quoting
# VIM_CMD="$VIM_PRG -u $VIMRC -U NONE -i NONE --noplugin -N --not-a-term"
VIM_CMD="$VIM_PRG -u $VIMRC -U NONE -i NONE -N --not-a-term"

# Add space separated tests, i.e. "test_replica.vim test_pippo.vim etc"
TESTS="test_replica.vim"
Expand All @@ -35,6 +39,7 @@ RunTestsInFile() {
if ! [ -f results.txt ]; then
echo "ERROR: Test results file 'results.txt' is not found."
if [ "$GITHUB" -eq 1 ]; then
rm VIMRC
exit 2
fi
fi
Expand All @@ -44,6 +49,7 @@ RunTestsInFile() {
if grep -qw FAIL results.txt; then
echo "ERROR: Some test(s) in $testfile failed."
if [ "$GITHUB" -eq 1 ]; then
rm VIMRC
exit 3
fi
fi
Expand All @@ -62,6 +68,7 @@ echo "SUCCESS: All the tests passed."
if [ "$GITHUB" -eq 1 ]; then
exit 0
fi
# kill %- > /dev/null

rm "$VIMRC"
# kill %- > /dev/null
# vim: shiftwidth=2 softtabstop=2 noexpandtab
100 changes: 79 additions & 21 deletions test/test_replica.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def Generate_python_testfile()
# %%

d = a -b

# %%
print('last_line')
END
writefile(lines, src_name)
enddef
Expand All @@ -35,36 +32,97 @@ def Cleanup_python_testfile()
delete(src_name)
enddef

def LastIpythonNonBlankLine(bufnrr: number): string
var current_buf = bufnr()
exe $'buffer {bufnrr}'
var lnum = line('$')
var lval = getbufoneline(bufnrr, lnum)
exe $'buffer {current_buf}'

while lnum > 0 && getbufline(bufnrr, lnum)[0] =~ '^\s*$'
lnum -= 1
lval = getbufline(bufnrr, lnum)[0]
endwhile
return lval
enddef

# Tests start here
def g:Test_replica_basic()
Generate_python_testfile()

exe $"edit {src_name}"

# Start console
ReplicaConsoleToggle
WaitForAssert(() => assert_equal(2, winnr('$')))
# TODO: Check how to remove the söeeå
sleep 1
# TODO: Check how to remove the sleep
# It must be very generous otherwise the CI tests won't pass.
sleep 4
redraw!

var bufnr = term_list()[0]
var lastline = LastIpythonNonBlankLine(bufnr)
var term_cursor = term_getcursor(bufnr)
var lastline = term_getline(bufnr, term_cursor[0])

var expected_prompt = '[1]'
assert_true(lastline =~# expected_prompt)
# WaitForAssert(() => assert_true(lastline =~# expected_prompt))

# ReplicaSendCell
# {prompt_in_ipython_console: line_in_src_buffer}
var prompts_lines = {2: 4, 3: 7, 4: 9}

for [prompt, line] in items(prompts_lines)
ReplicaSendCell
sleep 2
redraw!
expected_prompt = prompt
term_cursor = term_getcursor(bufnr)
lastline = term_getline(bufnr, term_cursor[0])
WaitForAssert(() => assert_true(lastline =~# expected_prompt))
assert_true(line('.') == line)
endfor

# ReplicaSendLine
cursor(1, 1)
prompts_lines = {5: 2, 6: 3}

for [prompt, line] in items(prompts_lines)
ReplicaSendLine
sleep 1
redraw!
expected_prompt = prompt
term_cursor = term_getcursor(bufnr)
lastline = term_getline(bufnr, term_cursor[0])
WaitForAssert(() => assert_true(lastline =~# expected_prompt))
assert_true(line('.') == line)
endfor

# Double Toggle
ReplicaConsoleToggle
WaitForAssert(() => assert_equal(1, winnr('$')))
WaitForAssert(() => assert_true(bufexists('IPYTHON')))
ReplicaConsoleToggle
WaitForAssert(() => assert_equal(2, winnr('$')))
WaitForAssert(() => assert_true(lastline =~# expected_prompt))
WaitForAssert(() => assert_true(bufexists('IPYTHON')))

# Remove cells
ReplicaRemoveCells
WaitForAssert(() => assert_equal(search(g:replica_cells_delimiters.python, 'cnw'), 0))

# Restart kernel
ReplicaConsoleRestart
sleep 5
redraw!
bufnr = term_list()[0]
term_cursor = term_getcursor(bufnr)
lastline = term_getline(bufnr, term_cursor[0])
expected_prompt = '[1]'
WaitForAssert(() => assert_equal(2, winnr('$')))
WaitForAssert(() => assert_true(lastline =~# expected_prompt))

# ReplicaSendFile
ReplicaSendFile
sleep 3
redraw!
term_cursor = term_getcursor(bufnr)
lastline = term_getline(bufnr, term_cursor[0])
expected_prompt = '[2]'
echom lastline
sleep 2
WaitForAssert(() => assert_equal(2, winnr('$')))
WaitForAssert(() => assert_true(lastline =~# expected_prompt))

# Shutoff
ReplicaConsoleShutoff
WaitForAssert(() => assert_false(bufexists('IPYTHON')))
WaitForAssert(() => assert_equal(1, winnr('$')))

Cleanup_python_testfile()
enddef
3 changes: 0 additions & 3 deletions test/vimrc_for_tests

This file was deleted.