| ... | ... | @@ -34,6 +34,15 @@ pub fn main() !void { |
| 34 | 34 | const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg")); |
| 35 | 35 | defer allocator.free(out_file_name); |
| 36 | 36 | |
| 37 | var do_code_tests = true; |
| 38 | if (args_it.next(allocator)) |arg| { |
| 39 | if (mem.eql(u8, try arg, "--skip-code-tests")) { |
| 40 | do_code_tests = false; |
| 41 | } else { |
| 42 | @panic("unrecognized arg"); |
| 43 | } |
| 44 | } |
| 45 | |
| 37 | 46 | var in_file = try fs.cwd().openFile(in_file_name, .{ .read = true }); |
| 38 | 47 | defer in_file.close(); |
| 39 | 48 | |
| ... | ... | @@ -50,7 +59,7 @@ pub fn main() !void { |
| 50 | 59 | try fs.cwd().makePath(tmp_dir_name); |
| 51 | 60 | defer fs.cwd().deleteTree(tmp_dir_name) catch {}; |
| 52 | 61 | |
| 53 | | try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe); |
| 62 | try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe, do_code_tests); |
| 54 | 63 | try buffered_writer.flush(); |
| 55 | 64 | } |
| 56 | 65 | |
| ... | ... | @@ -564,8 +573,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 564 | 573 | ); |
| 565 | 574 | } |
| 566 | 575 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 567 | | } else |
| 568 | | unreachable; // TODO issue #707 |
| 576 | } else unreachable; // TODO issue #707 |
| 569 | 577 | try nodes.append(Node{ |
| 570 | 578 | .Code = Code{ |
| 571 | 579 | .id = code_kind_id, |
| ... | ... | @@ -784,12 +792,12 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: |
| 784 | 792 | if (mem.indexOf(u8, src[index..token.loc.start], "//")) |comment_start_off| { |
| 785 | 793 | // render one comment |
| 786 | 794 | const comment_start = index + comment_start_off; |
| 787 | | const comment_end_off = mem.indexOf(u8, src[comment_start .. token.loc.start], "\n"); |
| 795 | const comment_end_off = mem.indexOf(u8, src[comment_start..token.loc.start], "\n"); |
| 788 | 796 | const comment_end = if (comment_end_off) |o| comment_start + o else token.loc.start; |
| 789 | 797 | |
| 790 | 798 | try writeEscaped(out, src[index..comment_start]); |
| 791 | 799 | try out.writeAll("<span class=\"tok-comment\">"); |
| 792 | | try writeEscaped(out, src[comment_start .. comment_end]); |
| 800 | try writeEscaped(out, src[comment_start..comment_end]); |
| 793 | 801 | try out.writeAll("</span>"); |
| 794 | 802 | index = comment_end; |
| 795 | 803 | tokenizer.index = index; |
| ... | ... | @@ -1002,7 +1010,7 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: To |
| 1002 | 1010 | return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src); |
| 1003 | 1011 | } |
| 1004 | 1012 | |
| 1005 | | fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void { |
| 1013 | fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8, do_code_tests: bool) !void { |
| 1006 | 1014 | var code_progress_index: usize = 0; |
| 1007 | 1015 | |
| 1008 | 1016 | var env_map = try process.getEnvMap(allocator); |
| ... | ... | @@ -1061,6 +1069,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any |
| 1061 | 1069 | try out.writeAll("<pre>"); |
| 1062 | 1070 | try tokenizeAndPrint(tokenizer, out, code.source_token); |
| 1063 | 1071 | try out.writeAll("</pre>"); |
| 1072 | |
| 1073 | if (!do_code_tests) { |
| 1074 | print("SKIP\n", .{}); |
| 1075 | continue; |
| 1076 | } |
| 1077 | |
| 1064 | 1078 | const name_plus_ext = try std.fmt.allocPrint(allocator, "{s}.zig", .{code.name}); |
| 1065 | 1079 | const tmp_source_file_name = try fs.path.join( |
| 1066 | 1080 | allocator, |