| ... | ... | @@ -796,28 +796,37 @@ fn writeEscaped(out: anytype, input: []const u8) !void { |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | | //#define VT_RED "\x1b[31;1m" |
| 800 | | //#define VT_GREEN "\x1b[32;1m" |
| 801 | | //#define VT_CYAN "\x1b[36;1m" |
| 802 | | //#define VT_WHITE "\x1b[37;1m" |
| 803 | | //#define VT_BOLD "\x1b[0;1m" |
| 804 | | //#define VT_RESET "\x1b[0m" |
| 805 | | |
| 806 | | test "term color" { |
| 807 | | const input_bytes = "A\x1b[32;1mgreen\x1b[0mB"; |
| 808 | | const result = try termColor(std.testing.allocator, input_bytes); |
| 809 | | defer std.testing.allocator.free(result); |
| 810 | | try testing.expectEqualSlices(u8, "A<span class=\"t32_1\">green</span>B", result); |
| 799 | // Returns true if number is in slice. |
| 800 | fn in(slice: []const u8, number: u8) bool { |
| 801 | for (slice) |n| { |
| 802 | if (number == n) return true; |
| 803 | } |
| 804 | return false; |
| 811 | 805 | } |
| 812 | 806 | |
| 813 | 807 | fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 808 | // The SRG sequences generates by the Zig compiler are in the format: |
| 809 | // ESC [ <foreground-color> ; <n> m |
| 810 | // or |
| 811 | // ESC [ <n> m |
| 812 | // |
| 813 | // where |
| 814 | // foreground-color is 31 (red), 32 (green), 36 (cyan) |
| 815 | // n is 0 (reset), 1 (bold), 2 (dim) |
| 816 | // |
| 817 | // Note that 37 (white) is currently not used by the compiler. |
| 818 | // |
| 819 | // See std.debug.TTY.Color. |
| 820 | const supported_sgr_colors = [_]u8{ 31, 32, 36 }; |
| 821 | const supported_sgr_numbers = [_]u8{ 0, 1, 2 }; |
| 822 | |
| 814 | 823 | var buf = std.ArrayList(u8).init(allocator); |
| 815 | 824 | defer buf.deinit(); |
| 816 | 825 | |
| 817 | 826 | var out = buf.writer(); |
| 818 | | var number_start_index: usize = undefined; |
| 819 | | var first_number: usize = undefined; |
| 820 | | var second_number: usize = undefined; |
| 827 | var sgr_param_start_index: usize = undefined; |
| 828 | var sgr_num: u8 = undefined; |
| 829 | var sgr_color: u8 = undefined; |
| 821 | 830 | var i: usize = 0; |
| 822 | 831 | var state: enum { |
| 823 | 832 | start, |
| ... | ... | @@ -848,7 +857,7 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 848 | 857 | }, |
| 849 | 858 | .lbracket => switch (c) { |
| 850 | 859 | '0'...'9' => { |
| 851 | | number_start_index = i; |
| 860 | sgr_param_start_index = i; |
| 852 | 861 | state = .number; |
| 853 | 862 | }, |
| 854 | 863 | else => return error.UnsupportedEscape, |
| ... | ... | @@ -856,13 +865,12 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 856 | 865 | .number => switch (c) { |
| 857 | 866 | '0'...'9' => {}, |
| 858 | 867 | else => { |
| 859 | | first_number = std.fmt.parseInt(usize, input[number_start_index..i], 10) catch unreachable; |
| 860 | | second_number = 0; |
| 868 | sgr_num = try std.fmt.parseInt(u8, input[sgr_param_start_index..i], 10); |
| 869 | sgr_color = 0; |
| 861 | 870 | state = .after_number; |
| 862 | 871 | i -= 1; |
| 863 | 872 | }, |
| 864 | 873 | }, |
| 865 | | |
| 866 | 874 | .after_number => switch (c) { |
| 867 | 875 | ';' => state = .arg, |
| 868 | 876 | 'D' => state = .start, |
| ... | ... | @@ -877,7 +885,7 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 877 | 885 | }, |
| 878 | 886 | .arg => switch (c) { |
| 879 | 887 | '0'...'9' => { |
| 880 | | number_start_index = i; |
| 888 | sgr_param_start_index = i; |
| 881 | 889 | state = .arg_number; |
| 882 | 890 | }, |
| 883 | 891 | else => return error.UnsupportedEscape, |
| ... | ... | @@ -885,7 +893,15 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 885 | 893 | .arg_number => switch (c) { |
| 886 | 894 | '0'...'9' => {}, |
| 887 | 895 | else => { |
| 888 | | second_number = std.fmt.parseInt(usize, input[number_start_index..i], 10) catch unreachable; |
| 896 | // Keep the sequence consistent, foreground color first. |
| 897 | // 32;1m is equivalent to 1;32m, but the latter will |
| 898 | // generate an incorrect HTML class without notice. |
| 899 | sgr_color = sgr_num; |
| 900 | if (!in(&supported_sgr_colors, sgr_color)) return error.UnsupportedForegroundColor; |
| 901 | |
| 902 | sgr_num = try std.fmt.parseInt(u8, input[sgr_param_start_index..i], 10); |
| 903 | if (!in(&supported_sgr_numbers, sgr_num)) return error.UnsupportedNumber; |
| 904 | |
| 889 | 905 | state = .expect_end; |
| 890 | 906 | i -= 1; |
| 891 | 907 | }, |
| ... | ... | @@ -896,10 +912,16 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 896 | 912 | while (open_span_count != 0) : (open_span_count -= 1) { |
| 897 | 913 | try out.writeAll("</span>"); |
| 898 | 914 | } |
| 899 | | if (first_number != 0 or second_number != 0) { |
| 900 | | try out.print("<span class=\"t{d}_{d}\">", .{ first_number, second_number }); |
| 901 | | open_span_count += 1; |
| 915 | if (sgr_num == 0) { |
| 916 | if (sgr_color != 0) return error.UnsupportedColor; |
| 917 | continue; |
| 902 | 918 | } |
| 919 | if (sgr_color != 0) { |
| 920 | try out.print("<span class=\"sgr-{d}_{d}m\">", .{ sgr_color, sgr_num }); |
| 921 | } else { |
| 922 | try out.print("<span class=\"sgr-{d}m\">", .{sgr_num}); |
| 923 | } |
| 924 | open_span_count += 1; |
| 903 | 925 | }, |
| 904 | 926 | else => return error.UnsupportedEscape, |
| 905 | 927 | }, |
| ... | ... | @@ -1227,41 +1249,39 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { |
| 1227 | 1249 | while (iter.next()) |orig_line| { |
| 1228 | 1250 | const line = mem.trimRight(u8, orig_line, " "); |
| 1229 | 1251 | if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { |
| 1230 | | try out.writeAll(start_line ++ "$ <kbd>"); |
| 1252 | try out.writeAll("$ <kbd>"); |
| 1231 | 1253 | const s = std.mem.trimLeft(u8, line[1..], " "); |
| 1232 | 1254 | if (escape) { |
| 1233 | 1255 | try writeEscaped(out, s); |
| 1234 | 1256 | } else { |
| 1235 | 1257 | try out.writeAll(s); |
| 1236 | 1258 | } |
| 1237 | | try out.writeAll("</kbd>" ++ end_line ++ "\n"); |
| 1259 | try out.writeAll("</kbd>" ++ "\n"); |
| 1238 | 1260 | } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { |
| 1239 | | try out.writeAll(start_line ++ "$ <kbd>"); |
| 1261 | try out.writeAll("$ <kbd>"); |
| 1240 | 1262 | const s = std.mem.trimLeft(u8, line[1..], " "); |
| 1241 | 1263 | if (escape) { |
| 1242 | 1264 | try writeEscaped(out, s); |
| 1243 | 1265 | } else { |
| 1244 | 1266 | try out.writeAll(s); |
| 1245 | 1267 | } |
| 1246 | | try out.writeAll(end_line ++ "\n"); |
| 1268 | try out.writeAll("\n"); |
| 1247 | 1269 | cmd_cont = true; |
| 1248 | 1270 | } else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) { |
| 1249 | | try out.writeAll(start_line); |
| 1250 | 1271 | if (escape) { |
| 1251 | 1272 | try writeEscaped(out, line); |
| 1252 | 1273 | } else { |
| 1253 | 1274 | try out.writeAll(line); |
| 1254 | 1275 | } |
| 1255 | | try out.writeAll("</kbd>" ++ end_line ++ "\n"); |
| 1276 | try out.writeAll("</kbd>" ++ "\n"); |
| 1256 | 1277 | cmd_cont = false; |
| 1257 | 1278 | } else { |
| 1258 | | try out.writeAll(start_line); |
| 1259 | 1279 | if (escape) { |
| 1260 | 1280 | try writeEscaped(out, line); |
| 1261 | 1281 | } else { |
| 1262 | 1282 | try out.writeAll(line); |
| 1263 | 1283 | } |
| 1264 | | try out.writeAll(end_line ++ "\n"); |
| 1284 | try out.writeAll("\n"); |
| 1265 | 1285 | } |
| 1266 | 1286 | } |
| 1267 | 1287 | |
| ... | ... | @@ -1507,7 +1527,7 @@ fn genHtml( |
| 1507 | 1527 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1508 | 1528 | const colored_stdout = try termColor(allocator, escaped_stdout); |
| 1509 | 1529 | |
| 1510 | | try shell_out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr }); |
| 1530 | try shell_out.print("$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr }); |
| 1511 | 1531 | if (exited_with_signal) { |
| 1512 | 1532 | try shell_out.print("(process terminated by signal)", .{}); |
| 1513 | 1533 | } |
| ... | ... | @@ -1877,7 +1897,193 @@ fn dumpArgs(args: []const []const u8) void { |
| 1877 | 1897 | print("\n", .{}); |
| 1878 | 1898 | } |
| 1879 | 1899 | |
| 1880 | | test "shell parsed" { |
| 1900 | test "term supported colors" { |
| 1901 | const test_allocator = testing.allocator; |
| 1902 | |
| 1903 | { |
| 1904 | const input = "A\x1b[31;1mred\x1b[0mB"; |
| 1905 | const expect = "A<span class=\"sgr-31_1m\">red</span>B"; |
| 1906 | |
| 1907 | const result = try termColor(test_allocator, input); |
| 1908 | defer test_allocator.free(result); |
| 1909 | try testing.expectEqualSlices(u8, expect, result); |
| 1910 | } |
| 1911 | |
| 1912 | { |
| 1913 | const input = "A\x1b[32;1mgreen\x1b[0mB"; |
| 1914 | const expect = "A<span class=\"sgr-32_1m\">green</span>B"; |
| 1915 | |
| 1916 | const result = try termColor(test_allocator, input); |
| 1917 | defer test_allocator.free(result); |
| 1918 | try testing.expectEqualSlices(u8, expect, result); |
| 1919 | } |
| 1920 | |
| 1921 | { |
| 1922 | const input = "A\x1b[36;1mcyan\x1b[0mB"; |
| 1923 | const expect = "A<span class=\"sgr-36_1m\">cyan</span>B"; |
| 1924 | |
| 1925 | const result = try termColor(test_allocator, input); |
| 1926 | defer test_allocator.free(result); |
| 1927 | try testing.expectEqualSlices(u8, expect, result); |
| 1928 | } |
| 1929 | |
| 1930 | { |
| 1931 | const input = "A\x1b[1mbold\x1b[0mB"; |
| 1932 | const expect = "A<span class=\"sgr-1m\">bold</span>B"; |
| 1933 | |
| 1934 | const result = try termColor(test_allocator, input); |
| 1935 | defer test_allocator.free(result); |
| 1936 | try testing.expectEqualSlices(u8, expect, result); |
| 1937 | } |
| 1938 | |
| 1939 | { |
| 1940 | const input = "A\x1b[2mdim\x1b[0mB"; |
| 1941 | const expect = "A<span class=\"sgr-2m\">dim</span>B"; |
| 1942 | |
| 1943 | const result = try termColor(test_allocator, input); |
| 1944 | defer test_allocator.free(result); |
| 1945 | try testing.expectEqualSlices(u8, expect, result); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | test "term output from zig" { |
| 1950 | // Use data generated by https://github.com/perillo/zig-tty-test-data, |
| 1951 | // with zig version 0.11.0-dev.1898+36d47dd19. |
| 1952 | const test_allocator = testing.allocator; |
| 1953 | |
| 1954 | { |
| 1955 | // 1.1-with-build-progress.out |
| 1956 | const input = "Semantic Analysis [1324] \x1b[25D\x1b[0KLLVM Emit Object... \x1b[20D\x1b[0KLLVM Emit Object... \x1b[20D\x1b[0KLLD Link... \x1b[12D\x1b[0K"; |
| 1957 | const expect = ""; |
| 1958 | |
| 1959 | const result = try termColor(test_allocator, input); |
| 1960 | defer test_allocator.free(result); |
| 1961 | try testing.expectEqualSlices(u8, expect, result); |
| 1962 | } |
| 1963 | |
| 1964 | { |
| 1965 | // 2.1-with-reference-traces.out |
| 1966 | const input = "\x1b[1msrc/2.1-with-reference-traces.zig:3:7: \x1b[31;1merror: \x1b[0m\x1b[1mcannot assign to constant\n\x1b[0m x += 1;\n \x1b[32;1m~~^~~~\n\x1b[0m\x1b[0m\x1b[2mreferenced by:\n main: src/2.1-with-reference-traces.zig:7:5\n callMain: /usr/local/lib/zig/lib/std/start.zig:607:17\n remaining reference traces hidden; use '-freference-trace' to see all reference traces\n\n\x1b[0m"; |
| 1967 | const expect = |
| 1968 | \\<span class="sgr-1m">src/2.1-with-reference-traces.zig:3:7: </span><span class="sgr-31_1m">error: </span><span class="sgr-1m">cannot assign to constant |
| 1969 | \\</span> x += 1; |
| 1970 | \\ <span class="sgr-32_1m">~~^~~~ |
| 1971 | \\</span><span class="sgr-2m">referenced by: |
| 1972 | \\ main: src/2.1-with-reference-traces.zig:7:5 |
| 1973 | \\ callMain: /usr/local/lib/zig/lib/std/start.zig:607:17 |
| 1974 | \\ remaining reference traces hidden; use '-freference-trace' to see all reference traces |
| 1975 | \\ |
| 1976 | \\</span> |
| 1977 | ; |
| 1978 | |
| 1979 | const result = try termColor(test_allocator, input); |
| 1980 | defer test_allocator.free(result); |
| 1981 | try testing.expectEqualSlices(u8, expect, result); |
| 1982 | } |
| 1983 | |
| 1984 | { |
| 1985 | // 2.2-without-reference-traces.out |
| 1986 | const input = "\x1b[1m/usr/local/lib/zig/lib/std/io/fixed_buffer_stream.zig:128:29: \x1b[31;1merror: \x1b[0m\x1b[1minvalid type given to fixedBufferStream\n\x1b[0m else => @compileError(\"invalid type given to fixedBufferStream\"),\n \x1b[32;1m^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\x1b[0m\x1b[1m/usr/local/lib/zig/lib/std/io/fixed_buffer_stream.zig:116:66: \x1b[36;1mnote: \x1b[0m\x1b[1mcalled from here\n\x1b[0mpub fn fixedBufferStream(buffer: anytype) FixedBufferStream(Slice(@TypeOf(buffer))) {\n; \x1b[32;1m~~~~~^~~~~~~~~~~~~~~~~\n\x1b[0m"; |
| 1987 | const expect = |
| 1988 | \\<span class="sgr-1m">/usr/local/lib/zig/lib/std/io/fixed_buffer_stream.zig:128:29: </span><span class="sgr-31_1m">error: </span><span class="sgr-1m">invalid type given to fixedBufferStream |
| 1989 | \\</span> else => @compileError("invalid type given to fixedBufferStream"), |
| 1990 | \\ <span class="sgr-32_1m">^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1991 | \\</span><span class="sgr-1m">/usr/local/lib/zig/lib/std/io/fixed_buffer_stream.zig:116:66: </span><span class="sgr-36_1m">note: </span><span class="sgr-1m">called from here |
| 1992 | \\</span>pub fn fixedBufferStream(buffer: anytype) FixedBufferStream(Slice(@TypeOf(buffer))) { |
| 1993 | \\; <span class="sgr-32_1m">~~~~~^~~~~~~~~~~~~~~~~ |
| 1994 | \\</span> |
| 1995 | ; |
| 1996 | |
| 1997 | const result = try termColor(test_allocator, input); |
| 1998 | defer test_allocator.free(result); |
| 1999 | try testing.expectEqualSlices(u8, expect, result); |
| 2000 | } |
| 2001 | |
| 2002 | { |
| 2003 | // 2.3-with-notes.out |
| 2004 | const input = "\x1b[1msrc/2.3-with-notes.zig:6:9: \x1b[31;1merror: \x1b[0m\x1b[1mexpected type '*2.3-with-notes.Derp', found '*2.3-with-notes.Wat'\n\x1b[0m bar(w);\n \x1b[32;1m^\n\x1b[0m\x1b[1msrc/2.3-with-notes.zig:6:9: \x1b[36;1mnote: \x1b[0m\x1b[1mpointer type child '2.3-with-notes.Wat' cannot cast into pointer type child '2.3-with-notes.Derp'\n\x1b[0m\x1b[1msrc/2.3-with-notes.zig:2:13: \x1b[36;1mnote: \x1b[0m\x1b[1mopaque declared here\n\x1b[0mconst Wat = opaque {};\n \x1b[32;1m^~~~~~~~~\n\x1b[0m\x1b[1msrc/2.3-with-notes.zig:1:14: \x1b[36;1mnote: \x1b[0m\x1b[1mopaque declared here\n\x1b[0mconst Derp = opaque {};\n \x1b[32;1m^~~~~~~~~\n\x1b[0m\x1b[1msrc/2.3-with-notes.zig:4:18: \x1b[36;1mnote: \x1b[0m\x1b[1mparameter type declared here\n\x1b[0mextern fn bar(d: *Derp) void;\n \x1b[32;1m^~~~~\n\x1b[0m\x1b[0m\x1b[2mreferenced by:\n main: src/2.3-with-notes.zig:10:5\n callMain: /usr/local/lib/zig/lib/std/start.zig:607:17\n remaining reference traces hidden; use '-freference-trace' to see all reference traces\n\n\x1b[0m"; |
| 2005 | const expect = |
| 2006 | \\<span class="sgr-1m">src/2.3-with-notes.zig:6:9: </span><span class="sgr-31_1m">error: </span><span class="sgr-1m">expected type '*2.3-with-notes.Derp', found '*2.3-with-notes.Wat' |
| 2007 | \\</span> bar(w); |
| 2008 | \\ <span class="sgr-32_1m">^ |
| 2009 | \\</span><span class="sgr-1m">src/2.3-with-notes.zig:6:9: </span><span class="sgr-36_1m">note: </span><span class="sgr-1m">pointer type child '2.3-with-notes.Wat' cannot cast into pointer type child '2.3-with-notes.Derp' |
| 2010 | \\</span><span class="sgr-1m">src/2.3-with-notes.zig:2:13: </span><span class="sgr-36_1m">note: </span><span class="sgr-1m">opaque declared here |
| 2011 | \\</span>const Wat = opaque {}; |
| 2012 | \\ <span class="sgr-32_1m">^~~~~~~~~ |
| 2013 | \\</span><span class="sgr-1m">src/2.3-with-notes.zig:1:14: </span><span class="sgr-36_1m">note: </span><span class="sgr-1m">opaque declared here |
| 2014 | \\</span>const Derp = opaque {}; |
| 2015 | \\ <span class="sgr-32_1m">^~~~~~~~~ |
| 2016 | \\</span><span class="sgr-1m">src/2.3-with-notes.zig:4:18: </span><span class="sgr-36_1m">note: </span><span class="sgr-1m">parameter type declared here |
| 2017 | \\</span>extern fn bar(d: *Derp) void; |
| 2018 | \\ <span class="sgr-32_1m">^~~~~ |
| 2019 | \\</span><span class="sgr-2m">referenced by: |
| 2020 | \\ main: src/2.3-with-notes.zig:10:5 |
| 2021 | \\ callMain: /usr/local/lib/zig/lib/std/start.zig:607:17 |
| 2022 | \\ remaining reference traces hidden; use '-freference-trace' to see all reference traces |
| 2023 | \\ |
| 2024 | \\</span> |
| 2025 | ; |
| 2026 | |
| 2027 | const result = try termColor(test_allocator, input); |
| 2028 | defer test_allocator.free(result); |
| 2029 | try testing.expectEqualSlices(u8, expect, result); |
| 2030 | } |
| 2031 | |
| 2032 | { |
| 2033 | // 3.1-with-error-return-traces.out |
| 2034 | |
| 2035 | const input = "error: Error\n\x1b[1m/home/zig/src/3.1-with-error-return-traces.zig:5:5\x1b[0m: \x1b[2m0x20b008 in callee (3.1-with-error-return-traces)\x1b[0m\n return error.Error;\n \x1b[32;1m^\x1b[0m\n\x1b[1m/home/zig/src/3.1-with-error-return-traces.zig:9:5\x1b[0m: \x1b[2m0x20b113 in caller (3.1-with-error-return-traces)\x1b[0m\n try callee();\n \x1b[32;1m^\x1b[0m\n\x1b[1m/home/zig/src/3.1-with-error-return-traces.zig:13:5\x1b[0m: \x1b[2m0x20b153 in main (3.1-with-error-return-traces)\x1b[0m\n try caller();\n \x1b[32;1m^\x1b[0m\n"; |
| 2036 | const expect = |
| 2037 | \\error: Error |
| 2038 | \\<span class="sgr-1m">/home/zig/src/3.1-with-error-return-traces.zig:5:5</span>: <span class="sgr-2m">0x20b008 in callee (3.1-with-error-return-traces)</span> |
| 2039 | \\ return error.Error; |
| 2040 | \\ <span class="sgr-32_1m">^</span> |
| 2041 | \\<span class="sgr-1m">/home/zig/src/3.1-with-error-return-traces.zig:9:5</span>: <span class="sgr-2m">0x20b113 in caller (3.1-with-error-return-traces)</span> |
| 2042 | \\ try callee(); |
| 2043 | \\ <span class="sgr-32_1m">^</span> |
| 2044 | \\<span class="sgr-1m">/home/zig/src/3.1-with-error-return-traces.zig:13:5</span>: <span class="sgr-2m">0x20b153 in main (3.1-with-error-return-traces)</span> |
| 2045 | \\ try caller(); |
| 2046 | \\ <span class="sgr-32_1m">^</span> |
| 2047 | \\ |
| 2048 | ; |
| 2049 | |
| 2050 | const result = try termColor(test_allocator, input); |
| 2051 | defer test_allocator.free(result); |
| 2052 | try testing.expectEqualSlices(u8, expect, result); |
| 2053 | } |
| 2054 | |
| 2055 | { |
| 2056 | // 3.2-with-stack-trace.out |
| 2057 | const input = "\x1b[1m/usr/local/lib/zig/lib/std/debug.zig:561:19\x1b[0m: \x1b[2m0x22a107 in writeCurrentStackTrace__anon_5898 (3.2-with-stack-trace)\x1b[0m\n while (it.next()) |return_address| {\n \x1b[32;1m^\x1b[0m\n\x1b[1m/usr/local/lib/zig/lib/std/debug.zig:157:80\x1b[0m: \x1b[2m0x20bb23 in dumpCurrentStackTrace (3.2-with-stack-trace)\x1b[0m\n writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(io.getStdErr()), start_addr) catch |err| {\n \x1b[32;1m^\x1b[0m\n\x1b[1m/home/zig/src/3.2-with-stack-trace.zig:5:36\x1b[0m: \x1b[2m0x20d3b2 in foo (3.2-with-stack-trace)\x1b[0m\n std.debug.dumpCurrentStackTrace(null);\n \x1b[32;1m^\x1b[0m\n\x1b[1m/home/zig/src/3.2-with-stack-trace.zig:9:8\x1b[0m: \x1b[2m0x20b458 in main (3.2-with-stack-trace)\x1b[0m\n foo();\n \x1b[32;1m^\x1b[0m\n\x1b[1m/usr/local/lib/zig/lib/std/start.zig:607:22\x1b[0m: \x1b[2m0x20a965 in posixCallMainAndExit (3.2-with-stack-trace)\x1b[0m\n root.main();\n \x1b[32;1m^\x1b[0m\n\x1b[1m/usr/local/lib/zig/lib/std/start.zig:376:5\x1b[0m: \x1b[2m0x20a411 in _start (3.2-with-stack-trace)\x1b[0m\n @call(.never_inline, posixCallMainAndExit, .{});\n \x1b[32;1m^\x1b[0m\n"; |
| 2058 | const expect = |
| 2059 | \\<span class="sgr-1m">/usr/local/lib/zig/lib/std/debug.zig:561:19</span>: <span class="sgr-2m">0x22a107 in writeCurrentStackTrace__anon_5898 (3.2-with-stack-trace)</span> |
| 2060 | \\ while (it.next()) |return_address| { |
| 2061 | \\ <span class="sgr-32_1m">^</span> |
| 2062 | \\<span class="sgr-1m">/usr/local/lib/zig/lib/std/debug.zig:157:80</span>: <span class="sgr-2m">0x20bb23 in dumpCurrentStackTrace (3.2-with-stack-trace)</span> |
| 2063 | \\ writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(io.getStdErr()), start_addr) catch |err| { |
| 2064 | \\ <span class="sgr-32_1m">^</span> |
| 2065 | \\<span class="sgr-1m">/home/zig/src/3.2-with-stack-trace.zig:5:36</span>: <span class="sgr-2m">0x20d3b2 in foo (3.2-with-stack-trace)</span> |
| 2066 | \\ std.debug.dumpCurrentStackTrace(null); |
| 2067 | \\ <span class="sgr-32_1m">^</span> |
| 2068 | \\<span class="sgr-1m">/home/zig/src/3.2-with-stack-trace.zig:9:8</span>: <span class="sgr-2m">0x20b458 in main (3.2-with-stack-trace)</span> |
| 2069 | \\ foo(); |
| 2070 | \\ <span class="sgr-32_1m">^</span> |
| 2071 | \\<span class="sgr-1m">/usr/local/lib/zig/lib/std/start.zig:607:22</span>: <span class="sgr-2m">0x20a965 in posixCallMainAndExit (3.2-with-stack-trace)</span> |
| 2072 | \\ root.main(); |
| 2073 | \\ <span class="sgr-32_1m">^</span> |
| 2074 | \\<span class="sgr-1m">/usr/local/lib/zig/lib/std/start.zig:376:5</span>: <span class="sgr-2m">0x20a411 in _start (3.2-with-stack-trace)</span> |
| 2075 | \\ @call(.never_inline, posixCallMainAndExit, .{}); |
| 2076 | \\ <span class="sgr-32_1m">^</span> |
| 2077 | \\ |
| 2078 | ; |
| 2079 | |
| 2080 | const result = try termColor(test_allocator, input); |
| 2081 | defer test_allocator.free(result); |
| 2082 | try testing.expectEqualSlices(u8, expect, result); |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | test "printShell" { |
| 1881 | 2087 | const test_allocator = std.testing.allocator; |
| 1882 | 2088 | |
| 1883 | 2089 | { |
| ... | ... | @@ -1885,7 +2091,7 @@ test "shell parsed" { |
| 1885 | 2091 | \\$ zig build test.zig |
| 1886 | 2092 | ; |
| 1887 | 2093 | const expected = |
| 1888 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 2094 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 1889 | 2095 | \\</samp></pre></figure> |
| 1890 | 2096 | ; |
| 1891 | 2097 | |
| ... | ... | @@ -1893,7 +2099,6 @@ test "shell parsed" { |
| 1893 | 2099 | defer buffer.deinit(); |
| 1894 | 2100 | |
| 1895 | 2101 | try printShell(buffer.writer(), shell_out, false); |
| 1896 | | std.log.emerg("{s}", .{buffer.items}); |
| 1897 | 2102 | try testing.expectEqualSlices(u8, expected, buffer.items); |
| 1898 | 2103 | } |
| 1899 | 2104 | { |
| ... | ... | @@ -1902,8 +2107,8 @@ test "shell parsed" { |
| 1902 | 2107 | \\build output |
| 1903 | 2108 | ; |
| 1904 | 2109 | const expected = |
| 1905 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 1906 | | \\<span class="line">build output</span> |
| 2110 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 2111 | \\build output |
| 1907 | 2112 | \\</samp></pre></figure> |
| 1908 | 2113 | ; |
| 1909 | 2114 | |
| ... | ... | @@ -1920,9 +2125,9 @@ test "shell parsed" { |
| 1920 | 2125 | \\$ ./test |
| 1921 | 2126 | ; |
| 1922 | 2127 | const expected = |
| 1923 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 1924 | | \\<span class="line">build output</span> |
| 1925 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 2128 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 2129 | \\build output |
| 2130 | \\$ <kbd>./test</kbd> |
| 1926 | 2131 | \\</samp></pre></figure> |
| 1927 | 2132 | ; |
| 1928 | 2133 | |
| ... | ... | @@ -1940,10 +2145,10 @@ test "shell parsed" { |
| 1940 | 2145 | \\output |
| 1941 | 2146 | ; |
| 1942 | 2147 | const expected = |
| 1943 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 1944 | | \\<span class="line"></span> |
| 1945 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 1946 | | \\<span class="line">output</span> |
| 2148 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 2149 | \\ |
| 2150 | \\$ <kbd>./test</kbd> |
| 2151 | \\output |
| 1947 | 2152 | \\</samp></pre></figure> |
| 1948 | 2153 | ; |
| 1949 | 2154 | |
| ... | ... | @@ -1960,9 +2165,9 @@ test "shell parsed" { |
| 1960 | 2165 | \\output |
| 1961 | 2166 | ; |
| 1962 | 2167 | const expected = |
| 1963 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 1964 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 1965 | | \\<span class="line">output</span> |
| 2168 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 2169 | \\$ <kbd>./test</kbd> |
| 2170 | \\output |
| 1966 | 2171 | \\</samp></pre></figure> |
| 1967 | 2172 | ; |
| 1968 | 2173 | |
| ... | ... | @@ -1981,11 +2186,11 @@ test "shell parsed" { |
| 1981 | 2186 | \\output |
| 1982 | 2187 | ; |
| 1983 | 2188 | const expected = |
| 1984 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span> |
| 1985 | | \\<span class="line"> --build-option</kbd></span> |
| 1986 | | \\<span class="line">build output</span> |
| 1987 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 1988 | | \\<span class="line">output</span> |
| 2189 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \ |
| 2190 | \\ --build-option</kbd> |
| 2191 | \\build output |
| 2192 | \\$ <kbd>./test</kbd> |
| 2193 | \\output |
| 1989 | 2194 | \\</samp></pre></figure> |
| 1990 | 2195 | ; |
| 1991 | 2196 | |
| ... | ... | @@ -1999,15 +2204,15 @@ test "shell parsed" { |
| 1999 | 2204 | // intentional space after "--build-option1 \" |
| 2000 | 2205 | const shell_out = |
| 2001 | 2206 | \\$ zig build test.zig \ |
| 2002 | | \\ --build-option1 \ |
| 2207 | \\ --build-option1 \ |
| 2003 | 2208 | \\ --build-option2 |
| 2004 | 2209 | \\$ ./test |
| 2005 | 2210 | ; |
| 2006 | 2211 | const expected = |
| 2007 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span> |
| 2008 | | \\<span class="line"> --build-option1 \</span> |
| 2009 | | \\<span class="line"> --build-option2</kbd></span> |
| 2010 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 2212 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \ |
| 2213 | \\ --build-option1 \ |
| 2214 | \\ --build-option2</kbd> |
| 2215 | \\$ <kbd>./test</kbd> |
| 2011 | 2216 | \\</samp></pre></figure> |
| 2012 | 2217 | ; |
| 2013 | 2218 | |
| ... | ... | @@ -2023,8 +2228,8 @@ test "shell parsed" { |
| 2023 | 2228 | \\$ ./test |
| 2024 | 2229 | ; |
| 2025 | 2230 | const expected = |
| 2026 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span> |
| 2027 | | \\<span class="line">$ ./test</kbd></span> |
| 2231 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \ |
| 2232 | \\$ ./test</kbd> |
| 2028 | 2233 | \\</samp></pre></figure> |
| 2029 | 2234 | ; |
| 2030 | 2235 | |
| ... | ... | @@ -2041,9 +2246,9 @@ test "shell parsed" { |
| 2041 | 2246 | \\$1 |
| 2042 | 2247 | ; |
| 2043 | 2248 | const expected = |
| 2044 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span> |
| 2045 | | \\<span class="line">$ <kbd>./test</kbd></span> |
| 2046 | | \\<span class="line">$1</span> |
| 2249 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd> |
| 2250 | \\$ <kbd>./test</kbd> |
| 2251 | \\$1 |
| 2047 | 2252 | \\</samp></pre></figure> |
| 2048 | 2253 | ; |
| 2049 | 2254 | |
| ... | ... | @@ -2058,7 +2263,7 @@ test "shell parsed" { |
| 2058 | 2263 | \\$zig build test.zig |
| 2059 | 2264 | ; |
| 2060 | 2265 | const expected = |
| 2061 | | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$zig build test.zig</span> |
| 2266 | \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$zig build test.zig |
| 2062 | 2267 | \\</samp></pre></figure> |
| 2063 | 2268 | ; |
| 2064 | 2269 | |