Skip to content

Commit b03c456

Browse files
authored
Merge pull request #56 from rmNULL/master
exit 1 on failure to create NOTES_DIRECTORY
2 parents 7352030 + 14e8f59 commit b03c456

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

notes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ notes_dir="${configured_dir:-$HOME/notes}"
1313
escaped_notes_dir="$(printf "$notes_dir" | sed -e 's/[]\/$*.^|[]/\\&/g')"
1414

1515
# Make sure the notes directory actually exists, and create it if it doesn't
16-
if [ ! -d "$notes_dir" ]; then
17-
mkdir -p "$notes_dir"
16+
if ! $(mkdir -p "$notes_dir"); then
17+
echo "Could not create directory $notes_dir, please update your \$NOTES_DIRECTORY" >&2
18+
exit 1
1819
fi
1920

2021
# If no $EDITOR, look for `editor` (symlink on debian/ubuntu/etc)

test/test-config.bats

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ notes="./notes"
4242
assert_success
4343
assert_exists "$NOTES_DIRECTORY/test.txt"
4444
}
45+
46+
@test "Configuration should be accepted if NOTES_DIR doesn't exist" {
47+
mkdir -p $HOME/.config/notes
48+
echo "NOTES_DIRECTORY=$NOTES_DIRECTORY/notesdir" > $HOME/.config/notes/config
49+
run $notes new test
50+
51+
assert_success
52+
}
53+
54+
@test "Configuration should be rejected if NOTES_DIR is a existing file" {
55+
mkdir -p $HOME/.config/notes
56+
touch $NOTES_DIRECTORY/testfile
57+
echo "NOTES_DIRECTORY=$NOTES_DIRECTORY/testfile" > $HOME/.config/notes/config
58+
run $notes new test
59+
60+
assert_failure
61+
assert_line "Could not create directory $NOTES_DIRECTORY/testfile, please update your \$NOTES_DIRECTORY"
62+
}

0 commit comments

Comments
 (0)