Skip to content

Commit

Permalink
update sema test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Sep 17, 2023
1 parent 6cce080 commit 8417bef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ pub fn enumCompletionItems(self: *DocumentStore, arena: std.mem.Allocator, handl
}

pub fn wantZir(self: DocumentStore) bool {
if (!self.config.enable_ast_check_diagnostics) return false;
if (self.config.analysis_backend == .astgen_analyser) return true;
if (!self.config.enable_ast_check_diagnostics) return false;
const can_run_ast_check = std.process.can_spawn and self.config.zig_exe_path != null and self.config.prefer_ast_check_as_child_process;
return !can_run_ast_check;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/SemaCases.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub fn lowerToBuild(
run_test.setName(b.fmt("run sema test on {s}", .{file_set.name}));
run_test.stdio = .zig_test;

run_test.addArg("--zig-exe-path");
run_test.addFileArg(.{ .path = b.zig_exe });
if (b.zig_lib_dir) |zig_lib_dir| {
run_test.addArg("--zig-lib-path");
run_test.addDirectoryArg(zig_lib_dir);
}

if (file_set.options.ignore_annotation) {
run_test.addArg("--fuzz");
}
Expand Down
50 changes: 32 additions & 18 deletions tests/sema_tester.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,38 @@ pub fn main() Error!void {

_ = arg_it.skip();

var arena_allocator = std.heap.ArenaAllocator.init(gpa);
defer arena_allocator.deinit();

const arena = arena_allocator.allocator();

var files = std.ArrayListUnmanaged([]const u8){};
defer {
for (files.items) |path| gpa.free(path);
files.deinit(gpa);
}
var is_fuzz = false;

var config = zls.Config{
.analysis_backend = .astgen_analyser,
};

while (arg_it.next()) |arg| {
if (std.mem.eql(u8, arg, "--")) {
while (arg_it.next()) |path| {
// std.debug.print("file_path: {s}\n", .{path});
const duped_path = try gpa.dupe(u8, path);
errdefer gpa.free(duped_path);
try files.append(gpa, duped_path);
try files.append(arena, try arena.dupe(u8, path));
try files.append(arena, try arena.dupe(u8, path));
}
break;
} else if (std.mem.eql(u8, arg, "--zig-exe-path")) {
const zig_exe_path = arg_it.next() orelse {
stderr.print("expected argument after '--zig-exe-path'.\n", .{}) catch {};
std.process.exit(1);
};
config.zig_exe_path = try arena.dupe(u8, zig_exe_path);
} else if (std.mem.eql(u8, arg, "--zig-lib-path")) {
const zig_lib_path = arg_it.next() orelse {
stderr.print("expected argument after '--zig-lib-path'.\n", .{}) catch {};
std.process.exit(1);
};
config.zig_lib_path = try arena.dupe(u8, zig_lib_path);
} else if (std.mem.eql(u8, arg, "--fuzz")) {
is_fuzz = true;
} else {
Expand All @@ -69,11 +85,7 @@ pub fn main() Error!void {

var document_store = zls.DocumentStore{
.allocator = gpa,
.config = &zls.Config{
.analysis_backend = .astgen_analyser,
.enable_ast_check_diagnostics = true,
.prefer_ast_check_as_child_process = false,
},
.config = &config,
.runtime_zig_version = &@as(?zls.ZigVersionWrapper, null),
};
var mod = Module.init(gpa, &ip, &document_store);
Expand All @@ -89,11 +101,7 @@ pub fn main() Error!void {
errdefer error_builder.writeDebug();
error_builder.file_name_visibility = .always;

const handle_uri = switch (builtin.os.tag) {
.windows => "file:///C:\\test.zig",
else => "file:///test.zig",
};

var previous_handle_uri: ?[]const u8 = null;
var previous_eb_filename: ?[]const u8 = null;

for (files.items, 0..) |file_path, increment| {
Expand All @@ -103,11 +111,17 @@ pub fn main() Error!void {
const source = file.readToEndAllocOptions(gpa, std.math.maxInt(usize), null, @alignOf(u8), 0) catch |err|
std.debug.panic("failed to read from {s}: {}", .{ file_path, err });

const handle_uri = try zls.URI.fromPath(arena, file_path);

if (increment == 0) {
defer gpa.free(source);
try document_store.openDocument(handle_uri, source);
previous_handle_uri = handle_uri;
} else {
try document_store.refreshDocument(handle_uri, source);
try document_store.refreshDocument(previous_handle_uri.?, source);
// rename handle
document_store.handles.getKeyPtr(previous_handle_uri.?).?.* = handle_uri;
try document_store.handles.reIndex(document_store.allocator);
}
const handle: *zls.DocumentStore.Handle = document_store.handles.get(handle_uri).?;

Expand Down

0 comments on commit 8417bef

Please sign in to comment.