forked from google/vroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasics.vroom
141 lines (87 loc) · 4.09 KB
/
basics.vroom
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
This is a vroom script.
Everything that doesn't start with two spaces is a comment. Feel free to
explain your tests.
Vroom input lines start with ` > `. That's two spaces, a greater-than sign,
and another space. They're passed like :map commands:
> iHello, world!<ESC>
Easy as that. Output lines start with two spaces and check the current buffer.
Hello, world!
Whenever you break up your output tests, vroom goes back to checking the top of
the buffer. Let's check the output again to make sure it hasn't changed:
Hello, world!
It's still good.
You start a new test with three blank lines:
This is a new test! Starting a new test is roughly equivalent to running
> :stopinsert<CR>
> :silent! bufdo! bdelete!<CR>
and then increasing vroom's test counter. If you think three blank lines are
unsightly, you may also begin a new test with the @clear directive. See
examples/directives.vroom for details.
You can leave vim in insert mode between commands, though it's not recommended:
> iHello,
Hello,
> world!<ESC>
Hello, world!
You may also change which buffer you're checking.
> iThis text is in buffer THREE<ESC>
> :vnew<CR>
> iThis text is in buffer 4.<ESC>
This text is in buffer THREE (3)
This text is in buffer 4. (4)
Notice the (3) and (4) at the end of the lines -- these are choosing the buffer
to check, and they're called "vroom controls".
(Why 3 and 4 instead of 1 and 2? Vim buffer numbers are sequential, but they
don't ever reset during a vim session -- you just have to count how many buffers
you've used. It's the nature of the beast.)
Most vroom lines can end in vroom controls, which are a space followed by
parenthesis at the end of a line. You may also do things like select a range of
lines to check or change the match mode. See examples/controls.vroom for more.
You may check message output with ` ~ ` lines. This is useful for catching and
handling errors. Make sure you use `:echomsg` and not vanilla `:echo`! Echos are
not persistent, and vroom has no way of checking them.
> :echomsg "Hello, world!"<CR>
~ Hello, world!
> :echomsg exists('x')<CR>
~ 0
See examples/messages.vroom for more information.
There are two useful shortcuts that you may appreciate. Firstly, you can use
lines starting with ` :` to enter vim commands more succinctly:
:echomsg "Another message!"
~ Another message!
This is exactly equivalent to ` > :echomsg "Another message!"<CR>`
Secondly, you can use lines starting with ` % ` to enter user input.
% Goodbye, world.
Goodbye, world.
Which is exactly equivalent to ` > iGoodby, world.<ESC>`: it enters insert
mode, spits out your text, and exits insert mode.
Be careful with these shortcuts! They only work from normal mode. If vim isn't in
normal mode when you use them, things could get a little hairy..
:new
> i
:LaunchTheNukes
> <ESC>
& :LaunchTheNukes
&
Notice how we just tried to match the output line `:LaunchTheNukes`. We couldn't
write it verbatim, because vroom would have thought it was a control line! So we
used ` & ` instead, which explicitly forces output checking. See
examples/escaping.vroom for details.
The currently running file can be found in the $VROOMFILE environment variable.
It is local to the directory where vroom is started.
:echomsg $VROOMFILE
~ *basics.vroom (glob)
The relative path to the directory containing $VROOMFILE can be found in the
$VROOMDIR environment variable.
If vroom was started from the directory containing $VROOMFILE, $VROOMDIR will
be set to '.', and so a file in the same directory as $VROOMFILE can be named
using a path such as $VROOMDIR/foo.vim.
:echomsg $VROOMDIR
~ (\.|(.+/)?examples) (regex)
That's all there is to it!
In more complicated tests you may need to sandbox vim, preventing it from doing
things like hitting the network for data. To learn how to hijack system calls,
see examples/system.vroom.
If you have weird test output that you need to match, you may want to check out
examples/escaping.vroom and examples/continuations.vroom.
Then you just run the vroom script (you can use -v for extra output) on your
vroom file, and away you go!