Skip to content

Commit

Permalink
Merge pull request #1794 from zigtools/techatrix/test-filters
Browse files Browse the repository at this point in the history
update test filters option + remove test name prefixes
  • Loading branch information
llogick authored Feb 27, 2024
2 parents 845a9a0 + adcd65f commit 9cd661a
Show file tree
Hide file tree
Showing 26 changed files with 632 additions and 657 deletions.
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const builtin = @import("builtin");
const zls_version = std.SemanticVersion{ .major = 0, .minor = 12, .patch = 0 };

/// document the latest breaking change that caused a change to the string below:
/// std: make options a struct instance instead of a namespace
const min_zig_string = "0.12.0-dev.2679+54bbc73f8";
/// std.http.Client: fix UAF when handling redirects
const min_zig_string = "0.12.0-dev.3030+032c2ee9b";

const Build = blk: {
const current_zig = builtin.zig_version;
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn build(b: *Build) !void {
const enable_tracy_allocation = b.option(bool, "enable_tracy_allocation", "Enable using TracyAllocator to monitor allocations.") orelse enable_tracy;
const enable_tracy_callstack = b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse enable_tracy;
const coverage = b.option(bool, "generate_coverage", "Generate coverage data with kcov") orelse false;
const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match filter") orelse &[0][]const u8{};
const data_version = b.option([]const u8, "data_version", "The Zig version your compiler is.") orelse "master";
const data_version_path = b.option([]const u8, "version_data_path", "Manually specify zig language reference file");
const override_version_data_file_path = b.option([]const u8, "version_data_file_path", "Relative path to version data file (if none, will be named with timestamp)");
Expand Down Expand Up @@ -197,7 +197,7 @@ pub fn build(b: *Build) !void {
.root_source_file = .{ .path = "tests/tests.zig" },
.target = target,
.optimize = optimize,
.filter = test_filter,
.filters = test_filters,
.single_threaded = single_threaded,
.use_llvm = use_llvm,
.use_lld = use_llvm,
Expand All @@ -211,7 +211,7 @@ pub fn build(b: *Build) !void {
.root_source_file = .{ .path = "src/zls.zig" },
.target = target,
.optimize = optimize,
.filter = test_filter,
.filters = test_filters,
.single_threaded = single_threaded,
.use_llvm = use_llvm,
.use_lld = use_llvm,
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

.dependencies = .{
.known_folders = .{
.url = "https://github.com/ziglibs/known-folders/archive/2aa7f2e9855d45b20072e15107fb379b9380adbe.tar.gz",
.hash = "12209925016f4b5486a713828ead3bcc900fa4f039c93de1894aa7d5253f7633b92c",
.url = "https://github.com/ziglibs/known-folders/archive/055c95a717c5b54a0fc52ff5f370439c28eb2e73.tar.gz",
.hash = "12204a8a7e9184a77f70795b1fc8a9f94dff5cce208c20c5c6452967dddc498e0b64",
},
.diffz = .{
.url = "https://github.com/ziglibs/diffz/archive/e10bf15962e45affb3fcd7d9a950977a69c901b3.tar.gz",
Expand Down
6 changes: 3 additions & 3 deletions deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ linkFarm "zig-packages" [
};
}
{
name = "12209925016f4b5486a713828ead3bcc900fa4f039c93de1894aa7d5253f7633b92c";
name = "12204a8a7e9184a77f70795b1fc8a9f94dff5cce208c20c5c6452967dddc498e0b64";
path = fetchzip {
url = "https://github.com/ziglibs/known-folders/archive/2aa7f2e9855d45b20072e15107fb379b9380adbe.tar.gz";
hash = "sha256-YibEEVTkcaC5F9LzaPRdTvZjqv9CqNfI7dEla4E5PNs=";
url = "https://github.com/ziglibs/known-folders/archive/055c95a717c5b54a0fc52ff5f370439c28eb2e73.tar.gz";
hash = "sha256-ApLxRxoo5iQ7L5TrONiojIqLYs/QtPTPriVJv6mvf6w=";
};
}
]
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/analyser/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,7 @@ fn optionalPtrTy(ip: *InternPool, ty: Index) Index {
}

/// will panic in during testing, otherwise will return `value`
inline fn panicOrElse(message: []const u8, value: anytype) @TypeOf(value) {
fn panicOrElse(comptime T: type, message: []const u8, value: T) T {
if (builtin.is_test) {
@panic(message);
}
Expand Down Expand Up @@ -3579,11 +3579,11 @@ pub fn onePossibleValue(ip: *InternPool, ty: Index) Index {
};
},
.function_type => Index.none,
.union_type => panicOrElse("TODO", Index.none),
.tuple_type => panicOrElse("TODO", Index.none),
.union_type => panicOrElse(Index, "TODO", Index.none),
.tuple_type => panicOrElse(Index, "TODO", Index.none),
.vector_type => |vector_info| {
if (vector_info.len == 0) {
return panicOrElse("TODO return empty array value", Index.the_only_possible_value);
return panicOrElse(Index, "TODO return empty array value", Index.the_only_possible_value);
}
return ip.onePossibleValue(vector_info.child);
},
Expand Down Expand Up @@ -3891,7 +3891,7 @@ fn printInternal(ip: *InternPool, ty: Index, writer: anytype, options: FormatOpt
},
.struct_type => |struct_index| {
const optional_decl_index = ip.getStruct(struct_index).owner_decl;
const decl_index = optional_decl_index.unwrap() orelse return panicOrElse("TODO", null);
const decl_index = optional_decl_index.unwrap() orelse return panicOrElse(?Index, "TODO", null);
const decl = ip.getDecl(decl_index);
try writer.print("{}", .{ip.fmtId(decl.name)});
},
Expand Down Expand Up @@ -3920,7 +3920,7 @@ fn printInternal(ip: *InternPool, ty: Index, writer: anytype, options: FormatOpt
}
try writer.writeByte('}');
},
.enum_type => return panicOrElse("TODO", null),
.enum_type => return panicOrElse(?Index, "TODO", null),
.function_type => |function_info| {
try writer.writeAll("fn(");

Expand Down Expand Up @@ -3957,7 +3957,7 @@ fn printInternal(ip: *InternPool, ty: Index, writer: anytype, options: FormatOpt

return function_info.return_type;
},
.union_type => return panicOrElse("TODO", null),
.union_type => return panicOrElse(?Index, "TODO", null),
.tuple_type => |tuple_info| {
assert(tuple_info.types.len == tuple_info.values.len);
try writer.writeAll("tuple{");
Expand Down
64 changes: 64 additions & 0 deletions src/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1908,3 +1908,67 @@ pub fn smallestEnclosingSubrange(children: []const offsets.Loc, loc: offsets.Loc
.len = end - start,
};
}

test smallestEnclosingSubrange {
const children = &[_]offsets.Loc{
.{ .start = 0, .end = 5 },
.{ .start = 5, .end = 10 },
.{ .start = 12, .end = 18 },
.{ .start = 18, .end = 22 },
.{ .start = 25, .end = 28 },
};

try std.testing.expect(smallestEnclosingSubrange(&.{}, undefined) == null);

// children <-->
// loc <--->
// result null
try std.testing.expect(
smallestEnclosingSubrange(&.{.{ .start = 0, .end = 4 }}, .{ .start = 0, .end = 5 }) == null,
);

// children <---><---> <----><--> <->
// loc <---------------------------->
// result null
try std.testing.expect(smallestEnclosingSubrange(children, .{ .start = 0, .end = 30 }) == null);

// children <---><---> <----><--> <->
// loc <--------->
// result <---> <---->
const result1 = smallestEnclosingSubrange(children, .{ .start = 6, .end = 17 }).?;
try std.testing.expectEqualSlices(
offsets.Loc,
children[1..3],
children[result1.start .. result1.start + result1.len],
);

// children <---><---> <----><--> <->
// loc <------------->
// result <---> <----><-->
const result2 = smallestEnclosingSubrange(children, .{ .start = 6, .end = 20 }).?;
try std.testing.expectEqualSlices(
offsets.Loc,
children[1..4],
children[result2.start .. result2.start + result2.len],
);

// children <---><---> <----><--> <->
// loc <----------->
// result <---> <----><--> <->
const result3 = smallestEnclosingSubrange(children, .{ .start = 10, .end = 23 }).?;
try std.testing.expectEqualSlices(
offsets.Loc,
children[1..5],
children[result3.start .. result3.start + result3.len],
);

// children <---><---> <----><--> <->
// loc <>
// result <---> <---->
const result4 = smallestEnclosingSubrange(children, .{ .start = 10, .end = 12 }).?;
try std.testing.expectEqualSlices(
offsets.Loc,
children[1..3],
children[result4.start .. result4.start + result4.len],
);
}
Loading

0 comments on commit 9cd661a

Please sign in to comment.