Compare commits

..

No commits in common. "61188b645343204e115bdf76421c6ac289fa612d" and "adea4b4c97de3adf5778cf958e7e5f837a0d3aae" have entirely different histories.

5 changed files with 1 additions and 82 deletions

View File

@ -1,7 +1,5 @@
test: test:
bash_unit ./tests/test_*.sh bash_unit ./tests/test_*.sh
runtests:
ls -1 zk tests/* | entr -c bash_unit ./tests/test_*.sh
install: install:
test -d ~/.local/bin/ || mkdir -p ~/.local/bin/ test -d ~/.local/bin/ || mkdir -p ~/.local/bin/
cp zk ~/.local/bin/zk cp zk ~/.local/bin/zk

View File

@ -1,44 +0,0 @@
#!/bin/bash
TMP_ZETTELKASTEN=""
setup() {
source ../zk
TMP_ZETTELKASTEN="$(mktemp -d)"
}
teardown() {
rm -rf "$TMP_ZETTELKASTEN"
}
test__zk_rm_gives_error_when_no_zettel_id_given() {
# shellcheck disable=SC2016
#fake rm 'echo'
assert_status_code 1 '_zk_rm'
}
test__zk_rm_gives_error_when_nonexistent_zettel_id_given() {
export ZKDIR="$TMP_ZETTELKASTEN"
zettel_id="11111111111111"
assert_status_code 2 '_zk_rm $zettel_id'
}
test__zk_rm_succeeds_when_existent_zettel_id_given() {
export ZKDIR="$TMP_ZETTELKASTEN"
zettel_id="11111111111111"
touch "$ZKDIR/$zettel_id"
assert_status_code 0 '_zk_rm 11111111111111'
}
test__zk_rm_removes_file_when_existent_zettel_id_given() {
export ZKDIR="$TMP_ZETTELKASTEN"
zettel_id="11111111111111"
echo testing >> "$ZKDIR/$zettel_id"
_zk_rm "$zettel_id"
assert_fails 'test -f "$ZKDIR/$zettel_id"'
}

View File

@ -52,15 +52,6 @@ test_get_command_returns_edit_for_substring() {
done done
} }
test_get_command_returns_edit_for_substring() {
expected="rm"
for arg in r rm; do
result="$(get_command "$ZKCOMMANDS" "$arg")"
assert_equals "$expected" "$result"
done
}
test_get_command_does_not_return_match_unless_at_start_of_command_string() { test_get_command_does_not_return_match_unless_at_start_of_command_string() {
commands="delete" commands="delete"
expected="" expected=""

View File

@ -48,18 +48,6 @@ test_main_calls_edit_when_edit_command_passed() {
assert_equals "$expected" "$result" assert_equals "$expected" "$result"
} }
test_main_calls_rm_when_rm_command_passed() {
fake check_zkdir test
expected="_zk_rm"
fake get_command 'echo rm'
fake _zk_rm "echo $expected"
result="$(main)"
assert_equals "$expected" "$result"
}
test_main_errors_if_unrecognized_command_given() { test_main_errors_if_unrecognized_command_given() {
fake check_zkdir test fake check_zkdir test
fake get_command echo "" fake get_command echo ""

16
zk
View File

@ -3,7 +3,7 @@
set -e set -e
ZKDIR="$HOME/.local/share/zk/" ZKDIR="$HOME/.local/share/zk/"
ZKCOMMANDS='list search new edit rm' ZKCOMMANDS='list search new edit'
check_zkdir() { check_zkdir() {
if ! test -d "$ZKDIR"; then if ! test -d "$ZKDIR"; then
@ -63,20 +63,6 @@ _zk_edit() {
fi fi
} }
_zk_rm() {
if test -z "$1"; then
echo "zk rm: no zettel id given" 1>&2
exit 1
fi
if ! find "$ZKDIR" -name "$1" | grep .; then
echo "zk rm: zettel "$1" not found" 1>&2
exit 2
fi
rm "$ZKDIR/$1"
}
main() { main() {
check_zkdir check_zkdir