29123e88a2a39ec57d1cd632ffa3241584c36e77

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
Michael Aquilina <michaelaquilina@gmail.com>
Date

Message

Add some _check_venv_path tests

Diff

 1diff --git a/tests/test_check_venv_path.zunit b/tests/test_check_venv_path.zunit
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..0b951e495de51720f93e902dc2c6439d8c7d7d7f
 4--- /dev/null
 5+++ b/tests/test_check_venv_path.zunit
 6@@ -0,0 +1,49 @@
 7+#!/usr/bin/env zunit
 8+
 9+@setup {
10+    load "../autoswitch_virtualenv.plugin.zsh"
11+    target="$(mktemp -d)"
12+    assert "$target" is_dir
13+}
14+
15+@teardown {
16+    rm -rf "$target"
17+}
18+
19+@test 'precmd functions are loaded' {
20+    assert '_check_venv' in $precmd_functions
21+}
22+
23+@test '_check_venv_path with bad path works' {
24+    run _check_venv_path '/i/dont/exist'
25+
26+    assert "$output" is_empty
27+    assert $state equals 0
28+}
29+
30+@test '_check_venv_path with no venv' {
31+    run _check_venv_path "$target"
32+
33+    assert "$output" is_empty
34+    assert $state equals 0
35+}
36+
37+@test '_check_venv_path with existing venv' {
38+    touch "$target/.venv"
39+    assert "$target/.venv" is_file
40+
41+    run _check_venv_path "$target"
42+
43+    assert "$output" same_as "$target/.venv"
44+    assert $state equals 0
45+}
46+
47+@test '_check_venv_path in subdirectory with parent venv' {
48+    touch "$target/.venv"
49+    assert "$target/.venv" is_file
50+
51+    run _check_venv_path "$target/src/examples"
52+
53+    assert "$output" same_as "$target/.venv"
54+    assert $state equals 0
55+}