Skip to content

Commit 13edd15

Browse files
authored
Add more index error tests (#649)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 6e14ef8 commit 13edd15

File tree

8 files changed

+210
-0
lines changed

8 files changed

+210
-0
lines changed

test/cli/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ endmacro()
1212

1313
if(ONE_INDEX)
1414
sourcemeta_one_test_cli(common index bundle-ref-no-fragment)
15+
sourcemeta_one_test_cli(common index config-file-not-found)
16+
sourcemeta_one_test_cli(common index duplicate-id)
1517
sourcemeta_one_test_cli(common index extend-builtin-not-found)
18+
sourcemeta_one_test_cli(common index extend-file-not-found)
1619
sourcemeta_one_test_cli(common index external-reference)
20+
sourcemeta_one_test_cli(common index flag-unexpected-value)
21+
sourcemeta_one_test_cli(common index id-outside-base)
1722
sourcemeta_one_test_cli(common index invalid-configuration)
1823
sourcemeta_one_test_cli(common index invalid-schema)
1924
sourcemeta_one_test_cli(common index invalid-schema-top-level-ref-draft7)
@@ -22,7 +27,9 @@ if(ONE_INDEX)
2227
sourcemeta_one_test_cli(common index invalid-url-option-urn)
2328
sourcemeta_one_test_cli(common index invalid-url-option-non-http)
2429
sourcemeta_one_test_cli(common index invalid-url-option-no-value)
30+
sourcemeta_one_test_cli(common index no-arguments)
2531
sourcemeta_one_test_cli(common index output-non-directory)
32+
sourcemeta_one_test_cli(common index unknown-option)
2633
sourcemeta_one_test_cli(common index extra-files-on-rebuild)
2734
sourcemeta_one_test_cli(common index extra-directories-on-rebuild)
2835
sourcemeta_one_test_cli(common index directory-schema-same-name)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
"$1" "$(realpath "$TMP")/nonexistent.json" "$TMP/output" 2> "$TMP/output.txt" \
11+
&& CODE="$?" || CODE="$?"
12+
test "$CODE" = "1" || exit 1
13+
14+
cat << EOF > "$TMP/expected.txt"
15+
Writing output to: $(realpath "$TMP")/output
16+
error: could not locate the requested file
17+
at $(realpath "$TMP")/nonexistent.json
18+
EOF
19+
20+
diff "$TMP/output.txt" "$TMP/expected.txt"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << EOF > "$TMP/one.json"
11+
{
12+
"url": "https://sourcemeta.com/",
13+
"contents": {
14+
"example": {
15+
"contents": {
16+
"schemas": {
17+
"baseUri": "https://example.com/",
18+
"path": "./schemas"
19+
}
20+
}
21+
}
22+
}
23+
}
24+
EOF
25+
26+
mkdir "$TMP/schemas"
27+
28+
cat << 'EOF' > "$TMP/schemas/a.json"
29+
{
30+
"$schema": "http://json-schema.org/draft-07/schema#",
31+
"$id": "https://example.com/test"
32+
}
33+
EOF
34+
35+
cat << 'EOF' > "$TMP/schemas/b.json"
36+
{
37+
"$schema": "http://json-schema.org/draft-07/schema#",
38+
"$id": "https://example.com/test"
39+
}
40+
EOF
41+
42+
"$1" "$TMP/one.json" "$TMP/output" 2> "$TMP/output.txt" && CODE="$?" || CODE="$?"
43+
test "$CODE" = "1" || exit 1
44+
45+
cat << EOF > "$TMP/expected.txt"
46+
Writing output to: $(realpath "$TMP")/output
47+
Using configuration: $(realpath "$TMP")/one.json
48+
Detecting: $(realpath "$TMP")/schemas/a.json (#1)
49+
Detecting: $(realpath "$TMP")/schemas/b.json (#2)
50+
unexpected error: Cannot register the same identifier twice
51+
EOF
52+
53+
diff "$TMP/output.txt" "$TMP/expected.txt"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << EOF > "$TMP/one.json"
11+
{
12+
"url": "https://sourcemeta.com/",
13+
"extends": [ "./nonexistent.json" ]
14+
}
15+
EOF
16+
17+
"$1" "$TMP/one.json" "$TMP/output" 2> "$TMP/output.txt" && CODE="$?" || CODE="$?"
18+
test "$CODE" = "1" || exit 1
19+
20+
cat << EOF > "$TMP/expected.txt"
21+
Writing output to: $(realpath "$TMP")/output
22+
Using configuration: $(realpath "$TMP")/one.json
23+
error: Could not read referenced file
24+
from $(realpath "$TMP")/one.json
25+
at "/extends"
26+
to $(realpath "$TMP")/nonexistent.json
27+
EOF
28+
29+
diff "$TMP/output.txt" "$TMP/expected.txt"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
"$1" --verbose=true 2> "$TMP/output.txt" && CODE="$?" || CODE="$?"
11+
test "$CODE" = "1" || exit 1
12+
13+
cat << 'EOF' > "$TMP/expected.txt"
14+
error: This flag cannot take a value 'verbose'
15+
EOF
16+
17+
diff "$TMP/output.txt" "$TMP/expected.txt"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << EOF > "$TMP/one.json"
11+
{
12+
"url": "https://sourcemeta.com/",
13+
"contents": {
14+
"example": {
15+
"contents": {
16+
"schemas": {
17+
"baseUri": "https://example.com/",
18+
"path": "./schemas"
19+
}
20+
}
21+
}
22+
}
23+
}
24+
EOF
25+
26+
mkdir "$TMP/schemas"
27+
28+
cat << 'EOF' > "$TMP/schemas/test.json"
29+
{
30+
"$schema": "http://json-schema.org/draft-07/schema#",
31+
"$id": "https://other.com/test"
32+
}
33+
EOF
34+
35+
"$1" "$TMP/one.json" "$TMP/output" 2> "$TMP/output.txt" && CODE="$?" || CODE="$?"
36+
test "$CODE" = "1" || exit 1
37+
38+
cat << EOF > "$TMP/expected.txt"
39+
Writing output to: $(realpath "$TMP")/output
40+
Using configuration: $(realpath "$TMP")/one.json
41+
Detecting: $(realpath "$TMP")/schemas/test.json (#1)
42+
error: The schema identifier is not relative to the corresponding base
43+
at https://other.com/test
44+
with base https://example.com/
45+
EOF
46+
47+
diff "$TMP/output.txt" "$TMP/expected.txt"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
"$1" > "$TMP/output.txt" 2>/dev/null && CODE="$?" || CODE="$?"
11+
test "$CODE" = "1" || exit 1
12+
13+
# Skip the version line as the edition varies between Community and Enterprise
14+
tail -n +2 "$TMP/output.txt" > "$TMP/output_trimmed.txt"
15+
16+
cat << EOF > "$TMP/expected.txt"
17+
Usage: $(basename "$1") <one.json> <path/to/output/directory>
18+
EOF
19+
20+
diff "$TMP/output_trimmed.txt" "$TMP/expected.txt"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
"$1" --unknown-flag 2> "$TMP/output.txt" && CODE="$?" || CODE="$?"
11+
test "$CODE" = "1" || exit 1
12+
13+
cat << 'EOF' > "$TMP/expected.txt"
14+
error: Unknown option 'unknown-flag'
15+
EOF
16+
17+
diff "$TMP/output.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)