mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
This commit is contained in:
@@ -12,8 +12,8 @@ pub fn main(init: std.process.Init.Minimal) !void {
|
||||
const process_cwd_path = try std.process.getCwdAlloc(gpa);
|
||||
defer gpa.free(process_cwd_path);
|
||||
|
||||
var env_map = try init.environ.createMap(gpa);
|
||||
defer env_map.deinit();
|
||||
var environ_map = try init.environ.createMap(gpa);
|
||||
defer environ_map.deinit();
|
||||
|
||||
var it = try init.args.iterateAllocator(gpa);
|
||||
defer it.deinit();
|
||||
@@ -23,7 +23,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
|
||||
const cwd_path = it.next() orelse break :child_path .{ child_path, false };
|
||||
// If there is a third argument, it is the current CWD somewhere within the cache directory.
|
||||
// In that case, modify the child path in order to test spawning a path with a leading `..` component.
|
||||
break :child_path .{ try std.fs.path.relative(gpa, process_cwd_path, &env_map, cwd_path, child_path), true };
|
||||
break :child_path .{ try std.fs.path.relative(gpa, process_cwd_path, &environ_map, cwd_path, child_path), true };
|
||||
};
|
||||
defer if (needs_free) gpa.free(child_path);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
try std.testing.expectEqual(0, init.env_map.count());
|
||||
try std.testing.expectEqual(0, init.environ_map.count());
|
||||
}
|
||||
|
||||
@@ -126,26 +126,26 @@ pub fn main(init: std.process.Init) !void {
|
||||
|
||||
// Environ.Map
|
||||
{
|
||||
var env_map = try environ.createMap(allocator);
|
||||
defer env_map.deinit();
|
||||
var environ_map = try environ.createMap(allocator);
|
||||
defer environ_map.deinit();
|
||||
|
||||
try std.testing.expectEqualSlices(u8, "123", env_map.get("FOO").?);
|
||||
try std.testing.expectEqual(null, env_map.get("FO"));
|
||||
try std.testing.expectEqual(null, env_map.get("FOOO"));
|
||||
try std.testing.expectEqualSlices(u8, "123", environ_map.get("FOO").?);
|
||||
try std.testing.expectEqual(null, environ_map.get("FO"));
|
||||
try std.testing.expectEqual(null, environ_map.get("FOOO"));
|
||||
if (builtin.os.tag == .windows) {
|
||||
try std.testing.expectEqualSlices(u8, "123", env_map.get("foo").?);
|
||||
try std.testing.expectEqualSlices(u8, "123", environ_map.get("foo").?);
|
||||
}
|
||||
try std.testing.expectEqualSlices(u8, "ABC=123", env_map.get("EQUALS").?);
|
||||
try std.testing.expectEqual(null, env_map.get("EQUALS=ABC"));
|
||||
try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", env_map.get("КИРиллИЦА").?);
|
||||
try std.testing.expectEqualSlices(u8, "ABC=123", environ_map.get("EQUALS").?);
|
||||
try std.testing.expectEqual(null, environ_map.get("EQUALS=ABC"));
|
||||
try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", environ_map.get("КИРиллИЦА").?);
|
||||
if (builtin.os.tag == .windows) {
|
||||
try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", env_map.get("кирИЛЛица").?);
|
||||
try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", environ_map.get("кирИЛЛица").?);
|
||||
}
|
||||
try std.testing.expectEqualSlices(u8, "", env_map.get("NO_VALUE").?);
|
||||
try std.testing.expectEqual(null, env_map.get("NOT_SET"));
|
||||
try std.testing.expectEqualSlices(u8, "", environ_map.get("NO_VALUE").?);
|
||||
try std.testing.expectEqual(null, environ_map.get("NOT_SET"));
|
||||
if (builtin.os.tag == .windows) {
|
||||
try std.testing.expectEqualSlices(u8, "hi", env_map.get("=HIDDEN").?);
|
||||
try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", env_map.get("INVALID_UTF16_\xed\xa0\x80").?);
|
||||
try std.testing.expectEqualSlices(u8, "hi", environ_map.get("=HIDDEN").?);
|
||||
try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", environ_map.get("INVALID_UTF16_\xed\xa0\x80").?);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
const cwd = try std.process.getCwdAlloc(init.arena.allocator());
|
||||
|
||||
// If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
|
||||
const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.env_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
|
||||
const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
|
||||
defer gpa.free(exe_rel_path);
|
||||
|
||||
try std.Io.Dir.cwd().symLink(io, exe_rel_path, symlink_path, .{});
|
||||
|
||||
@@ -94,7 +94,7 @@ fn testExecBat(gpa: Allocator, io: Io, bat: []const u8, args: []const []const u8
|
||||
const can_have_trailing_empty_args = std.mem.eql(u8, bat, "args3.bat");
|
||||
|
||||
const result = try std.process.run(gpa, io, .{
|
||||
.env_map = env,
|
||||
.environ_map = env,
|
||||
.argv = argv,
|
||||
});
|
||||
defer gpa.free(result.stdout);
|
||||
|
||||
@@ -141,7 +141,7 @@ fn testExecBat(gpa: Allocator, io: Io, bat: []const u8, args: []const []const u8
|
||||
const can_have_trailing_empty_args = std.mem.eql(u8, bat, "args3.bat");
|
||||
|
||||
const result = try std.process.run(gpa, io, .{
|
||||
.env_map = env,
|
||||
.environ_map = env,
|
||||
.argv = argv,
|
||||
});
|
||||
defer gpa.free(result.stdout);
|
||||
|
||||
@@ -96,12 +96,12 @@ fn checkRelative(
|
||||
expected_stdout: []const u8,
|
||||
argv: []const []const u8,
|
||||
cwd: ?[]const u8,
|
||||
env_map: ?*const std.process.Environ.Map,
|
||||
environ_map: ?*const std.process.Environ.Map,
|
||||
) !void {
|
||||
const result = try std.process.run(allocator, io, .{
|
||||
.argv = argv,
|
||||
.cwd = cwd,
|
||||
.env_map = env_map,
|
||||
.environ_map = environ_map,
|
||||
});
|
||||
defer allocator.free(result.stdout);
|
||||
defer allocator.free(result.stderr);
|
||||
|
||||
Reference in New Issue
Block a user