| ... | ... | @@ -931,3 +931,36 @@ pub fn createNullDelimitedEnvMap(arena: *mem.Allocator, env_map: *const std.BufM |
| 931 | 931 | } |
| 932 | 932 | return envp_buf[0..envp_count :null]; |
| 933 | 933 | } |
| 934 | |
| 935 | test "createNullDelimitedEnvMap" { |
| 936 | const testing = std.testing; |
| 937 | const allocator = testing.allocator; |
| 938 | var envmap = BufMap.init(allocator); |
| 939 | defer envmap.deinit(); |
| 940 | |
| 941 | try envmap.set("HOME", "/home/ifreund"); |
| 942 | try envmap.set("WAYLAND_DISPLAY", "wayland-1"); |
| 943 | try envmap.set("DISPLAY", ":1"); |
| 944 | try envmap.set("DEBUGINFOD_URLS", " "); |
| 945 | try envmap.set("XCURSOR_SIZE", "24"); |
| 946 | |
| 947 | var arena = std.heap.ArenaAllocator.init(allocator); |
| 948 | defer arena.deinit(); |
| 949 | const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap); |
| 950 | |
| 951 | testing.expectEqual(@as(usize, 5), environ.len); |
| 952 | |
| 953 | inline for (.{ |
| 954 | "HOME=/home/ifreund", |
| 955 | "WAYLAND_DISPLAY=wayland-1", |
| 956 | "DISPLAY=:1", |
| 957 | "DEBUGINFOD_URLS= ", |
| 958 | "XCURSOR_SIZE=24", |
| 959 | }) |target| { |
| 960 | for (environ) |variable| { |
| 961 | if (mem.eql(u8, mem.span(variable orelse continue), target)) break; |
| 962 | } else { |
| 963 | testing.expect(false); // Environment variable not found |
| 964 | } |
| 965 | } |
| 966 | } |