From bc4b416f534c00bb273f347d8ccf48c51932f66a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 28 Dec 2019 10:24:56 +0100 Subject: [PATCH] Fix WIKIROOT env var tests Fixed tests using new file structure for personal environment variables. Added test cases for library environment variable and bibtex (default) reference file variable. --- .config/shell/login.d/env-vars.sh | 6 +-- .config/shell/login.d/test/env-wiki-root.bats | 48 +++++++++++++++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.config/shell/login.d/env-vars.sh b/.config/shell/login.d/env-vars.sh index a53e2d1..a4421c9 100644 --- a/.config/shell/login.d/env-vars.sh +++ b/.config/shell/login.d/env-vars.sh @@ -3,9 +3,9 @@ # important directories # will be picked up by vim wiki plugin as root directory -export WIKIROOT="$HOME/documents/notes/" -export LIBRARYROOT="$HOME/documents/library" -export BIBFILE="$LIBRARYROOT/academia/academia.bib" +export WIKIROOT="${WIKIROOT:-$HOME/documents/notes/}" +export LIBRARYROOT="${LIBRARYROOT:-$HOME/documents/library/}" +export BIBFILE="${BIBFILE:-$LIBRARYROOT/academia/academia.bib}" # these are my personal 'important' environment settings export EDITOR=nvim diff --git a/.config/shell/login.d/test/env-wiki-root.bats b/.config/shell/login.d/test/env-wiki-root.bats index 422bcb9..0a39821 100644 --- a/.config/shell/login.d/test/env-wiki-root.bats +++ b/.config/shell/login.d/test/env-wiki-root.bats @@ -1,9 +1,16 @@ +# FIXME why is one saved with trailing "/" , the other not? +DEFAULT_NOTES="$HOME/documents/notes/" +DEFAULT_LIB="$HOME/documents/library" +DEFAULT_BIB="$DEFAULT_LIB/academia/academia.bib" + setup() { - testfile="$BATS_TEST_DIRNAME/../env-wiki-root.sh" + testfile="$BATS_TEST_DIRNAME/../env-vars.sh" } teardown() { - export WIKIROOT="" + unset WIKIROOT + unset LIBRARYROOT + unset BIBFILE } @test "Populates WIKIROOT environment variable" { @@ -13,7 +20,8 @@ teardown() { @test "Sets WIKIROOT to correct default path" { source $testfile - [ "$WIKIROOT" = "$HOME/documents/notes" ] + echo $WIKIROOT + [ "$WIKIROOT" = "$DEFAULT_NOTES" ] } @test "Leaves WIKIROOT as is if it is already set" { @@ -21,3 +29,37 @@ teardown() { source $testfile [ "$WIKIROOT" = "MY/CUSTOM/DIR" ] } + +@test "Populates LIBRARYROOT environment variable" { + source $testfile + [ -n "$LIBRARYROOT" ] +} + +@test "Sets LIBRARYROOT to correct default path" { + source $testfile + echo $LIBRARYROOT + [ "$LIBRARYROOT" = "$DEFAULT_LIB" ] +} + +@test "Leaves LIBRARYROOT as is if it is already set" { + export LIBRARYROOT="MY/CUSTOM/DIR" + source $testfile + [ "$LIBRARYROOT" = "MY/CUSTOM/DIR" ] +} + +@test "Populates BIBFILE environment variable" { + source $testfile + [ -n "$BIBFILE" ] +} + +@test "Sets BIBFILE to correct default path" { + source $testfile + echo $BIBFILE + [ "$BIBFILE" = "$DEFAULT_BIB" ] +} + +@test "Leaves BIBFILE as is if it is already set" { + export BIBFILE="MY/CUSTOM/DIR" + source $testfile + [ "$BIBFILE" = "MY/CUSTOM/DIR" ] +}