Skip to content

test: Use .snapshot.rb extension instead of .rb.snapshot. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/helpers/expectations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions test/scip/scip_test.bzl
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions test/scip_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sys/types.h>
#include <vector>

#include "absl/strings/match.h"
#include "absl/strings/str_replace.h"
#include "spdlog/sinks/stdout_color_sinks.h"

Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down