Skip to content

Commit

Permalink
Merge pull request #308 from serokell/int-index/golden
Browse files Browse the repository at this point in the history
[Chore] Tests: golden files, add BATS_ACCEPT
  • Loading branch information
int-index authored Nov 19, 2024
2 parents 5c826b2 + 3f687de commit 671f527
Show file tree
Hide file tree
Showing 37 changed files with 315 additions and 311 deletions.
67 changes: 4 additions & 63 deletions tests/golden/check-anchors/check-anchors.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,13 @@ load '../helpers/bats-file/load'
load '../helpers'

@test "We report ambiguous anchor references" {
golden_file=$(realpath expected1.gold)
to_temp xrefcheck -r ambiguous-anchors
assert_diff - <<EOF
=== Invalid references found ===
➥ In file a.md
bad reference (file-local) at src:16:1-43:
- text: "ambiguous anchor in this file"
- anchor: some-text
Ambiguous reference to anchor 'some-text'
In file a.md
It could refer to either:
- some-text (header I) at src:6:1-11
- some-text (header I) at src:8:1-15
- some-text (header II) at src:12:1-12
Use of ambiguous anchors is discouraged because the target
can change silently while the document containing it evolves.
➥ In file b.md
bad reference (relative) at src:7:1-48:
- text: "ambiguous anchor in other file"
- link: a.md
- anchor: some-text
Ambiguous reference to anchor 'some-text'
In file a.md
It could refer to either:
- some-text (header I) at src:6:1-11
- some-text (header I) at src:8:1-15
- some-text (header II) at src:12:1-12
Use of ambiguous anchors is discouraged because the target
can change silently while the document containing it evolves.
Invalid references dumped, 2 in total.
EOF
assert_diff
}

@test "We report references to non-existing anchors, giving hints about similar ones" {
golden_file=$(realpath expected2.gold)
to_temp xrefcheck -r non-existing-anchors
assert_diff - <<EOF
=== Invalid references found ===
➥ In file a.md
bad reference (file-local) at src:12:1-13:
- text: "broken"
- anchor: h3
Anchor 'h3' is not present, did you mean:
- h1 (header I) at src:6:1-4
- h2 (header II) at src:8:1-5
➥ In file a.md
bad reference (file-local) at src:14:1-18:
- text: "broken"
- anchor: heading
Anchor 'heading' is not present, did you mean:
- the-heading (header I) at src:10:1-13
➥ In file a.md
bad reference (file-local) at src:16:1-31:
- text: "broken"
- anchor: really-unique-anchor
Anchor 'really-unique-anchor' is not present
Invalid references dumped, 3 in total.
EOF
assert_diff
}
32 changes: 32 additions & 0 deletions tests/golden/check-anchors/expected1.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== Invalid references found ===

➥ In file a.md
bad reference (file-local) at src:16:1-43:
- text: "ambiguous anchor in this file"
- anchor: some-text

Ambiguous reference to anchor 'some-text'
In file a.md
It could refer to either:
- some-text (header I) at src:6:1-11
- some-text (header I) at src:8:1-15
- some-text (header II) at src:12:1-12
Use of ambiguous anchors is discouraged because the target
can change silently while the document containing it evolves.

➥ In file b.md
bad reference (relative) at src:7:1-48:
- text: "ambiguous anchor in other file"
- link: a.md
- anchor: some-text

Ambiguous reference to anchor 'some-text'
In file a.md
It could refer to either:
- some-text (header I) at src:6:1-11
- some-text (header I) at src:8:1-15
- some-text (header II) at src:12:1-12
Use of ambiguous anchors is discouraged because the target
can change silently while the document containing it evolves.

Invalid references dumped, 2 in total.
27 changes: 27 additions & 0 deletions tests/golden/check-anchors/expected2.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== Invalid references found ===

➥ In file a.md
bad reference (file-local) at src:12:1-13:
- text: "broken"
- anchor: h3

Anchor 'h3' is not present, did you mean:
- h1 (header I) at src:6:1-4
- h2 (header II) at src:8:1-5

➥ In file a.md
bad reference (file-local) at src:14:1-18:
- text: "broken"
- anchor: heading

Anchor 'heading' is not present, did you mean:
- the-heading (header I) at src:10:1-13

➥ In file a.md
bad reference (file-local) at src:16:1-31:
- text: "broken"
- anchor: really-unique-anchor

Anchor 'really-unique-anchor' is not present

Invalid references dumped, 3 in total.
30 changes: 2 additions & 28 deletions tests/golden/check-autolinks/check-autolinks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@ load '../helpers/bats-file/load'
load '../helpers'

@test "We're finding and checking autolinks" {
golden_file=$(realpath expected.gold)
to_temp xrefcheck -v
assert_diff - <<EOF
=== Repository data ===
file-with-autolinks.md:
- references:
- reference (external):
- text: "https://www.google.com/doodles"
- link: https://www.google.com/doodles
- reference (external) at src:8:0-18:
- text: "www.commonmark.org"
- link: http://www.commonmark.org
- anchors:
none
=== Invalid references found ===
➥ In file file-with-autolinks.md
bad reference (external) at src:8:0-18:
- text: "www.commonmark.org"
- link: http://www.commonmark.org
Permanent redirect found:
-| http://www.commonmark.org
-> https://commonmark.org
^-- stopped before this one
Invalid references dumped, 1 in total.
EOF
assert_diff
}
26 changes: 26 additions & 0 deletions tests/golden/check-autolinks/expected.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== Repository data ===

file-with-autolinks.md:
- references:
- reference (external):
- text: "https://www.google.com/doodles"
- link: https://www.google.com/doodles
- reference (external) at src:8:0-18:
- text: "www.commonmark.org"
- link: http://www.commonmark.org
- anchors:
none

=== Invalid references found ===

➥ In file file-with-autolinks.md
bad reference (external) at src:8:0-18:
- text: "www.commonmark.org"
- link: http://www.commonmark.org

Permanent redirect found:
-| http://www.commonmark.org
-> https://commonmark.org
^-- stopped before this one

Invalid references dumped, 1 in total.
5 changes: 3 additions & 2 deletions tests/golden/check-backslash/check-backslash.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ load '../helpers'


@test "Checking files with backslash" {
golden_file=$(realpath expected.gold)

cp a.md $TEST_TEMP_DIR
cp expected.gold $TEST_TEMP_DIR
touch "$TEST_TEMP_DIR/a\a.md" || \
return 0 # Cannot be tested on Windows

Expand All @@ -29,5 +30,5 @@ EOF

to_temp xrefcheck -v

assert_diff expected.gold
assert_diff
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ load '../helpers'


@test "GitHub anchors: check, ambiguous and similar detection is case-insensitive" {
golden_file=$(realpath expected1.gold)
to_temp xrefcheck -c config-github.yaml

assert_diff expected1.gold
assert_diff
}

@test "GitLab anchors: check and ambiguous detection is case-sensitive, but similar detection is not" {
golden_file=$(realpath expected2.gold)
to_temp xrefcheck -c config-gitlab.yaml

assert_diff expected2.gold
assert_diff
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ load '../helpers'


@test "GitHub paths: case-sensitive" {
golden_file=$(realpath expected.gold)
to_temp xrefcheck -v -c config-github.yaml

assert_diff expected.gold
assert_diff
}

@test "GitLab paths: case-sensitive" {
golden_file=$(realpath expected.gold)
to_temp xrefcheck -v -c config-gitlab.yaml

assert_diff expected.gold
assert_diff
}
51 changes: 6 additions & 45 deletions tests/golden/check-cli/check-cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,60 +42,21 @@ load '../helpers'
}

@test "Basic root, check errors report" {
golden_file=$(realpath expected1.gold)
to_temp xrefcheck --root .

assert_diff - <<EOF
=== Invalid references found ===
➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -
File does not exist:
one/two/three
Invalid references dumped, 1 in total.
EOF
assert_diff
}

@test "Root with redundant slashes, check errors report" {
golden_file=$(realpath expected2.gold)
to_temp xrefcheck --root ././///././././//./

assert_diff - <<EOF
=== Invalid references found ===
➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -
File does not exist:
one/two/three
Invalid references dumped, 1 in total.
EOF
assert_diff
}

@test "No root, check errors report" {
golden_file=$(realpath expected3.gold)
to_temp xrefcheck

assert_diff - <<EOF
=== Invalid references found ===
➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -
File does not exist:
one/two/three
Invalid references dumped, 1 in total.
EOF
assert_diff
}

@test "Single file as root" {
Expand Down
12 changes: 12 additions & 0 deletions tests/golden/check-cli/expected1.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Invalid references found ===

➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -

File does not exist:
one/two/three

Invalid references dumped, 1 in total.
12 changes: 12 additions & 0 deletions tests/golden/check-cli/expected2.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Invalid references found ===

➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -

File does not exist:
one/two/three

Invalid references dumped, 1 in total.
12 changes: 12 additions & 0 deletions tests/golden/check-cli/expected3.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Invalid references found ===

➥ In file to-ignore/broken-link.md
bad reference (absolute) at src:7:1-25:
- text: "my link"
- link: /one/two/three
- anchor: -

File does not exist:
one/two/three

Invalid references dumped, 1 in total.
Loading

0 comments on commit 671f527

Please sign in to comment.