Skip to content

examples: ship without CI; docs and code drift apart silently #231

@carlos7ags

Description

@carlos7ags

Problem

examples/ has no *_test.go files. The example programs ship with detailed doc comments listing required system fonts and platform-specific expectations, but nothing exercises them end-to-end. Issue #227 was effectively the user being our CI for examples/cjk/main.go:

  • The example's doc comment said it works on Windows with msyh.ttc and Ubuntu with NotoSansCJK-Regular.ttc
  • Both paths hit the TTC-dispatch bug
  • The example was tested on macOS, where findCJKFont() happens to return Arial Unicode.ttf (a TTF, not a TTC)
  • Nobody caught it until a Windows user ran it

Proposal

Add a test per example that:

  1. Compiles and runs the example with a synthetic / minimal-system fixture (reuse the loadAnySystemTTF + buildSyntheticTTC helpers that landed for CJK fail render some Chinese Characters. #227)
  2. Asserts the produced PDF starts with %PDF- and embeds the requested font (BaseFont check)
  3. Skips cleanly when no compatible fixture is available, rather than skipping silently the whole thing

Sketch:

// examples/cjk/main_test.go
func TestCJKExampleProducesValidPDF(t *testing.T) {
    if testing.Short() { t.Skip(\"example test (use -tags examples to enable in default runs)\") }
    // Stub findCJKFont to return a synthetic TTC built from a Latin TTF, so
    // the test runs on any host. Or use os.Setenv to point findCJKFont at
    // a fixture path.
    // Run main(), capture stdout, assert cjk.pdf starts with %PDF- and
    // includes the requested @font-face PostScript name as BaseFont.
}

Some examples may need a small refactor (extract buildHTML + findCJKFont from main() so tests can call them directly without re-running os.Exit).

Scope suggestion

Phase 1: examples/cjk (the one #227 reported). Phase 2: roll out to other examples on the same template (examples/fonts, examples/zugferd, examples/sign).

Acceptance criteria

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions