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
|
import json
import os
import shutil
import time
# A shell script to run the subplot binary from the source directory's Rust
# build target directory, adding the -t option to use the source directory's
# template directory.
#
# This is a string template where the source directory is filled in when used.
wrapper = """\
#!/bin/sh
set -eu
exec '{srcdir}/target/debug/{prog}' --resources '{srcdir}/share' "$@"
"""
def install_subplot(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
# We require the SUBPLOT_DIR environment variable to be set to the path to
# the directory where the Subplot binaries are installed.
bindir = os.environ.get("SUBPLOT_DIR")
assert (
bindir is not None
), "MUST set SUBPLOT_DIR to directory where Subplot binaries are installed"
runcmd_prepend_to_path(ctx, dirname=bindir)
def uninstall_subplot(ctx):
if "bin-dir" in ctx:
bindir = ctx["bin-dir"]
if os.path.exists(bindir):
shutil.rmtree(bindir)
def scenario_was_run(ctx, name=None):
runcmd_stdout_contains = globals()["runcmd_stdout_contains"]
runcmd_stdout_contains(ctx, text="\nscenario: {}\n".format(name))
def scenario_was_not_run(ctx, name=None):
runcmd_stdout_doesnt_contain = globals()["runcmd_stdout_doesnt_contain"]
runcmd_stdout_doesnt_contain(ctx, text="\nscenario: {}\n".format(name))
def step_was_run(ctx, keyword=None, name=None):
runcmd_stdout_contains = globals()["runcmd_stdout_contains"]
runcmd_stdout_contains(ctx, text="\n step: {} {}\n".format(keyword, name))
def step_was_run_and_then(ctx, keyword1=None, name1=None, keyword2=None, name2=None):
runcmd_stdout_contains = globals()["runcmd_stdout_contains"]
runcmd_stdout_contains(
ctx,
text="\n step: {} {}\n step: {} {}".format(keyword1, name1, keyword2, name2),
)
def cleanup_was_run(ctx, keyword1=None, name1=None, keyword2=None, name2=None):
runcmd_stdout_contains = globals()["runcmd_stdout_contains"]
runcmd_stdout_contains(
ctx,
text="\n cleanup: {} {}\n cleanup: {} {}\n".format(
keyword1, name1, keyword2, name2
),
)
def cleanup_was_not_run(ctx, keyword=None, name=None):
runcmd_stdout_doesnt_contain = globals()["runcmd_stdout_doesnt_contain"]
runcmd_stdout_doesnt_contain(ctx, text="\n cleanup: {} {}\n".format(keyword, name))
def json_output_matches_file(ctx, filename=None):
assert_dict_eq = globals()["assert_dict_eq"]
ns = ctx.declare("_runcmd")
actual = json.loads(ns["stdout"])
expected = json.load(open(filename))
assert_dict_eq(actual, expected)
def file_ends_in_zero_newlines(ctx, filename=None):
assert_ne = globals()["assert_ne"]
content = open(filename, "r").read()
assert_ne(content[-1], "\n")
def file_ends_in_one_newline(ctx, filename=None):
assert_eq = globals()["assert_eq"]
assert_ne = globals()["assert_ne"]
content = open(filename, "r").read()
assert_eq(content[-1], "\n")
assert_ne(content[-2], "\n")
def file_ends_in_two_newlines(ctx, filename=None):
assert_eq = globals()["assert_eq"]
content = open(filename, "r").read()
assert_eq(content[-2:], "\n\n")
def binary(basename):
srcdir = globals()["srcdir"]
return os.path.join(srcdir, "target", "debug", basename)
def do_nothing(ctx):
pass
def sleep_seconds(ctx, delay="1"):
time.sleep(int(delay))
|