Skip to content

Commit

Permalink
[#165] Add tests for local references
Browse files Browse the repository at this point in the history
Problem: We want all cases of local references to be covered by bats tests
(e.g. cause we want to be sure that all this works well on Windows),
but there was only one case covered in `check-anchors`

Solution: make a `check-local-refs` folder and test different
types of links  with different roots
  • Loading branch information
Sorokin-Anton committed Oct 4, 2022
1 parent 12003cc commit 9b70282
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 32 deletions.
30 changes: 0 additions & 30 deletions tests/golden/check-anchors/check-anchors.bats

This file was deleted.

23 changes: 23 additions & 0 deletions tests/golden/check-local-refs/check-local-refs.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: MPL-2.0

load '../helpers/bats-support/load'
load '../helpers/bats-assert/load'
load '../helpers/bats-file/load'
load '../helpers'


@test "Checking local references, root = \".\"" {
to_temp xrefcheck

assert_diff expected1.gold
}

@test "Checking local references, root = \"dir1\"" {
to_temp xrefcheck -r dir1

assert_diff expected2.gold
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- SPDX-License-Identifier: MPL-2.0
-->

# File with no anchors
# Existing anchor d1f1
35 changes: 35 additions & 0 deletions tests/golden/check-local-refs/dir1/dir2/d2f1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
-
- SPDX-License-Identifier: MPL-2.0
-->

# Current file links
[existing-cf-ref](#current-file-links)
[bad-cf-ref](#bad)

# Relative links
[existing-file-rel](d2f2.md)
[existing-file-rel](./d2f2.md)
[existing-file-rel](../dir2/.././d1f1.md)


[existing-anchor-rel-1](d2f2.md#existing-anchor-d2f2)
[existing-anchor-rel-2](./d2f2.md#existing-anchor-d2f2)
[existing-anchor-rel-3](../dir2/../d1f1.md#existing-anchor-d1f1)

[bad-file-rel](../a/b/c/unexisting-file.md)

[bad-anchor-rel-1](d2f2.md#bad-anchor)
[bad-anchor-rel-2](unexisting-file.md#bad-anchor)

# Absolute links
Should be correct when root is `/tests/golden/check-local-refs`:
[file-abs-1](/dir1/./d1f1.md)
[anchor-abs-1](/dir1/.././d1f1.md#existing-anchor-d1f1)
[anchor-abs-2](/dir1/dir2/../../dir1/./dir2/d2f2.md#existing-anchor-d2f2)
Should be correct when root is `/tests/golden/check-local-refs/dir1`:
[file-abs-2](/d1f1.md)
[file-abs-3](/dir2/d2f2.md)
[file-abs-4](/./dir2/../d1f1.md)
[anchor-abs-3](/./dir2/../d1f1.md#existing-anchor-d1f1)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- SPDX-License-Identifier: MPL-2.0
-->

[no-anchor](no-anchor.md#invalid-anchor)
# Existing anchor d2f2
91 changes: 91 additions & 0 deletions tests/golden/check-local-refs/expected1.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=== Invalid references found ===

➥ In file dir1/dir2/d2f1.md
bad reference (current file) at src:9:1-18:
- text: "bad-cf-ref"
- link:
- anchor: bad

⛀ Anchor 'bad' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:21:1-43:
- text: "bad-file-rel"
- link: ../a/b/c/unexisting-file.md
- anchor: -

⛀ File does not exist:
dir1/dir2/../a/b/c/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:23:1-38:
- text: "bad-anchor-rel-1"
- link: d2f2.md
- anchor: bad-anchor

⛀ Anchor 'bad-anchor' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:24:1-49:
- text: "bad-anchor-rel-2"
- link: unexisting-file.md
- anchor: bad-anchor

⛀ File does not exist:
dir1/dir2/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:29:1-55:
- text: "anchor-abs-1"
- link: /dir1/.././d1f1.md
- anchor: existing-anchor-d1f1

⛀ File does not exist:
./dir1/.././d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:32:1-22:
- text: "file-abs-2"
- link: /d1f1.md
- anchor: -

⛀ File does not exist:
./d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:33:1-27:
- text: "file-abs-3"
- link: /dir2/d2f2.md
- anchor: -

⛀ File does not exist:
./dir2/d2f2.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:34:1-32:
- text: "file-abs-4"
- link: /./dir2/../d1f1.md
- anchor: -

⛀ File does not exist:
././dir2/../d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:35:1-55:
- text: "anchor-abs-3"
- link: /./dir2/../d1f1.md
- anchor: existing-anchor-d1f1

⛀ File does not exist:
././dir2/../d1f1.md


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

➥ In file dir1/dir2/d2f1.md
bad reference (current file) at src:9:1-18:
- text: "bad-cf-ref"
- link:
- anchor: bad

⛀ Anchor 'bad' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:21:1-43:
- text: "bad-file-rel"
- link: ../a/b/c/unexisting-file.md
- anchor: -

⛀ File does not exist:
dir1/dir2/../a/b/c/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:23:1-38:
- text: "bad-anchor-rel-1"
- link: d2f2.md
- anchor: bad-anchor

⛀ Anchor 'bad-anchor' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:24:1-49:
- text: "bad-anchor-rel-2"
- link: unexisting-file.md
- anchor: bad-anchor

⛀ File does not exist:
dir1/dir2/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:28:1-29:
- text: "file-abs-1"
- link: /dir1/./d1f1.md
- anchor: -

⛀ File does not exist:
dir1/dir1/./d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:29:1-55:
- text: "anchor-abs-1"
- link: /dir1/.././d1f1.md
- anchor: existing-anchor-d1f1

⛀ File does not exist:
dir1/dir1/.././d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:30:1-73:
- text: "anchor-abs-2"
- link: /dir1/dir2/../../dir1/./dir2/d2f2.md
- anchor: existing-anchor-d2f2

⛀ File does not exist:
dir1/dir1/dir2/../../dir1/./dir2/d2f2.md


Invalid references dumped, 7 in total.

0 comments on commit 9b70282

Please sign in to comment.