Skip to content

Commit 8d39455

Browse files
Merge pull request #1 from nooneknowspeter/refactor/patch-system
Refactor/patch system
2 parents bb327f0 + a1ddbde commit 8d39455

8 files changed

Lines changed: 304 additions & 267 deletions

File tree

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing
2+
3+
<!-- TODO: -->

build.zig

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ pub fn build(b: *STD.Build) !void {
1616

1717
// cli
1818
{
19-
const CPPLINGS_CLI = b.addExecutable(.{ .name = "cpplings_cli", .root_module = b.createModule(.{
20-
.target = TARGET,
21-
.optimize = OPTIMIZE,
22-
.root_source_file = b.path("src/main.zig"),
23-
}) });
19+
const CPPLINGS_CLI = b.addExecutable(.{
20+
.name = "cpplings_cli",
21+
.root_module = b.createModule(.{
22+
.target = TARGET,
23+
.optimize = OPTIMIZE,
24+
.root_source_file = b.path("src/main.zig"),
25+
}),
26+
});
2427

2528
b.installArtifact(CPPLINGS_CLI);
2629
const CPPLINGS_CLI_ARTIFIACT = b.addRunArtifact(CPPLINGS_CLI);
@@ -36,6 +39,23 @@ pub fn build(b: *STD.Build) !void {
3639
}
3740
}
3841

42+
// tests
43+
{
44+
const CPPLINGS_CLI_TESTS = b.addTest(.{
45+
.name = "cpplings_tests",
46+
.root_module = b.createModule(.{
47+
.target = TARGET,
48+
.optimize = OPTIMIZE,
49+
.root_source_file = b.path("src/test.zig"),
50+
}),
51+
});
52+
53+
const CPPLINGS_CLI_TESTS_ARTIFACT = b.addRunArtifact(CPPLINGS_CLI_TESTS);
54+
55+
const CPPLINGS_CLI_TESTS_STEP = b.step("tests", "Run cpplings tests");
56+
CPPLINGS_CLI_TESTS_STEP.dependOn(&CPPLINGS_CLI_TESTS_ARTIFACT.step);
57+
}
58+
3959
// exercises
4060
{
4161
const COMPILER_FLAGS = [_][]const u8{ "-std=c++23", "-Wall", "-Werror", "-Wextra" };

src/cli.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,3 @@ pub fn run(allocator: STD.mem.Allocator, extra_options: struct { exercises_dir_p
339339

340340
try userInput(self);
341341
}
342-

src/cli/patch.zig

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/main.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@ pub fn help_documentation() void {
1515
pub fn main() !void {
1616
var mem_arena = STD.heap.ArenaAllocator.init(STD.heap.page_allocator);
1717
defer mem_arena.deinit();
18-
const MEM_ALLOCATOR = mem_arena.allocator();
18+
19+
const ALLOCATOR = mem_arena.allocator();
1920

2021
if (STD.os.argv.len > 2) {
2122
STD.debug.print("Too many arguments\n", .{});
2223
help_documentation();
2324
}
2425

2526
if (STD.os.argv.len == 1) {
26-
try CLI.run(MEM_ALLOCATOR, .{});
27+
try CLI.run(ALLOCATOR, .{});
2728
return;
2829
}
2930

3031
const PROGRAM_ARGUMENT = STD.mem.span(STD.os.argv[1]);
3132

3233
if (STD.mem.eql(u8, PROGRAM_ARGUMENT, "-s") or STD.mem.eql(u8, PROGRAM_ARGUMENT, "--solutions")) {
33-
try CLI.run(MEM_ALLOCATOR, .{ .exercises_dir_path = ".patches/solutions" });
34+
try CLI.run(ALLOCATOR, .{ .exercises_dir_path = ".patches/solutions" });
3435
} else if (STD.mem.eql(u8, PROGRAM_ARGUMENT, "-p") or STD.mem.eql(u8, PROGRAM_ARGUMENT, "--patch")) {
35-
try PATCH_SYSTEM.run(MEM_ALLOCATOR);
36+
const PATCH_SYSTEM_INSTANCE = try PATCH_SYSTEM.PatchSystem.init(ALLOCATOR, .{});
37+
defer PATCH_SYSTEM_INSTANCE.deinit(ALLOCATOR);
3638
} else if (STD.mem.eql(u8, PROGRAM_ARGUMENT, "-h") or STD.mem.eql(u8, PROGRAM_ARGUMENT, "--help") or STD.mem.eql(u8, PROGRAM_ARGUMENT, "help")) {
3739
help_documentation();
3840
} else {

0 commit comments

Comments
 (0)