diff --git a/test/helpers/expectations.cc b/test/helpers/expectations.cc index 7fbce90320..22ee5c6d72 100644 --- a/test/helpers/expectations.cc +++ b/test/helpers/expectations.cc @@ -77,8 +77,10 @@ bool addToExpectations(Expectations &exp, string_view filePath, bool isDirectory exp.minimizeRBI = filePath; return true; } else if (absl::EndsWith(filePath, ".rb") || absl::EndsWith(filePath, ".rbi")) { - exp.sourceFiles.emplace_back(filePath); - return true; + if (!absl::EndsWith(filePath, ".snapshot.rb")) { + exp.sourceFiles.emplace_back(filePath); + return true; + } } else if (absl::EndsWith(filePath, ".exp")) { auto kind_start = filePath.rfind(".", filePath.size() - strlen(".exp") - 1); auto kind = filePath.substr(kind_start + 1, filePath.size() - kind_start - strlen(".exp") - 1); diff --git a/test/scip/scip_test.bzl b/test/scip/scip_test.bzl index cf716066ab..08867adfc9 100644 --- a/test/scip/scip_test.bzl +++ b/test/scip/scip_test.bzl @@ -1,11 +1,11 @@ def basename(p): return p.rpartition("/")[-1] -def extension(p): - ext = basename(p).partition(".")[-1] - if ext == ",": # partition returns "," if there is no match 🙃 - return "" - return ext +def split_extension(p): + (before, _, ext) = basename(p).rpartition(".") + if before == "": + (before, ext) = (ext, "") + return (before, ext) def scip_test_suite(paths): tests = [] @@ -28,16 +28,16 @@ def scip_test_suite(paths): def scip_test(path): # path will end in either .snapshot, .rb or have no extension. - ext = extension(path) - if ext == "snapshot": - return - + filename, ext = split_extension(path) if ext != "rb": # TODO(varun): Add support for folder tests, when there is no extension return None + test_name, other_ext = split_extension(filename) + if other_ext != "": + # Don't make separate tests for .snapshot.rb files + return None - test_name = basename(path).partition(".")[0] - snapshot_path = path + ".snapshot" + snapshot_path = path[:-3] + ".snapshot.rb" args = ["$(location {})".format(path), "--output=$(location {})".format(snapshot_path)] data = [path, snapshot_path, "//test:scip_test_runner"] native.sh_test( diff --git a/test/scip/testdata/syntax.rb.snapshot b/test/scip/testdata/syntax.snapshot.rb similarity index 100% rename from test/scip/testdata/syntax.rb.snapshot rename to test/scip/testdata/syntax.snapshot.rb diff --git a/test/scip_test_runner.cc b/test/scip_test_runner.cc index 63c9614651..ffa67c7493 100644 --- a/test/scip_test_runner.cc +++ b/test/scip_test_runner.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/strings/match.h" #include "absl/strings/str_replace.h" #include "spdlog/sinks/stdout_color_sinks.h" @@ -239,9 +240,15 @@ void formatSnapshot(const scip::Document &document, std::ostream &out) { } } +string snapshot_path(string rb_path) { + ENFORCE(absl::EndsWith(rb_path, ".rb")); + rb_path.erase(rb_path.size() - 3, 3); + return rb_path + ".snapshot.rb"; +} + void updateSnapshots(const scip::Index &index, const std::filesystem::path &outputDir) { for (auto &doc : index.documents()) { - auto outputFilePath = doc.relative_path() + ".snapshot"; + auto outputFilePath = snapshot_path(doc.relative_path()); ofstream out(outputFilePath); if (!out.is_open()) { 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 void compareSnapshots(const scip::Index &index, const std::filesystem::path &snapshotDir) { for (auto &doc : index.documents()) { - auto filePath = doc.relative_path() + ".snapshot"; // TODO: Separate out folders! + auto filePath = snapshot_path(doc.relative_path()); // TODO: Separate out folders! ifstream inputStream(filePath); if (!inputStream.is_open()) { FAIL(fmt::format("failed to open snapshot file at {}", filePath));