Changes
4 changed files (+195/-26)
-
-
@@ -23,32 +23,11 @@ const optimize = b.standardOptimizeOption(.{});const man_opt = b.option(bool, "man", "Builds and installs man pages") orelse false; const zig_main = b.option(bool, "zigmain", "Use Zig rewrite") orelse false; const exe = exe: { const exe = b.addExecutable(.{ .name = "sunwait", .target = target, .optimize = optimize, }); if (zig_main) { exe.root_module.root_source_file = b.path("src/main.zig"); exe.root_module.addCMacro("SUNWAIT_NOMAIN", ""); } exe.linkLibC(); exe.addCSourceFiles(.{ .files = &.{ "src/print.c", "src/sunriset.c", "src/sunwait.c", }, }); exe.addIncludePath(b.path("src")); break :exe exe; }; const exe = addExe(b, .{ .target = target, .optimize = optimize, .zig_main = zig_main, }); // "zig build run" {
-
@@ -87,4 +66,69 @@ if (man_opt) {b.getInstallStep().dependOn(&man.step); } } // "zig build behavior_test" { const step = b.step("behavior_test", "Run behavior matching tests"); const legacy_exe = addExe(b, .{ .target = target, .optimize = optimize, }); const new_exe = addExe(b, .{ .target = target, .optimize = optimize, .zig_main = true, }); const t = b.addTest(.{ .name = "behavior_matching_test", .target = target, .optimize = optimize, .root_source_file = b.path("tests/main.zig"), }); const config = b.addOptions(); config.addOptionPath("legacy_bin", legacy_exe.getEmittedBin()); config.addOptionPath("new_bin", new_exe.getEmittedBin()); t.root_module.addOptions("config", config); const run = b.addRunArtifact(t); step.dependOn(&run.step); } } const AddExeOptions = struct { target: ?std.Build.ResolvedTarget = null, optimize: std.builtin.OptimizeMode, zig_main: bool = false, }; fn addExe(b: *std.Build, opts: AddExeOptions) *std.Build.Step.Compile { const exe = b.addExecutable(.{ .name = "sunwait", .target = opts.target, .optimize = opts.optimize, }); if (opts.zig_main) { exe.root_module.root_source_file = b.path("src/main.zig"); exe.root_module.addCMacro("SUNWAIT_NOMAIN", ""); } exe.linkLibC(); exe.addCSourceFiles(.{ .files = &.{ "src/print.c", "src/sunriset.c", "src/sunwait.c", }, }); exe.addIncludePath(b.path("src")); return exe; }
-
-
tests/main.zig (new)
-
@@ -0,0 +1,21 @@// Copyright (C) 2025 Shota FUJI // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // SPDX-License-Identifier: GPL-3.0-only test { _ = @import("./report.zig"); _ = @import("./poll.zig"); }
-
-
tests/poll.zig (new)
-
@@ -0,0 +1,47 @@// Copyright (C) 2025 Shota FUJI // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // SPDX-License-Identifier: GPL-3.0-only const std = @import("std"); const config = @import("config"); fn poll(allocator: std.mem.Allocator, bin: []const u8) !std.process.Child.RunResult { var env = std.process.EnvMap.init(allocator); defer env.deinit(); try env.put("TZ", "UTC"); return try std.process.Child.run(.{ .allocator = allocator, .argv = &.{ bin, "poll", "29.977435N", "31.132484E" }, .env_map = &env, }); } test { const legacy = try poll(std.testing.allocator, config.legacy_bin); defer std.testing.allocator.free(legacy.stderr); defer std.testing.allocator.free(legacy.stdout); const new = try poll(std.testing.allocator, config.new_bin); defer std.testing.allocator.free(new.stderr); defer std.testing.allocator.free(new.stdout); try std.testing.expectEqual(legacy.term.Exited, new.term.Exited); try std.testing.expectEqualStrings(legacy.stderr, new.stderr); try std.testing.expectEqualStrings(legacy.stdout, new.stdout); }
-
-
tests/report.zig (new)
-
@@ -0,0 +1,57 @@// Copyright (C) 2025 Shota FUJI // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // SPDX-License-Identifier: GPL-3.0-only const std = @import("std"); const config = @import("config"); fn report(allocator: std.mem.Allocator, bin: []const u8) !std.process.Child.RunResult { var env = std.process.EnvMap.init(allocator); defer env.deinit(); try env.put("TZ", "UTC"); return try std.process.Child.run(.{ .allocator = allocator, .argv = &.{ bin, "report", "d", "1", "m", "1", "y", "1", "29.977435N", "31.132484E", }, .env_map = &env, }); } test { const legacy = try report(std.testing.allocator, config.legacy_bin); defer std.testing.allocator.free(legacy.stderr); defer std.testing.allocator.free(legacy.stdout); const new = try report(std.testing.allocator, config.new_bin); defer std.testing.allocator.free(new.stderr); defer std.testing.allocator.free(new.stdout); try std.testing.expectEqual(legacy.term.Exited, new.term.Exited); try std.testing.expectEqualStrings(legacy.stderr, new.stderr); try std.testing.expectEqualStrings(legacy.stdout, new.stdout); }
-