From 36c51fdfe3b410b4081da28ecb3cf0b9bc3870e6 Mon Sep 17 00:00:00 2001 From: GalaxyShard Date: Wed, 9 Oct 2024 18:34:34 -0400 Subject: [PATCH] add test for addEmbedPath --- test/standalone/build.zig.zon | 3 +++ test/standalone/c_embed_path/build.zig | 25 ++++++++++++++++++++++ test/standalone/c_embed_path/data/foo.data | 1 + test/standalone/c_embed_path/test.c | 15 +++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/standalone/c_embed_path/build.zig create mode 100644 test/standalone/c_embed_path/data/foo.data create mode 100644 test/standalone/c_embed_path/test.c diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 30ec07823b75..b34cf5b54c4b 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -126,6 +126,9 @@ .c_compiler = .{ .path = "c_compiler", }, + .c_embed_path = .{ + .path = "c_embed_path", + }, .pie = .{ .path = "pie", }, diff --git a/test/standalone/c_embed_path/build.zig b/test/standalone/c_embed_path/build.zig new file mode 100644 index 000000000000..0247c99a4519 --- /dev/null +++ b/test/standalone/c_embed_path/build.zig @@ -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); +} diff --git a/test/standalone/c_embed_path/data/foo.data b/test/standalone/c_embed_path/data/foo.data new file mode 100644 index 000000000000..0f3e1106c996 --- /dev/null +++ b/test/standalone/c_embed_path/data/foo.data @@ -0,0 +1 @@ +This text is the contents of foo.data diff --git a/test/standalone/c_embed_path/test.c b/test/standalone/c_embed_path/test.c new file mode 100644 index 000000000000..babfdfe700b3 --- /dev/null +++ b/test/standalone/c_embed_path/test.c @@ -0,0 +1,15 @@ + +#include +#include +int main(void) { + // Raw bytes; not a C string + const char data[] = { +#embed + }; + 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; + } +}