This commit is contained in:
Jakub Doka 2025-03-14 11:33:12 +01:00
parent 53e9a095ed
commit 5e1173c86b
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
7 changed files with 46 additions and 48 deletions

View file

@ -18,16 +18,6 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = true,
}).module("zap");
const sqlite = b.dependency("sqlite", .{
.target = target,
.optimize = optimize,
}).module("sqlite");
hbc: {
const exe = b.addExecutable(.{
.name = "hbc",
@ -40,11 +30,11 @@ pub fn build(b: *std.Build) !void {
break :hbc;
}
const options = b.addOptions();
const test_step = b.step("test", "run tests");
const vendored_tests = vendored_tests: {
vendored_tests: {
const grn = b.addExecutable(.{
.name = "gen_tests.zig",
.name = "gen_vendored_tests",
.root_source_file = b.path("scripts/gen_vendored_tests.zig"),
.target = b.graph.host,
.optimize = .Debug,
@ -57,10 +47,23 @@ pub fn build(b: *std.Build) !void {
run_gen.addDirectoryArg(b.path("vendored-tests"));
run_gen.addArg("hbc-tests");
const out = run_gen.addOutputFileArg("vendored_tests.zig");
break :vendored_tests out;
};
const tests = example_tests: {
const test_run = b.addTest(.{
.name = "vendored_tests",
.root_source_file = out,
.target = b.graph.host,
.optimize = optimize,
.use_llvm = false,
.use_lld = false,
});
test_run.root_module.addAnonymousImport("utils", .{ .root_source_file = b.path("src/tests.zig") });
test_step.dependOn(&b.addRunArtifact(test_run).step);
break :vendored_tests;
}
example_tests: {
const gen = b.addExecutable(.{
.name = "gen_tests.zig",
.root_source_file = b.path("scripts/gen_tests.zig"),
@ -71,18 +74,23 @@ pub fn build(b: *std.Build) !void {
});
const run_gen = b.addRunArtifact(gen);
run_gen.has_side_effects = true;
run_gen.addFileArg(b.path("README.md"));
const out = run_gen.addOutputFileArg("tests.zig");
{
const rdm_stat = try std.fs.cwd().statFile("README.md");
const stat = if (std.fs.cwd().statFile("zig-out/tests.zig")) |s| s.mtime else |_| 0;
run_gen.has_side_effects = rdm_stat.mtime > stat;
}
const test_run = b.addTest(.{
.name = "vendored_tests",
.root_source_file = out,
.target = b.graph.host,
.optimize = optimize,
.use_llvm = false,
.use_lld = false,
});
break :example_tests out;
};
test_run.root_module.addAnonymousImport("utils", .{ .root_source_file = b.path("src/tests.zig") });
test_step.dependOn(&b.addRunArtifact(test_run).step);
break :example_tests;
}
const test_module = test_module: {
const module = b.addModule("test", .{
@ -91,12 +99,6 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});
module.addOptions("options", options);
module.addImport("zap", zap);
module.addImport("sqlite", sqlite);
module.addAnonymousImport("vendored-tests", .{ .root_source_file = vendored_tests });
module.addAnonymousImport("tests", .{ .root_source_file = tests });
break :test_module module;
};
@ -106,8 +108,6 @@ pub fn build(b: *std.Build) !void {
break :check;
}
const test_step = b.step("test", "run tests");
const fuzz_finding_tests = fuzzing: {
const dict_gen = b.addExecutable(.{
.name = "gen_fuzz_dict.zig",
@ -118,6 +118,8 @@ pub fn build(b: *std.Build) !void {
.use_lld = false,
});
dict_gen.root_module.addAnonymousImport("Lexer", .{ .root_source_file = b.path("src/frontend/Lexer.zig") });
const run_gen = b.addRunArtifact(dict_gen);
const dict_out = run_gen.addOutputFileArg("hblang.dict");
run_gen.addFileArg(b.path("README.md"));
@ -156,7 +158,7 @@ pub fn build(b: *std.Build) !void {
const gen_finding_tests = b.addExecutable(.{
.name = "gen_fuzz_finding_tests.zig",
.root_source_file = b.path("gen_fuzz_finding_tests.zig"),
.root_source_file = b.path("scripts/gen_fuzz_finding_tests.zig"),
.target = b.graph.host,
.optimize = .Debug,
.use_llvm = false,

View file

@ -1,5 +1,5 @@
const std = @import("std");
const Lexer = @import("src/Lexer.zig");
const Lexer = @import("Lexer");
pub fn main() !void {
var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);

View file

@ -5,14 +5,14 @@ pub fn main() !void {
const arena = arena_state.allocator();
const args = try std.process.argsAlloc(arena);
const case_dir, const switch_arg, const out = args[1..5].*;
const case_dir, const switch_arg, const out = args[1..4].*;
const out_file = try std.fs.cwd().createFile(out, .{});
defer out_file.close();
const writer = out_file.writer();
try writer.print(
\\const root = @import("root");
\\const utils = @import("utils");
\\
\\
, .{});
@ -52,7 +52,7 @@ pub fn main() !void {
try writer.print(
\\test "{s}" {{
\\ try root.runFuzzFindingTest(
\\ try utils.runFuzzFindingTest(
\\ "{s}",
\\ "{s}",
\\

View file

@ -14,7 +14,7 @@ pub fn main() !void {
const writer = out_file.writer();
try writer.print(
\\const root = @import("root");
\\const utils = @import("utils");
\\
\\
, .{});
@ -33,7 +33,7 @@ pub fn main() !void {
try writer.print(
\\test "{s}" {{
\\ try root.runTest(
\\ try utils.runTest(
\\ "{s}",
\\ "{s}",
\\

View file

@ -12,7 +12,7 @@ pub fn main() !void {
const writer = out_file.writer();
try writer.print(
\\const root = @import("root");
\\const utils = @import("utils");
\\
\\
, .{});
@ -37,7 +37,7 @@ pub fn main() !void {
const name = try std.fs.path.join(arena, &.{ vendored_tests, path, example.name });
try writer.print(
\\test "{s}" {{
\\ try root.runVendoredTest("{s}");
\\ try utils.runVendoredTest("{s}");
\\}}
\\
\\

View file

@ -277,7 +277,7 @@ pub fn runVm(
var vm = Vm{};
vm.ip = stack_end;
vm.fuel = 1024 * 10;
@memset(&vm.regs.values, 0);
//@memset(&vm.regs.values, 0);
vm.regs.set(.stack_addr, stack_end);
var ctx = Vm.SafeContext{
.writer = output,

View file

@ -4,12 +4,8 @@ pub const test_util = @import("test_util.zig");
pub const hbc = @import("hbc.zig");
pub const fuzz = @import("fuzz.zig");
test {
_ = @import("tests");
_ = @import("vendored-tests");
//_ = @import("zig-out/fuzz_finding_tests.zig");
std.testing.refAllDeclsRecursive(@This());
comptime {
if (@import("root") == @This()) std.testing.refAllDeclsRecursive(@This());
}
pub fn runTest(name: []const u8, code: [:0]const u8) !void {