authorgravatar for sayedmurtazamuttahary@gmail.commurtaza <sayedmurtazamuttahary@gmail.com> 2026-01-15 23:34:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-17 00:40:22+01:00
logb5770541bdc10311125a06ab2ef1b7f3546cea7a
tree0fe86cadab60847fe058c008b3dc2493bc5c4db7
parent790d28d6cd9029805af857d56645a6ce191bfe91

testing: ability to read environment variables from unit tests


2 files changed, 5 insertions(+), 0 deletions(-)

lib/compiler/test_runner.zig+2
......@@ -129,6 +129,7 @@ fn mainServer(init: std.process.Init.Minimal) !void {
129129 },
130130
131131 .run_test => {
132 testing.environ = init.environ;
132133 testing.allocator_instance = .{};
133134 testing.io_instance = .init(testing.allocator, .{
134135 .argv0 = .init(init.args),
......@@ -244,6 +245,7 @@ fn mainTerminal(init: std.process.Init.Minimal) void {
244245 if (testing.allocator_instance.deinit() == .leak) leaks += 1;
245246 }
246247 testing.log_level = .warn;
248 testing.environ = init.environ;
247249
248250 const test_node = root_node.start(test_fn.name, 0);
249251 if (!have_tty) {
lib/std/testing.zig+3
......@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22
33const std = @import("std.zig");
44const Io = std.Io;
5const Environ = std.process.Environ;
56const assert = std.debug.assert;
67const math = std.math;
78
......@@ -33,6 +34,8 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
3334pub var io_instance: Io.Threaded = undefined;
3435pub const io = if (builtin.is_test) io_instance.io() else @compileError("not testing");
3536
37pub var environ: Environ = if (builtin.is_test) undefined else @compileError("not testing");
38
3639/// TODO https://github.com/ziglang/zig/issues/5738
3740pub var log_level = std.log.Level.warn;
3841