mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
docgen: add exe_build_err tag
This commit is contained in:
parent
54a93e5393
commit
6e4f69a54a
@ -265,6 +265,7 @@ const SeeAlsoItem = struct {
|
||||
const ExpectedOutcome = enum {
|
||||
Succeed,
|
||||
Fail,
|
||||
BuildFail,
|
||||
};
|
||||
|
||||
const Code = struct {
|
||||
@ -468,6 +469,8 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
code_kind_id = Code.Id{ .Exe = ExpectedOutcome.Succeed };
|
||||
} else if (mem.eql(u8, code_kind_str, "exe_err")) {
|
||||
code_kind_id = Code.Id{ .Exe = ExpectedOutcome.Fail };
|
||||
} else if (mem.eql(u8, code_kind_str, "exe_build_err")) {
|
||||
code_kind_id = Code.Id{ .Exe = ExpectedOutcome.BuildFail };
|
||||
} else if (mem.eql(u8, code_kind_str, "test")) {
|
||||
code_kind_id = Code.Id.Test;
|
||||
} else if (mem.eql(u8, code_kind_str, "test_err")) {
|
||||
@ -1025,6 +1028,8 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
|
||||
tmp_dir_name,
|
||||
"--name",
|
||||
code.name,
|
||||
"--color",
|
||||
"on",
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", code.name);
|
||||
switch (code.mode) {
|
||||
@ -1060,6 +1065,39 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
|
||||
if (code.target_str) |triple| {
|
||||
try build_args.appendSlice([][]const u8{ "-target", triple });
|
||||
}
|
||||
if (expected_outcome == .BuildFail) {
|
||||
const result = try os.ChildProcess.exec(
|
||||
allocator,
|
||||
build_args.toSliceConst(),
|
||||
null,
|
||||
&env_map,
|
||||
max_doc_file_size,
|
||||
);
|
||||
switch (result.term) {
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code == 0) {
|
||||
warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
|
||||
for (build_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example incorrectly compiled");
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("{}\nThe following command crashed:\n", result.stderr);
|
||||
for (build_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example compile crashed");
|
||||
},
|
||||
}
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
try out.print("\n{}</code></pre>\n", colored_stderr);
|
||||
break :code_block;
|
||||
}
|
||||
_ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
|
||||
|
||||
if (code.target_str) |triple| {
|
||||
|
Loading…
Reference in New Issue
Block a user