Skip to content
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
70 changes: 69 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn build(b: *Build) !void {
const test_analysis_step = b.step("test-analysis", "Run all the analysis tests");

// Create run steps
@import("tests/add_analysis_cases.zig").addCases(b, target, optimize, test_analysis_step, test_filters);
addAnalysisCases(b, target, optimize, test_analysis_step, test_filters);

const run_tests = b.addRunArtifact(tests);
const run_src_tests = b.addRunArtifact(src_tests);
Expand Down Expand Up @@ -634,6 +634,74 @@ fn release(b: *Build, release_artifacts: []const *Build.Step.Compile, released_z
release_step.dependOn(&install_metadata.step);
}

fn addAnalysisCases(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.lang.OptimizeMode,
test_step: *std.Build.Step,
test_filters: []const []const u8,
) void {
const cases_path = "tests/analysis";

const check_exe = b.addExecutable(.{
.name = "analysis_check",
.root_module = b.createModule(.{
.root_source_file = b.path("tests/analysis_check.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zls", .module = b.modules.get("zls").? },
},
}),
});

b.dependOnDirectoryContents(b.path(cases_path));

var dir = b.root.openDir(b.graph.io, cases_path, .{ .iterate = true }) catch |err|
std.debug.panic("failed to open '{f}': {}", .{ b.path(cases_path), err });
defer dir.close(b.graph.io);

var it = dir.iterate();

while (true) {
const entry = it.next(b.graph.io) catch |err|
std.debug.panic("failed to walk directory '{f}': {}", .{ b.path(cases_path), err }) orelse break;

if (entry.kind != .file) continue;
if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.name), ".zig")) continue;

for (test_filters) |test_filter| {
if (std.mem.find(u8, entry.name, test_filter) != null) break;
} else if (test_filters.len > 0) continue;

const run_check = std.Build.Step.Run.create(b, b.fmt("run analysis on {s}", .{entry.name}));
run_check.producer = check_exe;

run_check.addArtifactArg(check_exe);
if (target.query.eql(b.graph.host.query)) {
run_check.addArg("--zig-exe-path");
run_check.addFileArg(.zig_exe);
}
run_check.setPreopen("/lib", .zig_lib);
if (!target.result.cpu.arch.isWasm()) {
run_check.addArg("--zig-lib-path");
run_check.addDirectoryArg(.zig_lib);
}

const input_file = b.path(cases_path).path(b, entry.name);
if (!target.result.cpu.arch.isWasm()) {
run_check.addFileArg(input_file);
} else {
// pass a relative file path when running with wasmtime
run_check.setCwd(b.path(cases_path));
run_check.addArg(entry.name);
run_check.addFileInput(input_file);
}

test_step.dependOn(&run_check.step);
}
}

const Build = blk: {
@setEvalBranchQuota(10_000);

Expand Down
72 changes: 0 additions & 72 deletions tests/add_analysis_cases.zig

This file was deleted.

Loading