Skip to content

Commit ed4a9cc

Browse files
authored
Merge pull request #764 from package-url/update-tests.md-to-match-test-schema-v0.1
update tests.md to match v0.1 test schema - editorial changes.
2 parents 52055b1 + f433f54 commit ed4a9cc

File tree

2 files changed

+85
-35
lines changed

2 files changed

+85
-35
lines changed

docs/tests.md

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,83 @@
11
## Tests
22

3-
To support the language-neutral testing of `purl` implementations, a test
4-
suite is provided as JSON document named `test-suite-data.json`. This JSON
5-
document contains an array of objects. Each object represents a test with
6-
these key/value pairs some of which may not be normalized:
7-
8-
- **purl**: a `purl` string.
9-
- **canonical**: the same `purl` string in canonical, normalized form
10-
- **type**: the `type` corresponding to this `purl`.
11-
- **namespace**: the `namespace` corresponding to this `purl`.
12-
- **name**: the `name` corresponding to this `purl`.
13-
- **version**: the `version` corresponding to this `purl`.
14-
- **qualifiers**: the `qualifiers` corresponding to this `purl` as an object
15-
of {key: value} qualifier pairs.
16-
- **subpath**: the `subpath` corresponding to this `purl`.
17-
- **is_invalid**: a boolean flag set to true if the test should report an
18-
error
19-
20-
To test `purl` parsing and building, a tool can use this test suite and for
21-
every listed test object, run these tests:
22-
23-
- parsing the test canonical `purl` then re-building a `purl` from these
24-
parsed components should return the test canonical `purl`
25-
26-
- parsing the test `purl` should return the components parsed from the test
27-
canonical `purl`
28-
29-
- parsing the test `purl` then re-building a `purl` from these parsed
30-
components should return the test canonical `purl`
31-
32-
- building a `purl` from the test components should return the test canonical
33-
`purl`
3+
The Package-URL (PURL) specification provides a JSON Schema and test
4+
files to support language-neutral testing of PURL implementations. The
5+
objectives for the PURL schema and test files are to enable tools to conform
6+
to the PURL specification for tool functions such as:
7+
- build a canonical PURL string from a set of PURL component data
8+
- parse a canonical PURL string into a set of PURL components
9+
- parse a PURL string input and rebuild it as a canonical PURL string
10+
11+
The current JSON schema is available at: [`purl-spec/schemas/purl-test.schema-0.1.json`](https://github.com/package-url/purl-spec/blob/main/schemas/purl-test.schema-0.1.json).
12+
13+
The test files are available at:
14+
- [`purl-spec/tests/spec/`](https://github.com/package-url/purl-spec/tree/main/tests/spec):
15+
This folder contains JSON test files that are not for a specific PURL type.
16+
- [`specification-test.json`](https://github.com/package-url/purl-spec/blob/main/tests/spec/specification-test.json) - This file contains an array of test objects
17+
that primarily cover testing the validity of individual PURL components,
18+
separators between PURL components, and complete PURL strings.
19+
- There is a proposal to add separate test files in this folder for each
20+
PURL component.
21+
- [`purl-spec/tests/types/`](https://github.com/package-url/purl-spec/tree/main/tests/types): This folder contains one JSON test file for each registered PURL type. These
22+
tests should be focused on test cases that are specific to a PURL type, such
23+
as those for namespace or qualifiers.
24+
25+
Two key properties in the PURL test JSON schema are:
26+
- Test groups
27+
- Test types
28+
29+
### Test groups
30+
31+
There are two PURL test groups:
32+
- **base**: Test group for base conformance tests. Base tests are pass/fail.
33+
- **advanced**: Test group for advanced tests. Advanced tests are more
34+
permissive than base tests. They may correct some errors.
35+
36+
### Test types
37+
38+
There are three PURL test types:
39+
- **build**: A test to build a canonical PURL output string from an input of
40+
decoded PURL components. See also [`/docs/how-build.md`](https://github.com/package-url/purl-spec/blob/main/docs/how-to-build.md).
41+
- **parse**: A test to parse a PURL input string into a set of decoded components. See also [`/docs/how-parse.md`](https://github.com/package-url/purl-spec/blob/main/docs/how-to-parse.md).
42+
- **roundtrip**: A test to parse an input PURL string and then rebuild it as a
43+
canonical PURL output string.
44+
45+
### Test case basics
46+
47+
#### Test case fields
48+
The fields for each test case are:
49+
- description: description of the test case purpose
50+
- test_group: base or advanced
51+
- test_type: build, parse, or roundtrip
52+
- input: PURL string or set of PURL components
53+
- expected_output: canonical PURL string, set of PURL components or null for
54+
an expected test failure
55+
- expected_failure: true or false
56+
- expected_failure_reason: description of the reason for the test case failure
57+
58+
#### Error handling
59+
The standard error-handling behaviour for all test cases is based on two
60+
properties from the PURL test schema:
61+
```
62+
"expected_failure": {
63+
"title": "Expected failure",
64+
"description": "true if this test input is expected to fail to be processed.",
65+
"type": "boolean",
66+
"default": false
67+
},
68+
"expected_failure_reason": {
69+
"title": "Expected failure reason",
70+
"description": "The reason why this test is expected to fail if expected_failure is true.",
71+
"default": null,
72+
"type": [
73+
"string",
74+
"null"
75+
]
76+
}
77+
```
78+
In the case of a test case failure the `expected_output` is null.
79+
80+
81+
82+
83+

schemas/purl-test.schema-0.1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@
107107
"roundtrip"
108108
],
109109
"meta:enum": {
110-
"build": "A PURL building test from decoded components to a canonical PURL string.",
111-
"parse": "A PURL parsing test from a canonical PURL string to decoded components.",
112-
"roundtrip": "A PURL roundtrip test, parsing then building back a PURL from a canonical string input."
110+
"build": "A test to build a canonical PURL output string from an input of decoded PURL components.",
111+
"parse": "A test to parse a PURL input string into a set of decoded components.",
112+
"roundtrip": "A test to produce a canonical PURL output string from an input PURL string."
113113
}
114114
},
115115
"expected_failure": {
@@ -120,7 +120,7 @@
120120
},
121121
"expected_failure_reason": {
122122
"title": "Expected failure reason",
123-
"description": "The reason why this test is is expected to fail if expected_failure is true.",
123+
"description": "The reason why this test is expected to fail if expected_failure is true.",
124124
"default": null,
125125
"type": [
126126
"string",

0 commit comments

Comments
 (0)