Skip to content

Commit ff3e3b5

Browse files
committed
Add basic tests
Test that venv and virtualenv environments are activated properly.
1 parent bc59a5c commit ff3e3b5

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

.github/workflows/venv.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test venv environments activation
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v5
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v6
17+
with:
18+
python-version: "3.12" # Vim on Ubuntu supports only 3.12
19+
20+
- name: Set up Vim
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install --yes vim
24+
25+
- name: Set up virtual environment
26+
run: |
27+
export VIM_VIRTUALENV_TARGET="$(mktemp --directory)"
28+
python -m venv "${VIM_VIRTUALENV_TARGET}"
29+
echo "VIM_VIRTUALENV_TARGET=${VIM_VIRTUALENV_TARGET}" >> "${GITHUB_ENV}"
30+
31+
- name: Test internal virtual environment
32+
run: |
33+
cd "${VIM_VIRTUALENV_TARGET}"
34+
vim --not-a-term -u "${GITHUB_WORKSPACE}/.github/workflows/vimrc.github" \
35+
-c "call assert_equal(1, virtualenv#state('virtualenv_internal'))" \
36+
-c "call assert_equal('venv', virtualenv#state('virtualenv_type'))" \
37+
-c "call assert_equal('${VIM_VIRTUALENV_TARGET}', virtualenv#state('virtualenv_directory'))" \
38+
-c "call g:ExitTest()"
39+
40+
- name: Test external virtual environment
41+
run: |
42+
source "${VIM_VIRTUALENV_TARGET}/bin/activate"
43+
vim --not-a-term -u "${GITHUB_WORKSPACE}/.github/workflows/vimrc.github" \
44+
-c "call assert_equal(0, virtualenv#state('virtualenv_internal'))" \
45+
-c "call assert_equal('venv', virtualenv#state('virtualenv_type'))" \
46+
-c "call assert_equal('${VIM_VIRTUALENV_TARGET}', virtualenv#state('virtualenv_directory'))" \
47+
-c "call g:ExitTest()"

.github/workflows/vimrc.github

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set nocompatible
2+
let &runtimepath = expand('$GITHUB_WORKSPACE')..','..&runtimepath
3+
4+
let g:virtualenv#auto_activate_everywhere = 1
5+
6+
function! g:ExitTest()
7+
for l:err in v:errors | echo l:err | endfor
8+
execute 'cquit! '..!empty(v:errors)
9+
endfunction

.github/workflows/virtualenv.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test virtualenv environments activation
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v5
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v6
17+
with:
18+
python-version: "3.12" # Vim on Ubuntu supports only 3.12
19+
20+
- name: Set up Vim
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install --yes vim
24+
25+
- name: Set up virtual environment
26+
run: |
27+
python -m pip install virtualenv
28+
export VIM_VIRTUALENV_TARGET="$(mktemp --directory)"
29+
python -m virtualenv "${VIM_VIRTUALENV_TARGET}"
30+
echo "VIM_VIRTUALENV_TARGET=${VIM_VIRTUALENV_TARGET}" >> "${GITHUB_ENV}"
31+
32+
- name: Test internal virtual environment
33+
run: |
34+
cd "${VIM_VIRTUALENV_TARGET}"
35+
vim --not-a-term -u "${GITHUB_WORKSPACE}/.github/workflows/vimrc.github" \
36+
-c "call assert_equal(1, virtualenv#state('virtualenv_internal'))" \
37+
-c "call assert_equal('virtualenv', virtualenv#state('virtualenv_type'))" \
38+
-c "call assert_equal('${VIM_VIRTUALENV_TARGET}', virtualenv#state('virtualenv_directory'))" \
39+
-c "call g:ExitTest()"
40+
41+
- name: Test external virtual environment
42+
run: |
43+
source "${VIM_VIRTUALENV_TARGET}/bin/activate"
44+
vim --not-a-term -u "${GITHUB_WORKSPACE}/.github/workflows/vimrc.github" \
45+
-c "call assert_equal(0, virtualenv#state('virtualenv_internal'))" \
46+
-c "call assert_equal('virtualenv', virtualenv#state('virtualenv_type'))" \
47+
-c "call assert_equal('${VIM_VIRTUALENV_TARGET}', virtualenv#state('virtualenv_directory'))" \
48+
-c "call g:ExitTest()"

0 commit comments

Comments
 (0)