summaryrefslogtreecommitdiff
path: root/yarns/900-implementations.yarn
blob: a2e149f41d12fd170da4c6d849506e23011e3bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Implementatios 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 <<EOF > "$DATADIR/source.conf"
    [config]
    source = $DATADIR/$MATCH_1
    EOF


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 <<EOF > "$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 (\S+)
    grep -e "$MATCH_2" "$DATADIR/$MATCH_1"