Skip to content

test, check: assertive tests, runnable examples, real ActivityConf compatibility check, and CheckError→Error rename#33

Merged
Kybxd merged 5 commits into
masterfrom
do-not-edit
May 26, 2026
Merged

test, check: assertive tests, runnable examples, real ActivityConf compatibility check, and CheckError→Error rename#33
Kybxd merged 5 commits into
masterfrom
do-not-edit

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented May 26, 2026

Description

Summary

Overhauls the checker test surface and tightens a few generator/runtime rough edges:

  • Replaces the old test/main.go print-and-eyeball runner with a proper assertive go test suite.
  • Adds runnable Go examples (Example_check, Example_checkCompatibility) that double as living docs.
  • Renames the generated error type CheckErrorError and Issue.Error()Issue.String() for better Go ergonomics.
  • Implements a real, deterministic ActivityConf.CheckCompatibility (was a placeholder that dumped two prototexts with non-deterministic map ordering).
  • Bumps tableau to pick up CSV load-origin metadata and adds the fixtures needed to exercise it.

Details

Tests & examples

  • test/main.go is deleted; test/main_test.go is rewritten as standard testing.T cases covering Hub.Check (text + JSON formats), Hub.CheckCompatibility (old/new snapshot pairs), tableau.Filter, SkipLoadErrors, BreakFailedCount, and WithLoadOptions(load.IgnoreUnknownFields()).
  • test/example_test.go adds two // Output:-asserted examples:
    • Example_check uses BreakFailedCount(1) to keep output stable at a single issue.
    • Example_checkCompatibility narrows the run to ItemConf + ActivityConf via tableau.Filter, so output is a single deterministic line and err can be printed directly — no errors.As / sort / first-line-truncation hacks. Other messagers (e.g. ThemeConf) are filtered out because their load errors carry a multi-line file excerpt.
  • .github/workflows/testing.yml drops the obsolete go test test/main.go step; go test ./... now covers everything.

check package rename

  • Generator templates (cmd/protoc-gen-go-tableau-checker/embed/templates/error.go.tpl, hub.go.tpl) and the regenerated test/check/error.check.go / test/check/hub.check.go:
    • CheckErrorError (canonical Go name for an error type wrapping Issues []*Issue).
    • Issue.Error()Issue.String() (an Issue is a value, not itself an error).
  • Downstream users who regenerate from these templates will see *check.Error / Issue.String() instead of *check.CheckError / Issue.Error().

Real ActivityConf.CheckCompatibility

  • test/check/test_conf.check.go: replaces the placeholder that unconditionally returned a two-prototext dump with a real check — diff old vs. new ItemConf.item_map, collect ids removed in the new snapshot, sort with slices.Sort (Go 1.24), and return a single-line error:
    ItemConf incompatible: N item id(s) removed in new version: [...]
    
  • This makes the message deterministic (no map-iteration order leaking through prototext) and lets both main_test.go and Example_checkCompatibility assert on the full string.

Deps & fixtures

  • go.mod / go.sum: bump tableau to the version exposing CSV load-origin metadata.
  • New fixtures test/testdata2/{Item#ItemConf,Test#ChapterConf}.csv and test/testdata3/{Item#ItemConf,Test#ChapterConf}.csv to drive the new compatibility cases across distinct origins.
  • Minor proto tweaks in test/proto/item_conf.proto and test/proto/test_conf.proto to support the fixtures.

Test plan

  • go test ./... — green, including both examples.
  • go vet ./... — clean.
  • Example_checkCompatibility ran 5+ times in a row with stable output.

Breaking changes

  • Generated code: *check.CheckError*check.Error, Issue.Error()Issue.String(). Regenerate to pick up the new names.
  • test/main.go removed; use go test ./....

Kybxd added 3 commits May 26, 2026 10:27
- Remove test/main.go and the corresponding `go run .` step in the CI
  testing workflow; everything previously exercised there is now covered
  by `go test`.
- Move `Filter`, `protoPkg`, `pathPrefix` into test/main_test.go so the
  test directory is self-contained.
- Strengthen assertions in TestLoad / TestCheck / TestCheckCompatibility:
  validate Issue.Kind, Message prefixes ("load failed:" /
  "custom check failed:"), Workbook/Worksheet names, the exact text
  output for the single-issue Check case, and JSON payload keys
  ("workbook":, "worksheet":, "load failed:, "custom check failed:).
- Mark the generated error.<ext>.go header with "DO NOT EDIT" by passing
  doNotEdit=true in generateError, since the whole file is templated and
  not meant to be hand-edited. Regenerated test/check/error.check.go to
  match.
…String

Resolve two lint findings (revive `exported`/stutter and `errname`) on
the generated check package without weakening semantics:

- CheckError -> Error: avoid the `check.CheckError` stutter at the call
  site; consumers now use `check.Error`, which is the conventional Go
  name for a package's primary error type.
- Issue.Error() -> Issue.String(): a single Issue is a diagnostic
  record, not an error value. The aggregate `*Error` is what implements
  the `error` interface; an individual `*Issue` now satisfies
  `fmt.Stringer` instead, so `errname` no longer flags it.

Updated both code generator templates (error.go.tpl, hub.go.tpl) and
regenerated test/check/error.check.go and test/check/hub.check.go.
test/main_test.go is updated to use *check.Error in errors.As targets.

Verified with `go vet ./...` and `go test ./...` (all green).
Comment thread test/main.go
@@ -1,64 +0,0 @@
package main
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not deprecate it. We can use go Example Tests for usage reference.

Kybxd added 2 commits May 26, 2026 17:30
Port the previously deleted test/main.go demo into Go example tests so the
canonical Hub.Check / Hub.CheckCompatibility usage stays exercised by
`go test` and discoverable via `go doc`.

- Example_check: invokes Check on testdata/ with BreakFailedCount(1) so a
  single deterministic custom-check error is asserted via `// Output:`.
- Example_checkCompatibility: invokes CheckCompatibility on testdata/ vs
  testdata1/ with SkipLoadErrors and BreakFailedCount(10); unwraps the
  returned *check.Error, sorts issues by (workbook, worksheet, kind), and
  prints `[kind] workbook/worksheet: <first-line-of-message>` for each
  issue. Sorting + first-line-only formatting eliminates ordering and
  prototext map non-determinism, allowing a full `// Output:` assertion
  over all collected issues.
Replace the placeholder CheckCompatibility method with a real implementation
that detects removed item IDs between old and new config snapshots. Update
tests and examples to reflect the new behavior and simplify deterministic
output handling.
@Kybxd Kybxd changed the title test+gen: harden checker test assertions and rename CheckError -> Error / Issue.Error -> Issue.String test, check: assertive tests, runnable examples, real ActivityConf compatibility check, and CheckError→Error rename May 26, 2026
@Kybxd Kybxd merged commit 22b1da5 into master May 26, 2026
2 checks passed
@Kybxd Kybxd deleted the do-not-edit branch May 26, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants