Skip to content

About

Conformance test suites & tools for JSON, YAML & OAI documents

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

conformance-suites

Tests Coverage CI vuln scan CodeQL

Release CodeFactor Grade License

GoDoc Discord Channel go version Top language Commits since latest release


Conformance test suites for JSON and YAML parsers, generated from the published grammars.

Announcements

  • 2026-11-2 7 :
    • v0.0.4 landed, first YAML test corpus released (compact)

Status

Early days: the API is still in flux. Documentation and code are still being honed...

A first corpus is released (that's the compact YAML compact, with ~ 28 000 documents). Other will follow suit!

Test suites for YAML 1.2 and JSON (RFC 8259) ship today. Each comes with an oracle, a suite generator and a compact corpus embedded in Go.

Full-size corpora ship as release assets.

Motivation

Hand-written test suites such as the YAML Test Suite are precise but small.

We want to test parsers on thousands of documents, most of them broken in ways nobody would write by hand. We also want tools to test our YAML and JSON parsers using property-based and fuzz tests.

For that we need corpus generators, based on grammars and that are smart enough to capture extra-grammar rules.

Each document produced needs a verdict, and a classification to compare and explain the outcome of different parsers, which may come with different implementation-specific stances.

This project compiles the grammar each specification publishes into a recognizer, and uses it as the oracle.

Where a specification leaves a choice to the implementation, a case carries a tag, and we may declare a parser's position on each tag.

Documentation

The documentation site explains the file format, the tags and positions, and how to score a parser.

Usage

go get github.com/go-openapi/conformance-suites

Ask the oracles directly:

import (
    jsoncorpus "github.com/go-openapi/conformance-suites/json"
    yamlcorpus "github.com/go-openapi/conformance-suites/yaml"
)

ok := yamlcorpus.Stream([]byte("a: [1, 2]\n")).OK // YAML 1.2
ok = jsoncorpus.Text([]byte(`{"a":1}`)).OK         // RFC 8259

Read an embedded corpus, then score your parser case by case with a stance.Table:

import yamlembed "github.com/go-openapi/conformance-suites/yaml/corpus" // a module of its own: 1.6 MB

header, cases, err := jsoncorpus.CompactSuite() // in the root module
header, cases, err = yamlembed.CompactSuite()

To go past the corpus, seed a Go fuzz target with it, or draw YAML documents for property tests with yamlgen and rapid: see Fuzz and property tests.

Corpora

A corpus is a gzipped JSON Lines file: a parser written in any language can be scored against it.

Consensus

For YAML specifically, it is very difficult to compare parsers.

We have taken inspiration from the work by @perlpunk there YAML test matrix. and produce our own comparison of YAML parsers.

Our consensus report compares fewer parsers, and tries to provide a deeper insight on how their differ. We introduce our new YAML parser go-openapi/go-yaml to the bunch.

Modules

module packages contents
root suite, stance, json (jsoncorpus), yaml (yamlcorpus) the file format, positions and outcomes, the JSON suite, the YAML oracle
yaml/yamlgen yamlgen, yamlbuild the YAML generator and corpus builder
yaml/corpus yamlembed the compact YAML corpus, embedded
yaml/consensus consensus, goopenapi, goyaml, libfyaml, perlref, yamlstar, cmd/consensus adapters for five YAML implementations, and the command that writes the consensus report
yaml/calibrate tests only checks the generator against go-openapi/go-yaml

The root module imports only the standard library. Only yaml/consensus and yaml/calibrate import a parser.

Known limitations

  • The recognizer stores offsets as int32: documents are limited to 2 GiB.
  • The oracle reads UTF-8. A case in another encoding is tagged, or marked opaque when the oracle cannot decode it.
  • Verdicts are YAML 1.2 only: there is no YAML 1.1 grammar.

Credits

  • The YAML Test Suite by @ingydotnet. We vendor it under internal/yamltestsuite to calibrate the YAML recognizer.
  • JSONTestSuite by Nicolas Seriot. We vendor it under internal/jsontestsuite to calibrate the JSON recognizer, and check that the generated JSON corpus holds every construct it holds.
  • yaml/yaml-grammar, which publishes the YAML 1.2 productions as data. Our YAML recognizer is compiled from it.
  • The YAML test matrix by @perlpunk has been a valuable source of inspiration for our work.

Change log

See https://github.com/go-openapi/conformance-suites/releases

References

Academic work on the topic of grammar-based test generation

Prior art

Licensing

This library ships under the SPDX-License-Identifier: Apache-2.0.

The vendored YAML Test Suite and JSONTestSuite fixtures ship under the MIT License. See NOTICE.

Other documentation

Cutting a new release

Maintainers can cut a new release by either:

  • running this workflow
  • or pushing a semver tag
    • signed tags are preferred
    • The tag message is prepended to release notes

About

Conformance test suites & tools for JSON, YAML & OAI documents

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages