Implementations of scenario steps ================================ This chapter contains implementations for the various steps used in the scenarios above. No use of git ------------- The test suite won't be using git. Normally `jt` would add new notes to git, and commit them, but there's no need for that during the test suite. That part either works or it doesn't, and it's simple enough that it almost certainly will work. (Go on, make me eat my words.) However, running git adds more complexity to the test suite, such as dealing with the git configuration, or lack thereof, of the user running the test suite. Set up an empty journal ----------------------- For tests, we need an empty journal. IMPLEMENTS GIVEN an empty journal in (\S+) mkdir "$DATADIR/$MATCH_1" cat < "$DATADIR/source.conf" [config] source = $DATADIR/$MATCH_1 EOF cd "$DATADIR/$MATCH_1" git init . touch README git add README git commit -m initial Keeping time ------------ For various things we need to pretend we know what the time is. For example, we may need to test that a filename is generated correctly from the current timestamp. Because of this, `jt` has a `--pretend-time` setting, which we will use extensively in the test suite. Within the test suite we implement this by having a `time.conf` configuration file, created by a "GIVEN the time is ..." step, and making sure we give that configuration file to `jt` when it's run by the test suite. IMPLEMENTS GIVEN the time is (\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) cat < "$DATADIR/time.conf" [config] pretend-time = $MATCH_1 EOF Running jt commands ------------------- We run `jt` from the source tree, without any configurations from the user, and with specific settings to make the test suite run smoother. IMPLEMENTS WHEN I run jt (.*) run_jt $MATCH_1 Sometimes we expect `jt` to fail. In that case, the scenario step shouldn't fail. IMPLEMENTS WHEN I try to run jt (.*) run_jt $MATCH_1 || true Check that the latest invocation of `jt` didn't fail. IMPLEMENTS THEN it fails ! grep -Fx 0 "$DATADIR/jt.exit" Checking file existence ----------------------- Does a file exist? IMPLEMENTS THEN file (\S+) exists test -e "$DATADIR/$MATCH_1" Does a file _not_ exist? IMPLEMENTS THEN file (\S+) doesn't exist ! test -e "$DATADIR/$MATCH_1" Checking file contents ---------------------- Does a file match a regular expression? IMPLEMENTS THEN file (\S+) matches (.+)$ grep -e "$MATCH_2" "$DATADIR/$MATCH_1"