-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66b224f
commit 36c51fd
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const test_step = b.step("test", "Test it"); | ||
b.default_step = test_step; | ||
|
||
const optimize: std.builtin.OptimizeMode = .Debug; | ||
|
||
const exe = b.addExecutable(.{ | ||
.name = "test", | ||
.target = b.graph.host, | ||
.optimize = optimize, | ||
}); | ||
exe.addCSourceFile(.{ | ||
.file = b.path("test.c"), | ||
.flags = &.{"-std=c23"}, | ||
}); | ||
exe.linkLibC(); | ||
exe.addEmbedPath(b.path("data")); | ||
|
||
const run_c_cmd = b.addRunArtifact(exe); | ||
run_c_cmd.expectExitCode(0); | ||
run_c_cmd.skip_foreign_checks = true; | ||
test_step.dependOn(&run_c_cmd.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This text is the contents of foo.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
int main(void) { | ||
// Raw bytes; not a C string | ||
const char data[] = { | ||
#embed <foo.data> | ||
}; | ||
const char *expected = "This text is the contents of foo.data\n"; | ||
if (sizeof data == strlen(expected) && memcmp(data, expected, sizeof data) == 0) { | ||
return EXIT_SUCCESS; | ||
} else { | ||
return EXIT_FAILURE; | ||
} | ||
} |