From fa3be4d60438ef6e9d291a57664405f81b373547 Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Wed, 30 Oct 2024 23:22:07 +0800 Subject: [PATCH] feat: run spec test in condition --- README.md | 17 ++++++++++++++++- build.zig | 13 +++++++++++++ src/root.zig | 1 - src/spec_test.zig | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/spec_test.zig diff --git a/README.md b/README.md index c5981a5..5ff9baa 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,19 @@ git submodule update --init --recursive cd bls make -f Makefile.onelib ETH_CFLAGS=-DBLS_ETH LIB_DIR=lib zig build -``` \ No newline at end of file +``` + +## Test + +first you should build bls as described above + +when you run `zig build test`, the spec tests are not run by default. + +if you want to run spec tests, you need to download the test vectors and add `-Dspec=true` to the zig build command. + +```bash +# download test vectors +make deps_test +# add -Dspec=true to run spec tests +zig build test -Dspec=true +``` diff --git a/build.zig b/build.zig index 66e85ed..dacc88a 100644 --- a/build.zig +++ b/build.zig @@ -111,4 +111,17 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_lib_unit_tests.step); test_step.dependOn(&run_exe_unit_tests.step); + + const spec: ?bool = b.option(bool, "spec", "whether to run the spec tests"); + if (spec) |s| { + if (s) { + const spec_tests = b.addTest(.{ + .root_source_file = b.path("src/spec_test.zig"), + .target = target, + .optimize = optimize, + }); + const run_spec_tests = b.addRunArtifact(spec_tests); + test_step.dependOn(&run_spec_tests.step); + } + } } diff --git a/src/root.zig b/src/root.zig index 3c12bff..3adfabd 100644 --- a/src/root.zig +++ b/src/root.zig @@ -31,5 +31,4 @@ pub const deposit_helper = @import("consensus/helpers/deposit.zig"); test { @import("std").testing.refAllDeclsRecursive(@This()); - _ = @import("./spec_tests/root.zig"); } diff --git a/src/spec_test.zig b/src/spec_test.zig new file mode 100644 index 0000000..7133d6d --- /dev/null +++ b/src/spec_test.zig @@ -0,0 +1,3 @@ +test { + _ = @import("./spec_tests/root.zig"); +}