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
|
"""Defines a rule for runtime test targets."""
load("//tools:defs.bzl", "go_test")
def _runtime_test_impl(ctx):
# Construct arguments.
args = [
"--lang",
ctx.attr.lang,
"--image",
ctx.attr.image,
]
if ctx.attr.exclude_file:
args += [
"--exclude_file",
ctx.files.exclude_file[0].short_path,
]
# Build a runner.
runner = ctx.actions.declare_file("%s-executer" % ctx.label.name)
runner_content = "\n".join([
"#!/bin/bash",
"%s %s $@\n" % (ctx.files._runner[0].short_path, " ".join(args)),
])
ctx.actions.write(runner, runner_content, is_executable = True)
# Return the runner.
return [DefaultInfo(
executable = runner,
runfiles = ctx.runfiles(
files = ctx.files._runner + ctx.files.exclude_file + ctx.files._proctor,
collect_default = True,
collect_data = True,
),
)]
_runtime_test = rule(
implementation = _runtime_test_impl,
attrs = {
"image": attr.string(
mandatory = False,
),
"lang": attr.string(
mandatory = True,
),
"exclude_file": attr.label(
mandatory = False,
allow_single_file = True,
),
"_runner": attr.label(
default = "//test/runtimes/runner:runner",
),
"_proctor": attr.label(
default = "//test/runtimes/proctor:proctor",
),
},
test = True,
)
def runtime_test(name, **kwargs):
_runtime_test(
name = name,
image = name, # Resolved as images/runtimes/%s.
tags = [
"local",
"manual",
],
**kwargs
)
def exclude_test(name, exclude_file):
"""Test that a exclude file parses correctly."""
go_test(
name = name + "_exclude_test",
library = ":runner",
srcs = ["exclude_test.go"],
args = ["--exclude_file", "test/runtimes/" + exclude_file],
data = [exclude_file],
)
|