Skip to content

Commit 7fff89f

Browse files
wip: Setup testing for SCIP!
1 parent 86822d1 commit 7fff89f

File tree

10 files changed

+564
-1
lines changed

10 files changed

+564
-1
lines changed

test/BUILD

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,43 @@ cc_binary(
5757
],
5858
)
5959

60+
cc_binary(
61+
name = "scip_test_runner",
62+
testonly = 1,
63+
srcs = [
64+
"scip_test_runner.cc"
65+
],
66+
linkstatic = select({
67+
"//tools/config:linkshared": 0,
68+
"//conditions:default": 1,
69+
}),
70+
visibility = ["//tools:__pkg__", "//test/scip:__pkg__"],
71+
deps = [ # TODO(varun): Revisit dependencies after rewriting test runner.
72+
"//ast/desugar",
73+
"//ast/treemap",
74+
"//cfg/builder",
75+
"//class_flatten",
76+
"//common/web_tracer_framework:tracing",
77+
"//core/serialize",
78+
"//definition_validator",
79+
"//infer",
80+
"//local_vars",
81+
"//main/autogen", # TODO(varun): why is this needed?
82+
"//namer",
83+
"//payload",
84+
"//proto",
85+
"//resolver",
86+
"//rewriter",
87+
"//scip_indexer:interface",
88+
"//scip_indexer:scip_indexer",
89+
"//test/helpers",
90+
"@com_google_absl//absl/strings",
91+
"@cxxopts",
92+
"@doctest",
93+
"@doctest//:doctest_custom_main",
94+
]
95+
)
96+
6097
cc_binary(
6198
name = "parser_test_runner",
6299
testonly = 1,
@@ -251,6 +288,17 @@ pipeline_tests(
251288
"WhitequarkParserTests",
252289
)
253290

291+
pipeline_tests(
292+
"test_corpus_scip",
293+
glob(
294+
[
295+
"testdata/scip/**/*.rb",
296+
"testdata/scip/**/*.exp",
297+
],
298+
),
299+
"SCIPTests",
300+
)
301+
254302
pipeline_tests(
255303
"test_corpus_lsp",
256304
glob(

test/pipeline_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def single_package_rbi_test(name, rb_files):
100100
_TEST_RUNNERS = {
101101
"PosTests": ":pipeline_test_runner",
102102
"LSPTests": ":lsp_test_runner",
103+
"SCIPTests": ":scip_test_runner",
103104
"WhitequarkParserTests": ":parser_test_runner",
104105
"PackagerTests": ":pipeline_test_runner",
105106
}

test/scip/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load(":scip_test.bzl", "scip_test_suite")
2+
3+
scip_test_suite(paths = glob(["testdata/*"]))

test/scip/scip_test.bzl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
def basename(p):
2+
return p.rpartition("/")[-1]
3+
4+
def extension(p):
5+
ext = basename(p).partition(".")[-1]
6+
if ext == ",": # partition returns "," if there is no match 🙃
7+
return ""
8+
return ext
9+
10+
def scip_test_suite(paths):
11+
tests = []
12+
updates = []
13+
for path in paths:
14+
names = scip_test(path)
15+
if names:
16+
tests.append(names[0])
17+
updates.append(names[1])
18+
native.test_suite(
19+
name = "scip",
20+
tests = tests,
21+
)
22+
native.test_suite(
23+
name = "update",
24+
tests = updates,
25+
)
26+
27+
28+
def scip_test(path):
29+
# path will end in either .snapshot, .rb or have no extension.
30+
31+
ext = extension(path)
32+
if ext == "snapshot":
33+
return
34+
35+
if ext != "rb":
36+
# TODO(varun): Add support for folder tests, when there is no extension
37+
return None
38+
39+
test_name = basename(path).partition(".")[0]
40+
snapshot_path = path + ".snapshot"
41+
args = ["$(location {})".format(path), "--output=$(location {})".format(snapshot_path)]
42+
data = [path, snapshot_path, "//test:scip_test_runner"]
43+
native.sh_test(
44+
name = test_name,
45+
srcs = ["scip_test_runner.sh"],
46+
args = args,
47+
data = data,
48+
size = "small",
49+
)
50+
update_test_name = "update_".format(test_name)
51+
native.sh_test(
52+
name = update_test_name,
53+
srcs = ["scip_test_runner.sh"],
54+
args = args + ["--update-snapshots"],
55+
data = data,
56+
tags = ["manual"],
57+
size = "small",
58+
)
59+
return (test_name, update_test_name)

test/scip/scip_test_runner.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
./test/scip_test_runner "$@"

test/scip/testdata/syntax.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# typed: true
2+
3+
a = [57, 33]
4+
i = 0
5+
a[i] # a.[](i)
6+
a << 970 # a.push(970)
7+
a[2..-1]
8+
9+
def globalFn1()
10+
x = 10
11+
x
12+
end
13+
14+
def globalFn2()
15+
x = globalFn1()
16+
end

test/scip/testdata/syntax.rb.snapshot

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# typed: true
2+
3+
a = [57, 33]
4+
#^ definition local 1~#119448696
5+
#^^^^^^^^^^^^^^^ definition scip-ruby gem TODO TODO <static-init>().
6+
i = 0
7+
#^ definition local 2~#119448696
8+
a[i] # a.[](i)
9+
#^ reference local 1~#119448696
10+
a << 970 # a.push(970)
11+
#^ reference local 1~#119448696
12+
a[2..-1]
13+
#^ reference local 1~#119448696
14+
15+
def globalFn1()
16+
#^^^^^^^^^^^^^^^ definition scip-ruby gem TODO TODO globalFn1().
17+
x = 10
18+
# ^ definition local 1~#3846536873
19+
x
20+
# ^ reference local 1~#3846536873
21+
end
22+
23+
def globalFn2()
24+
#^^^^^^^^^^^^^^^ definition scip-ruby gem TODO TODO globalFn2().
25+
x = globalFn1()
26+
# ^ definition local 1~#3796204016
27+
# ^^^^^^^^^^^^^^^ reference local 1~#3796204016
28+
# ^^^^^^^^^ reference scip-ruby gem TODO TODO globalFn1().
29+
end

0 commit comments

Comments
 (0)