Skip to content

Commit

Permalink
♻️ refactor lib and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Oct 20, 2023
1 parent 88e2ba9 commit 35b0d79
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
5 changes: 4 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,19 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .path = "src/tests.zig" },
.target = target,
.optimize = optimize,
});
// Add dependency modules to the tests.
unit_tests.addModule("zig-cli", zig_cli_module);

const run_unit_tests = b.addRunArtifact(unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&lib.step);
test_step.dependOn(&run_unit_tests.step);
}
15 changes: 15 additions & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
pub const vm = struct {
pub usingnamespace @import("vm/core.zig");
pub usingnamespace @import("vm/error.zig");
pub usingnamespace @import("vm/instructions.zig");
pub usingnamespace @import("vm/run_context.zig");
pub usingnamespace @import("vm/memory/memory.zig");
pub usingnamespace @import("vm/memory/relocatable.zig");
pub usingnamespace @import("vm/memory/segments.zig");
};

pub const math = struct {
pub usingnamespace @import("math/fields/fields.zig");
pub usingnamespace @import("math/fields/stark_felt_252_gen_fp.zig");
pub usingnamespace @import("math/fields/starknet.zig");
};

pub const utils = struct {
pub usingnamespace @import("utils/log.zig");
pub usingnamespace @import("utils/time.zig");
};
40 changes: 3 additions & 37 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,9 @@ pub const std_options = struct {
pub const logFn = customlogFn;
};

pub fn main() !void {
try cmd.run();
}

// *****************************************************************************
// * VM TESTS *
// * MAIN ENTRY POINT *
// *****************************************************************************

test "vm" {
_ = @import("vm/core.zig");
_ = @import("vm/instructions.zig");
_ = @import("vm/run_context.zig");
}

test "memory" {
_ = @import("vm/memory/memory.zig");
_ = @import("vm/memory/segments.zig");
}

test "relocatable" {
_ = @import("vm/memory/relocatable.zig");
}

// *****************************************************************************
// * MATH TESTS *
// *****************************************************************************

test "fields" {
_ = @import("math/fields/fields.zig");
_ = @import("math/fields/starknet.zig");
}

// *****************************************************************************
// * UTIL TESTS *
// *****************************************************************************

test "util" {
_ = @import("utils/log.zig");
_ = @import("utils/time.zig");
pub fn main() !void {
try cmd.run();
}
8 changes: 8 additions & 0 deletions src/tests.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const std = @import("std");
const lib = @import("lib.zig");

// Automatically run all tests in files declared in the `lib.zig` file.
test {
std.testing.log_level = std.log.Level.err;
std.testing.refAllDecls(lib);
}

0 comments on commit 35b0d79

Please sign in to comment.