authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-11 11:56:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-11 11:56:08-04:00
loge1fbb24d64caa956846405bd42aed59e5b9513f2
tree86a1d3151a5431a7578339fc2a967fb234b27f2f
parentb4e6e301e1a5411d09a306fb96cf4a5c8d0b754f
signaturelock-open Commit is signed but in an unrecognized format.

add test for spawning child process with empty environment

thanks to BenoitJGirard for pointing out the child process implementation needs 3 extra null bytes in #2031

4 files changed, 25 insertions(+), 0 deletions(-)

std/build.zig+6
...@@ -1530,6 +1530,12 @@ pub const RunStep = struct {...@@ -1530,6 +1530,12 @@ pub const RunStep = struct {
1530 }1530 }
1531 }1531 }
15321532
1533 pub fn clearEnvironment(self: *RunStep) void {
1534 const new_env_map = self.builder.allocator.create(BufMap) catch unreachable;
1535 new_env_map.* = BufMap.init(self.builder.allocator);
1536 self.env_map = new_env_map;
1537 }
1538
1533 pub fn addPathDir(self: *RunStep, search_path: []const u8) void {1539 pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
1534 const PATH = if (builtin.os == builtin.Os.windows) "Path" else "PATH";1540 const PATH = if (builtin.os == builtin.Os.windows) "Path" else "PATH";
1535 const env_map = self.getEnvMap();1541 const env_map = self.getEnvMap();
test/build_examples.zig+1
...@@ -19,6 +19,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {...@@ -19,6 +19,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {
19 cases.addBuildFile("test/standalone/pkg_import/build.zig");19 cases.addBuildFile("test/standalone/pkg_import/build.zig");
20 cases.addBuildFile("test/standalone/use_alias/build.zig");20 cases.addBuildFile("test/standalone/use_alias/build.zig");
21 cases.addBuildFile("test/standalone/brace_expansion/build.zig");21 cases.addBuildFile("test/standalone/brace_expansion/build.zig");
22 cases.addBuildFile("test/standalone/empty_env/build.zig");
22 if (false) {23 if (false) {
23 // TODO this test is disabled because it is failing on the CI server's linux. when this is fixed24 // TODO this test is disabled because it is failing on the CI server's linux. when this is fixed
24 // enable it for at least linux25 // enable it for at least linux
test/standalone/empty_env/build.zig created+12
...@@ -0,0 +1,12 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: *Builder) void {
4 const main = b.addExecutable("main", "main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
6
7 const run = main.run();
8 run.clearEnvironment();
9
10 const test_step = b.step("test", "Test it");
11 test_step.dependOn(&run.step);
12}
test/standalone/empty_env/main.zig created+6
...@@ -0,0 +1,6 @@
1const std = @import("std");
2
3pub fn main() void {
4 const env_map = std.os.getEnvMap(std.debug.global_allocator) catch @panic("unable to get env map");
5 std.testing.expect(env_map.count() == 0);
6}