mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
testing: ability to read environment variables from unit tests
This commit is contained in:
@@ -129,6 +129,7 @@ fn mainServer(init: std.process.Init.Minimal) !void {
|
||||
},
|
||||
|
||||
.run_test => {
|
||||
testing.environ = init.environ;
|
||||
testing.allocator_instance = .{};
|
||||
testing.io_instance = .init(testing.allocator, .{
|
||||
.argv0 = .init(init.args),
|
||||
@@ -244,6 +245,7 @@ fn mainTerminal(init: std.process.Init.Minimal) void {
|
||||
if (testing.allocator_instance.deinit() == .leak) leaks += 1;
|
||||
}
|
||||
testing.log_level = .warn;
|
||||
testing.environ = init.environ;
|
||||
|
||||
const test_node = root_node.start(test_fn.name, 0);
|
||||
if (!have_tty) {
|
||||
|
||||
@@ -2,6 +2,7 @@ const builtin = @import("builtin");
|
||||
|
||||
const std = @import("std.zig");
|
||||
const Io = std.Io;
|
||||
const Environ = std.process.Environ;
|
||||
const assert = std.debug.assert;
|
||||
const math = std.math;
|
||||
|
||||
@@ -33,6 +34,8 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
|
||||
pub var io_instance: Io.Threaded = undefined;
|
||||
pub const io = if (builtin.is_test) io_instance.io() else @compileError("not testing");
|
||||
|
||||
pub var environ: Environ = if (builtin.is_test) undefined else @compileError("not testing");
|
||||
|
||||
/// TODO https://github.com/ziglang/zig/issues/5738
|
||||
pub var log_level = std.log.Level.warn;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user