zig/test/incremental/change_embed_file
mlugg f47b8de2ad
incremental: handle @embedFile
Uses of `@embedFile` register dependencies on the corresponding
`Zcu.EmbedFile`. At the start of every update, we iterate all embedded
files and update them if necessary, and invalidate the dependencies if
they changed.

In order to properly integrate with the lazy analysis model, failed
embed files are now reported by the `AnalUnit` which actually used
`@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`.

An incremental test is added covering incremental updates to embedded
files, and I have verified locally that dependency invalidation is
working correctly.
2025-01-25 06:07:08 +00:00

47 lines
1.1 KiB
Plaintext

#target=x86_64-linux-selfhosted
#target=x86_64-linux-cbe
#target=x86_64-windows-cbe
#target=wasm32-wasi-selfhosted
#update=initial version
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll(string);
}
#file=string.txt
Hello, World!
#expect_stdout="Hello, World!\n"
#update=change file contents
#file=string.txt
Hello again, World!
#expect_stdout="Hello again, World!\n"
#update=delete file
#rm_file=string.txt
#expect_error=ignored
#update=remove reference to file
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll("a hardcoded string\n");
}
#expect_stdout="a hardcoded string\n"
#update=re-introduce reference to file
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll(string);
}
#expect_error=ignore
#update=recreate file
#file=string.txt
We're back, World!
#expect_stdout="We're back, World!\n"