-
-
Notifications
You must be signed in to change notification settings - Fork 556
[RFC] Add 'optional' key to canonical-schema #1518
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ cache: yarn | |
script: | ||
- bin/check_required_files_present | ||
- sh bin/check_versions | ||
- bin/check_optional | ||
- yarn test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
floating-point | ||
big-integer | ||
unicode |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ is easier to understand with an example: | |
|
||
```json | ||
{ "exercise": "foobar" | ||
, "version" : "1.0.0" | ||
, "version" : "1.1.0" | ||
, "comments": | ||
[ " Comments are always optional and can be used almost anywhere. " | ||
, " " | ||
|
@@ -92,6 +92,15 @@ is easier to understand with an example: | |
} | ||
, "expected" : null | ||
} | ||
{ "description": "Foo'ing a very big number returns nothing" | ||
, "optional" : "big-ints" | ||
, "comments" : [ "Making this test case pass requires using BigInts." ] | ||
, "property" : "foo" | ||
, "input" : { | ||
"word" : "28948022309329048855892746252171976962977213799489202546401021394546514198529" | ||
} | ||
, "expected" : null | ||
} | ||
, { "description": "Bar'ing a name with numbers gives an error" | ||
, "property" : "bar" | ||
, "input" : { | ||
|
@@ -118,6 +127,7 @@ There are also some conventions that must be followed: | |
- If an error is expected (because the input is invalid, or any other reason), the value at `"expected"` should be an object containing exactly one property, `"error"`, whose value is a string. | ||
- The string should explain why the error would occur. | ||
- A particular track's implementation of the exercise **need not** necessarily check that the error includes that exact string as the cause, depending on what is idiomatic in the language (it may not be idiomatic to check strings for error messages). | ||
- Test cases that only some tracks should implement, for example because it would unnecessarily increase the complexity of the exercise in some but not all languages, mark it with an `optional`-key. Multiple cases related to the same reason for optionality should have the same key. The decision that a test case is optional will often be made in the PR discussion, so don't worry about it too much while creating a PR. | ||
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.
This isn't really a convention that must be followed, but I've added it to not discourage contributors since the decision if a case only works on certain tracks isn't easy and requires input from multiple maintainers. However, I don't mind dropping it either if it doesn't fit this list. |
||
|
||
### Test Data Versioning | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
# This script checks that 'optional' fields in canonical-data.json are listed. | ||
|
||
optional_keys_file=OPTIONAL-KEYS.txt | ||
allowed_optional=$(jq -nR '[inputs]' $optional_keys_file) | ||
|
||
failed=0 | ||
|
||
check_optional_for_file() { | ||
json_file=$1 | ||
echo "Checking 'optional' fields in $json_file" | ||
|
||
present_optional=$(jq '[ .cases[] | recurse(.cases[]?) | .optional | select(. != null) ]' $json_file) | ||
invalid_optional=$(jq --null-input \ | ||
--argjson allowed "$allowed_optional" \ | ||
--argjson present "$present_optional" \ | ||
--raw-output '$present - $allowed | join("\n")') | ||
|
||
if [ ! -z "$invalid_optional" ]; then | ||
echo "Invalid optional fields:" | ||
echo "$invalid_optional" | perl -pe 's/^/ - /' | ||
echo | ||
|
||
failed=1 | ||
fi | ||
} | ||
|
||
for json_file in $(git diff --name-only master HEAD | grep '^exercises/.*/canonical-data\.json$'); do | ||
check_optional_for_file $json_file | ||
done | ||
|
||
if [ $failed -gt 0 ]; then | ||
echo "Allowed optional fields (see $optional_keys_file) are:" | ||
cat $optional_keys_file | perl -pe 's/^/ - /' | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
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 example in #1492 explains in the
comments
that "Your track may choose to skip this test". That applies to all cases with anoptional
-key, so it doesn't need to be added to every case, imo. The comment outlines why the test is optional.