This directory contains the test suite for TMC.vim using Vader.vim.
test/
├── README.md # This file
├── helpers.vim # Test utilities and mocks
├── unit/ # Unit tests for individual modules
│ ├── test_util.vader
│ ├── test_project.vader
│ ├── test_course.vader
│ └── test_exercise.vader
└── integration/ # Integration and compatibility tests
├── test_vim_neovim_compat.vader
└── test_workflow.vader
- Vim 8.2+ or Neovim 0.5+
- Vader.vim test framework
# For Vim
git clone --depth 1 https://github.com/junegunn/vader.vim.git ~/.vim/plugged/vader.vim
# For Neovim
git clone --depth 1 https://github.com/junegunn/vader.vim.git \
~/.local/share/nvim/site/pack/vendor/start/vader.vimUsing Vim:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "runtime plugin/tmc.vim" \
-c "Vader! test/**/*.vader"Using Neovim:
nvim --headless -u NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "runtime plugin/tmc.vim" \
-c "Vader! test/**/*.vader"Unit tests only:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "Vader! test/unit/*.vader"Integration tests only:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "Vader! test/integration/*.vader"Single test file:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "Vader! test/unit/test_util.vader"Run tests interactively to see detailed output:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "runtime plugin/tmc.vim" \
-c "Vader test/**/*.vader"(Note: Without the ! after Vader, it runs in interactive mode)
" test/unit/test_mymodule.vader
" Description of what this file tests
Before:
source test/helpers.vim
call helpers#setup()
After:
call helpers#teardown()
Execute (Test case description):
" Arrange
let expected = 'value'
" Act
let result = tmc#mymodule#function()
" Assert
AssertEqual expected, result
Vader.vim provides these assertions:
Assert <condition>- Assert condition is truthyAssertEqual <expected>, <actual>- Assert equalityAssertNotEqual <expected>, <actual>- Assert inequalityAssertThrows <command>- Assert command throws error
The test/helpers.vim file provides:
helpers#setup()- Set up test environmenthelpers#teardown()- Clean up after testshelpers#mock_*_response()- Mock API responseshelpers#create_temp_dir()- Create temporary directoryhelpers#create_mock_exercise_root()- Create mock exercise- Custom assertions
- Isolation: Each test should be independent
- Setup/Teardown: Use Before/After blocks
- Descriptive Names: Test names should clearly describe what they test
- Mock External Calls: Don't make real network requests
- Test Both Success and Failure: Cover happy path and error cases
Execute (tmc#project#find_exercise_root should find .tmcproject.yml):
" Arrange
let temp_dir = helpers#create_temp_dir()
let exercise_dir = temp_dir . '/exercise1'
call helpers#create_mock_exercise_root(exercise_dir)
call writefile(['test'], exercise_dir . '/test.py')
" Act
execute 'edit' exercise_dir . '/test.py'
let root = tmc#project#find_exercise_root()
" Assert
AssertEqual exercise_dir, root
" Cleanup
execute 'bwipeout!'
call delete(temp_dir, 'rf')
Tests run automatically on GitHub Actions for:
- Vim 8.2, 9.0
- Neovim 0.5, 0.9, stable
- Ubuntu and macOS
See .github/workflows/ci.yml for CI configuration.
Ensure the plugin is loaded:
vim -Nu NONE \
-c "set runtimepath+=.,~/.vim/plugged/vader.vim" \
-c "runtime plugin/tmc.vim" \ # This line is important!
-c "Vader! test/**/*.vader"Use --headless with Neovim or check for interactive prompts in your tests.
Ensure Vader.vim is installed and in your runtimepath:
ls ~/.vim/plugged/vader.vim/plugin/vader.vim
# or
ls ~/.local/share/nvim/site/pack/vendor/start/vader.vim/plugin/vader.vimWhile VimScript doesn't have built-in coverage tools, ensure:
- All public functions have at least one test
- Both success and error paths are tested
- Edge cases are covered
When contributing:
- Add tests for new features
- Add tests for bug fixes (regression tests)
- Ensure all tests pass before submitting PR
- Follow the existing test structure and naming conventions
For more information, see CONTRIBUTING.md.