test-standalone: update cases to new main API

This commit is contained in:
Andrew Kelley
2026-01-01 23:52:26 -08:00
parent f2cf7b538f
commit 1b56686012
10 changed files with 45 additions and 46 deletions
+28 -4
View File
@@ -24,7 +24,10 @@ pub fn main(init: std.process.Init.Minimal) !void {
defer std.debug.assert(debug_allocator.deinit() == .ok);
const gpa = debug_allocator.allocator();
var threaded: std.Io.Threaded = .init(gpa, .{});
var threaded: std.Io.Threaded = .init(gpa, .{
.environ = init.environ,
.argv0 = .init(init.args),
});
defer threaded.deinit();
const io = threaded.io();
@@ -536,13 +539,24 @@ const LazyIncludePaths = struct {
target_machine_type: std.coff.IMAGE.FILE.MACHINE,
resolved_include_paths: ?[]const []const u8 = null,
pub fn get(self: *LazyIncludePaths, error_handler: *ErrorHandler) ![]const []const u8 {
pub fn get(
self: *LazyIncludePaths,
error_handler: *ErrorHandler,
env_map: *const std.process.Environ.Map,
) ![]const []const u8 {
const io = self.io;
if (self.resolved_include_paths) |include_paths|
return include_paths;
return getIncludePaths(self.arena, io, self.auto_includes_option, self.zig_lib_dir, self.target_machine_type) catch |err| switch (err) {
return getIncludePaths(
self.arena,
io,
self.auto_includes_option,
self.zig_lib_dir,
self.target_machine_type,
env_map,
) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => |e| {
switch (e) {
@@ -569,6 +583,7 @@ fn getIncludePaths(
auto_includes_option: cli.Options.AutoIncludes,
zig_lib_dir: []const u8,
target_machine_type: std.coff.IMAGE.FILE.MACHINE,
env_map: *const std.process.Environ.Map,
) ![]const []const u8 {
if (auto_includes_option == .none) return &[_][]const u8{};
@@ -641,7 +656,16 @@ fn getIncludePaths(
};
const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
const detected_libc = std.zig.LibCDirs.detect(
arena,
io,
zig_lib_dir,
&target,
is_native_abi,
true,
null,
env_map,
) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => return error.MingwIncludesNotFound,
};
+2 -2
View File
@@ -25,8 +25,8 @@ pub fn main(init: std.process.Init) u8 {
zig_integration = true;
}
const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet();
const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet();
const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet(init.env_map);
const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet(init.env_map);
var stderr_buf: [1024]u8 = undefined;
var stderr = Io.File.stderr().writer(io, &stderr_buf);
+3 -8
View File
@@ -3,18 +3,13 @@ const fatal = std.process.fatal;
extern fn add(a: u32, b: u32, addr: *usize) u32;
pub fn main() void {
var debug_alloc_inst: std.heap.DebugAllocator(.{}) = .init;
defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
const gpa = debug_alloc_inst.allocator();
pub fn main(init: std.process.Init) void {
const gpa = init.gpa;
const io = init.io;
var di: std.debug.SelfInfo = .init;
defer di.deinit(gpa);
var threaded: std.Io.Threaded = .init(gpa, .{});
defer threaded.deinit();
const io = threaded.io();
var add_addr: usize = undefined;
_ = add(1, 2, &add_addr);
+1 -1
View File
@@ -12,7 +12,7 @@
const std = @import("std");
pub fn main(init: std.process.Init) !void {
var args = try init.args.iterateAllocator(init.arena);
var args = try init.minimal.args.iterateAllocator(init.gpa);
defer args.deinit();
_ = args.next() orelse unreachable; // skip binary name
+1 -1
View File
@@ -14,7 +14,7 @@
const std = @import("std");
pub fn main(init: std.process.Init) !void {
var args = try init.args.iterateAllocator(init.arena);
var args = try init.minimal.args.iterateAllocator(init.gpa);
defer args.deinit();
_ = args.next() orelse unreachable; // skip binary name
+1 -1
View File
@@ -9,7 +9,7 @@
const std = @import("std");
pub fn main(init: std.process.Init) !void {
var args = try init.args.iterateAllocator(init.arena);
var args = try init.minimal.args.iterateAllocator(init.gpa);
defer args.deinit();
_ = args.next() orelse unreachable; // skip binary name
@@ -1,10 +1,7 @@
const std = @import("std");
pub fn main() !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
defer _ = gpa.deinit();
const args = try std.process.argsAlloc(gpa.allocator());
defer std.process.argsFree(gpa.allocator(), args);
pub fn main(init: std.process.Init) !void {
const args = try init.minimal.args.toSlice(init.arena.allocator());
const dynlib_name = args[1];
+2 -10
View File
@@ -7,24 +7,16 @@ const assert = std.debug.assert;
const path_max = std.fs.max_path_bytes;
pub fn main() !void {
pub fn main(init: std.process.Init) !void {
switch (builtin.target.os.tag) {
.wasi => return, // WASI doesn't support changing the working directory at all.
.windows => return, // POSIX is not implemented by Windows
else => {},
}
var debug_allocator: std.heap.DebugAllocator(.{}) = .{};
defer assert(debug_allocator.deinit() == .ok);
const gpa = debug_allocator.allocator();
var threaded: std.Io.Threaded = .init(gpa, .{});
defer threaded.deinit();
const io = threaded.io();
try test_chdir_self();
try test_chdir_absolute();
try test_chdir_relative(gpa, io);
try test_chdir_relative(init.gpa, init.io);
}
// get current working directory and expect it to match given path
+2 -8
View File
@@ -6,16 +6,10 @@ const builtin = @import("builtin");
const std = @import("std");
const Io = std.Io;
pub fn main() !void {
pub fn main(init: std.process.Init) !void {
if (builtin.target.os.tag == .wasi) return; // Can link, but can't change into tmpDir
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
const gpa = debug_allocator.allocator();
defer std.debug.assert(debug_allocator.deinit() == .ok);
var threaded: std.Io.Threaded = .init(gpa, .{});
defer threaded.deinit();
const io = threaded.io();
const io = init.io;
var tmp = tmpDir(io, .{});
defer tmp.cleanup(io);
@@ -1,9 +1,6 @@
pub fn main() !void {
var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena_state.deinit();
const arena = arena_state.allocator();
const args = try std.process.argsAlloc(arena);
pub fn main(init: std.process.Init) !void {
const arena = init.arena.allocator();
const args = try init.minimal.args.toSlice(arena);
if (args.len != 2) return error.BadUsage;
const path = args[1];