Skip to content

Commit

Permalink
add test for addEmbedPath
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyShard committed Oct 23, 2024
1 parent 66b224f commit 36c51fd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/standalone/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
.c_compiler = .{
.path = "c_compiler",
},
.c_embed_path = .{
.path = "c_embed_path",
},
.pie = .{
.path = "pie",
},
Expand Down
25 changes: 25 additions & 0 deletions test/standalone/c_embed_path/build.zig
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);
}
1 change: 1 addition & 0 deletions test/standalone/c_embed_path/data/foo.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This text is the contents of foo.data
15 changes: 15 additions & 0 deletions test/standalone/c_embed_path/test.c
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;
}
}

0 comments on commit 36c51fd

Please sign in to comment.