|
| 1 | +#!./test/libs/bats/bin/bats |
| 2 | + |
| 3 | +load 'libs/bats-support/load' |
| 4 | +load 'libs/bats-assert/load' |
| 5 | +load 'helpers' |
| 6 | + |
| 7 | +setup() { |
| 8 | + setupNotesEnv |
| 9 | +} |
| 10 | + |
| 11 | +teardown() { |
| 12 | + teardownNotesEnv |
| 13 | +} |
| 14 | + |
| 15 | +notes="./notes" |
| 16 | + |
| 17 | +@test "Should show created note" { |
| 18 | + echo line1 >> "$NOTES_DIRECTORY/note.md" |
| 19 | + echo line2 >> "$NOTES_DIRECTORY/note.md" |
| 20 | + run $notes cat note.md |
| 21 | + |
| 22 | + assert_success |
| 23 | + assert_output $'line1\nline2' |
| 24 | +} |
| 25 | + |
| 26 | +@test "Accepts names without .md to show" { |
| 27 | + echo line1 >> "$NOTES_DIRECTORY/note.md" |
| 28 | + echo line2 >> "$NOTES_DIRECTORY/note.md" |
| 29 | + run $notes cat note |
| 30 | + |
| 31 | + assert_success |
| 32 | + assert_output $'line1\nline2' |
| 33 | +} |
| 34 | + |
| 35 | +@test "Should fail to show non-existent note" { |
| 36 | + run $notes cat note |
| 37 | + |
| 38 | + assert_failure |
| 39 | +} |
| 40 | + |
| 41 | +@test "Accepts relative notes paths to show" { |
| 42 | + echo line1 >> "$NOTES_DIRECTORY/note.md" |
| 43 | + echo line2 >> "$NOTES_DIRECTORY/note.md" |
| 44 | + run $notes cat $NOTES_DIRECTORY/note.md |
| 45 | + |
| 46 | + assert_success |
| 47 | + assert_output $'line1\nline2' |
| 48 | +} |
| 49 | + |
| 50 | +@test "Show a file passed by pipe from find" { |
| 51 | + echo line1 >> "$NOTES_DIRECTORY/note.md" |
| 52 | + echo line2 >> "$NOTES_DIRECTORY/note.md" |
| 53 | + |
| 54 | + run bash -c "$notes find | $notes cat" |
| 55 | + |
| 56 | + assert_success |
| 57 | + assert_output $'line1\nline2' |
| 58 | +} |
| 59 | + |
| 60 | +@test "Show multiple files passed by pipe from find" { |
| 61 | + echo line1 >> "$NOTES_DIRECTORY/note.md" |
| 62 | + echo line2 >> "$NOTES_DIRECTORY/note2.md" |
| 63 | + |
| 64 | + run bash -c "$notes find | $notes cat" |
| 65 | + |
| 66 | + assert_success |
| 67 | + assert_output $'line1\nline2' |
| 68 | +} |
| 69 | + |
| 70 | +@test "Should complain and ask for a name if one is not provided to show" { |
| 71 | + run $notes cat |
| 72 | + |
| 73 | + assert_failure |
| 74 | + assert_line "Cat requires a name, but none was provided." |
| 75 | +} |
0 commit comments