add bats test suite

This commit is contained in:
bth 2024-01-19 09:15:49 -08:00
commit ad5c5cca2e
13 changed files with 104 additions and 3 deletions

View file

@ -37,6 +37,13 @@ if [ $2 ]; then
fi
fi
# HACK: emacs won't accept piped input as a file name, so we use --eval to open
# the file via find-file.
emacsclient --eval "(progn (find-file \"$NEXTFILE\") (um-journal-header) $UMTAG (message \"creating $NEXTFILE\"))"
UMELISP="(progn (find-file \"$NEXTFILE\") (um-journal-header) $UMTAG (message \"creating $NEXTFILE\"))"
# for testing and piping
if [ $UMNEXTECHO = true ]; then
echo $NEXTFILE $UMTAG
else
# HACK: emacs won't accept piped input as a file name, so we use --eval to open
# the file via find-file.
emacsclient --eval "$UMELISP"
fi

1
shell/test/bats Submodule

@ -0,0 +1 @@
Subproject commit 3d3f63d9772b98c88586ec0a66bd358a85d9b4a6

@ -0,0 +1 @@
Subproject commit e2d855bc78619ee15b0c702b5c30fb074101159f

@ -0,0 +1 @@
Subproject commit 9bf10e876dd6b624fe44423f0b35e064225f7556

82
shell/test/um.bats Normal file
View file

@ -0,0 +1,82 @@
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables visible to PATH
PATH="$DIR/..:$PATH"
# commands depend on being in the journal/ path.
cd $DIR/mockjournal
# so that we can run next.sh without dealing with emacsclient.
export UMNEXTECHO=true
}
teardown() {
export UMNEXTECHO=false
cd -
}
@test "um usage" {
run um
assert_output 'usage: um (next|last|cat|rename|tag)'
}
@test "next empty" {
run um next
assert_output '100.md'
}
@test "next descriptor" {
run um next foo
assert_output '100.foo.md'
}
@test "next descriptor tag" {
run um next foo bar
assert_output --partial '(insert "+ bar\n")'
}
@test "next descriptor +" {
run um next foo +
assert_output --partial '(insert "+ foo\n")'
}
@test "um last" {
run um last
assert_output '099.poo.md'
}
@test "um cat" {
run um cat 001.md 002.blah.md
assert_output '# 001
: 2024.01.14
+ foo
---
# 002.blah
: 2024.01.14
+ foo'
}
um_rename_awk() {
echo "$1
$2" | awk -f ../../rename.awk
}
@test "rename.awk" {
run um_rename_awk 01.md foo
assert_output '01.md 01.foo.md'
run um_rename_awk 01.foo.md bar
assert_output '01.foo.md 01.bar.md'
}
@test "um tag" {
run um tag foo
assert_output '001.md
002.blah.md'
}