-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.testing: add methods tmpDirPath, getTestArgs, buildExe #11138
Conversation
|
Question for next PR: Should there be a method to create a zig program from a string inside tests or where should it reside? var it = try std.process.argsWithAllocator(allocator);
const testargs = try testing.getTestArgs(&it);
defer it.deinit(); // no-op unless WASI or Windows
var tmp = testing.tmpDir(.{ .no_follow = true }); // ie zig-cache/tmp/8DLgoSEqz593PAEE
defer tmp.cleanup();
const tmpdirpath = try testing.tmpDirPath(allocator, &tmp);
defer allocator.free(tmpdirpath);
const child_name = "child"; // no need for suffixes (.exe, .wasm) due to '-femit-bin'
const suffix_zig = ".zig";
const child_path = try fs.path.join(allocator, &[_][]const u8{ tmpdirpath, child_name });
defer allocator.free(child_path);
const child_zig = try mem.concat(allocator, u8, &[_][]const u8{ child_path, suffix_zig });
defer allocator.free(child_zig);
try tmp.dir.writeFile("child.zig", childstr);
try testing.buildExe(testargs.zigexec, child_zig, child_path);That way, building (multiple) executables to a tmp folder would be exactly 1 properly checked function from within test blocks. Alternatively, I will implement a shortcut to obtain |
|
Some functionality is redundant to |
continuation of ziglang#11093 to simplify testing IPC * use cases - get path to temporary directory - get the test arguments inside test block for reusage - build executables from text within test blocks, ie to test IPC * missing conventions - how to name and debug test cases - where do simple+repititve build commands for testing belong
Its a good suggestion but eventually similar functions would be needed for all other zig operations like run, buildLib etc. |
|
@iddev5 With your proposed solution I get const zigfile_path = try tmp.writeZigFile(std.testing.allocator, childstr, child_name);
defer std.testing.allocator.free(zigfile_path);
const binary = zigfile_path[0 .. zigfile_path.len - 4]; // '.zig' is 4 characters
try testing.buildExe(testargs.zigexec, zigfile_path, binary);because we still need the path to the resulting binary for |
continuation of #11093 to simplify testing IPC