-
Notifications
You must be signed in to change notification settings - Fork 0
test(fixtures): introduce zspec Factory pattern for ProjectConfig + ResourceDef #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,15 @@ | |
| .hash = "nfd-0.1.0-y82kbsSLBgCxj9gDvxK7fxPFYnI3oe2wWx6M9ykp9Gio", | ||
| }, | ||
| .zspec = .{ | ||
| .url = "https://github.com/apotema/zspec/archive/v0.9.1.tar.gz", | ||
| .hash = "zspec-0.9.1-jaKLbbX4AwBKANdetxzzWc3UTO0UY0lcJJzTagQHlt5K", | ||
| .url = "https://github.com/apotema/zspec/archive/v0.9.2.tar.gz", | ||
| // Hash prefix says `0.9.1` because upstream's own | ||
| // `build.zig.zon` still declares `.version = "0.9.1"` at | ||
| // the v0.9.2 tag — Zig's package manager bakes that | ||
| // string into the hash and rejects manual edits with a | ||
| // "hash mismatch" error. The base64 portion is the only | ||
| // integrity-relevant part; the prefix is cosmetic | ||
| // metadata sourced from upstream. | ||
| .hash = "zspec-0.9.1-jaKLbXgMBACFwbNjflhbMyP113leoYjboxn-1UOP-FGw", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reply: Zig 0.16's package manager rejects this edit — |
||
| }, | ||
| .zstbi = .{ | ||
| .url = "git+https://github.com/zig-gamedev/zstbi?ref=main#3813f5f113b26f644cfa01a30155cc76b3526e91", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //! zspec Factory definitions shared across tests. | ||
| //! | ||
| //! Pattern recap (informs #109/#120 follow-up work): | ||
| //! | ||
| //! * `Factory.defineFrom(T, @import("…zon"))` — concise, fixture in | ||
| //! a separate `.zon` file, field-name typo detection at comptime. | ||
| //! Works only when every field of T has a concrete value the zon | ||
| //! literal can coerce to. Slice fields (`[]const X = &.{}`) hit the | ||
| //! `@as(FieldType, .{})` coercion path and fail to compile, so | ||
| //! reserve `defineFrom` for leaf types like `ResourceDef`. | ||
| //! | ||
| //! * `Factory.define(T, .{ ...defaults })` — same comptime defaults, | ||
| //! authored in Zig source. Necessary when T has slice or pointer | ||
| //! fields because we can write `&.{}` and `@as([]const X, &.{})` | ||
| //! explicitly. Use for outer types like `ProjectConfig`. | ||
| //! | ||
| //! Strings inside the defaults are static (comptime). `.build({})` | ||
| //! returns a value whose strings outlive any test arena, so the | ||
| //! resulting `ResourceDef` / `ProjectConfig` can be assigned directly | ||
| //! to a project arena-owned slice without per-field `dupe()` ceremony. | ||
| const zspec = @import("zspec"); | ||
| const Factory = zspec.Factory; | ||
| const project = @import("project.zig"); | ||
|
|
||
| const resource_zon = @import("test_fixtures/resource.zon"); | ||
|
|
||
| pub const ResourceFactory = Factory.defineFrom(project.ResourceDef, resource_zon); | ||
|
|
||
| pub const ProjectConfigFactory = Factory.define(project.ProjectConfig, .{ | ||
| .name = "factory_project", | ||
| .description = "", | ||
| .title = "Factory Project", | ||
| .width = 1280, | ||
| .height = 720, | ||
| .target_fps = 60, | ||
| .backend = .raylib, | ||
| .ecs = .zig_ecs, | ||
| .initial_scene = "main", | ||
| .core_version = "1.12.0", | ||
| .engine_version = "1.35.0", | ||
| .gfx_version = "1.10.0", | ||
| .assembler_version = "0.17.0", | ||
| .resources = @as([]const project.ResourceDef, &.{}), | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .{ | ||
| .name = "sprites", | ||
| .json = "assets/sprites.json", | ||
| .texture = "assets/sprites.png", | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hash prefix for
zspecstill references version0.9.1while the URL has been updated tov0.9.2. While Zig's package manager primarily uses the multihash suffix for integrity, having a version mismatch in the hash string is inconsistent and can be confusing for maintenance. It is recommended to update the prefix to match the new version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reply: tried this — Zig 0.16's package manager rejects the edit with
hash mismatch: manifest declares zspec-0.9.2-... but the fetched package has zspec-0.9.1-.... The version prefix is sourced from upstream's ownbuild.zig.zon.versionfield (still "0.9.1" at the v0.9.2 tag); only the base64 suffix is integrity-relevant. Left the prefix as-is with a comment in build.zig.zon explaining. The real fix is an upstream version bump — filed mentally for next zspec patch.