Skip to content

Commit d256620

Browse files
test: Use .snapshot.rb extension instead of .rb.snapshot. (#7)
Using .rb at the end makes syntax highlighting work out-of-the-box.
1 parent 1961cce commit d256620

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

test/helpers/expectations.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ bool addToExpectations(Expectations &exp, string_view filePath, bool isDirectory
7777
exp.minimizeRBI = filePath;
7878
return true;
7979
} else if (absl::EndsWith(filePath, ".rb") || absl::EndsWith(filePath, ".rbi")) {
80-
exp.sourceFiles.emplace_back(filePath);
81-
return true;
80+
if (!absl::EndsWith(filePath, ".snapshot.rb")) {
81+
exp.sourceFiles.emplace_back(filePath);
82+
return true;
83+
}
8284
} else if (absl::EndsWith(filePath, ".exp")) {
8385
auto kind_start = filePath.rfind(".", filePath.size() - strlen(".exp") - 1);
8486
auto kind = filePath.substr(kind_start + 1, filePath.size() - kind_start - strlen(".exp") - 1);

test/scip/scip_test.bzl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
def basename(p):
22
return p.rpartition("/")[-1]
33

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
4+
def split_extension(p):
5+
(before, _, ext) = basename(p).rpartition(".")
6+
if before == "":
7+
(before, ext) = (ext, "")
8+
return (before, ext)
99

1010
def scip_test_suite(paths):
1111
tests = []
@@ -28,16 +28,16 @@ def scip_test_suite(paths):
2828
def scip_test(path):
2929
# path will end in either .snapshot, .rb or have no extension.
3030

31-
ext = extension(path)
32-
if ext == "snapshot":
33-
return
34-
31+
filename, ext = split_extension(path)
3532
if ext != "rb":
3633
# TODO(varun): Add support for folder tests, when there is no extension
3734
return None
35+
test_name, other_ext = split_extension(filename)
36+
if other_ext != "":
37+
# Don't make separate tests for .snapshot.rb files
38+
return None
3839

39-
test_name = basename(path).partition(".")[0]
40-
snapshot_path = path + ".snapshot"
40+
snapshot_path = path[:-3] + ".snapshot.rb"
4141
args = ["$(location {})".format(path), "--output=$(location {})".format(snapshot_path)]
4242
data = [path, snapshot_path, "//test:scip_test_runner"]
4343
native.sh_test(

test/scip_test_runner.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sys/types.h>
1414
#include <vector>
1515

16+
#include "absl/strings/match.h"
1617
#include "absl/strings/str_replace.h"
1718
#include "spdlog/sinks/stdout_color_sinks.h"
1819

@@ -239,9 +240,15 @@ void formatSnapshot(const scip::Document &document, std::ostream &out) {
239240
}
240241
}
241242

243+
string snapshot_path(string rb_path) {
244+
ENFORCE(absl::EndsWith(rb_path, ".rb"));
245+
rb_path.erase(rb_path.size() - 3, 3);
246+
return rb_path + ".snapshot.rb";
247+
}
248+
242249
void updateSnapshots(const scip::Index &index, const std::filesystem::path &outputDir) {
243250
for (auto &doc : index.documents()) {
244-
auto outputFilePath = doc.relative_path() + ".snapshot";
251+
auto outputFilePath = snapshot_path(doc.relative_path());
245252
ofstream out(outputFilePath);
246253
if (!out.is_open()) {
247254
FAIL(fmt::format("failed to open snapshot output file at {}", outputFilePath));
@@ -252,7 +259,7 @@ void updateSnapshots(const scip::Index &index, const std::filesystem::path &outp
252259

253260
void compareSnapshots(const scip::Index &index, const std::filesystem::path &snapshotDir) {
254261
for (auto &doc : index.documents()) {
255-
auto filePath = doc.relative_path() + ".snapshot"; // TODO: Separate out folders!
262+
auto filePath = snapshot_path(doc.relative_path()); // TODO: Separate out folders!
256263
ifstream inputStream(filePath);
257264
if (!inputStream.is_open()) {
258265
FAIL(fmt::format("failed to open snapshot file at {}", filePath));

0 commit comments

Comments
 (0)