Skip to content

Commit 5e4eed9

Browse files
authored
Merge pull request #7949 from roc-lang/expected-snapshots
Tests for snapshots using EXPECTED
2 parents 60ae226 + e800cc6 commit 5e4eed9

File tree

927 files changed

+9250
-2131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

927 files changed

+9250
-2131
lines changed

build.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn build(b: *std.Build) void {
1717
const fmt_step = b.step("fmt", "Format all zig code");
1818
const check_fmt_step = b.step("check-fmt", "Check formatting of all zig code");
1919
const snapshot_step = b.step("snapshot", "Run the snapshot tool to update snapshot files");
20+
const update_expected_step = b.step("update-expected", "Update EXPECTED sections based on PROBLEMS in snapshots");
2021

2122
// general configuration
2223
const target = b.standardTargetOptions(.{ .default_target = .{
@@ -75,6 +76,17 @@ pub fn build(b: *std.Build) void {
7576
add_tracy(b, build_options, snapshot_exe, target, false, tracy);
7677
install_and_run(b, no_bin, snapshot_exe, snapshot_step, snapshot_step);
7778

79+
// Add update-expected tool
80+
const update_expected_exe = b.addExecutable(.{
81+
.name = "update-expected",
82+
.root_source_file = b.path("src/update_expected.zig"),
83+
.target = target,
84+
.optimize = optimize,
85+
.link_libc = true,
86+
});
87+
add_tracy(b, build_options, update_expected_exe, target, false, tracy);
88+
install_and_run(b, no_bin, update_expected_exe, update_expected_step, update_expected_step);
89+
7890
const all_tests = b.addTest(.{
7991
.root_source_file = b.path("src/test.zig"),
8092
.target = target,

src/check/canonicalize.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,7 @@ test {
29472947
_ = @import("canonicalize/test/int_test.zig");
29482948
_ = @import("canonicalize/test/frac_test.zig");
29492949
_ = @import("canonicalize/test/node_store_test.zig");
2950+
_ = @import("let_polymorphism_integration_test.zig");
29502951
}
29512952

29522953
/// Flatten a chain of if-then-else expressions into multiple if-branches

src/check/canonicalize/CIR.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,12 @@ pub fn diagnosticToReport(self: *CIR, diagnostic: Diagnostic, allocator: std.mem
174174
},
175175
.ident_not_in_scope => |data| blk: {
176176
const ident_name = self.env.idents.getText(data.ident);
177+
const region_info = self.calcRegionInfo(data.region);
177178
break :blk Diagnostic.buildIdentNotInScopeReport(
178179
allocator,
179180
ident_name,
181+
region_info,
182+
filename,
180183
);
181184
},
182185
.invalid_top_level_statement => |data| blk: {

src/check/canonicalize/Diagnostic.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ pub const Diagnostic = union(enum) {
214214
}
215215

216216
/// Build a report for "identifier not in scope" diagnostic
217-
pub fn buildIdentNotInScopeReport(allocator: Allocator, ident_name: []const u8) !Report {
217+
pub fn buildIdentNotInScopeReport(
218+
allocator: Allocator,
219+
ident_name: []const u8,
220+
region_info: base.RegionInfo,
221+
filename: []const u8,
222+
) !Report {
218223
var report = Report.init(allocator, "UNDEFINED VARIABLE", .runtime_error);
219224
const owned_ident = try report.addOwnedString(ident_name);
220225
try report.document.addText("Nothing is named ");
@@ -226,6 +231,13 @@ pub const Diagnostic = union(enum) {
226231
try report.document.addText(" or ");
227232
try report.document.addKeyword("exposing");
228233
try report.document.addReflowingText(" missing up-top?");
234+
try report.document.addLineBreak();
235+
try report.document.addLineBreak();
236+
try report.document.addSourceRegion(
237+
region_info,
238+
.error_highlight,
239+
filename,
240+
);
229241
return report;
230242
}
231243

0 commit comments

Comments
 (0)