-
Notifications
You must be signed in to change notification settings - Fork 36
feat(#553): add test-word lint #1237
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
Open
VasilevNStas
wants to merge
3
commits into
objectionary:master
Choose a base branch
from
VasilevNStas:fix/issue-553-test-word
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| --> | ||
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="test-word" version="2.0"> | ||
| <xsl:import href="/org/eolang/funcs/lineno.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/escape.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/test-name.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/defect-context.xsl"/> | ||
| <xsl:output encoding="UTF-8" method="xml"/> | ||
| <xsl:template match="/"> | ||
| <defects> | ||
| <xsl:variable name="top" select="/object/o[1]"/> | ||
| <xsl:for-each select="//o[@name and not(@name='φ') and matches(@name, 'test', 'i') and not(generate-id() = generate-id($top))]"> | ||
| <xsl:if test="eo:test-name(@name) or ancestor::o[eo:test-name(@name)] or matches($top/@name, '-tests$')"> | ||
| <xsl:element name="defect"> | ||
| <xsl:variable name="line" select="eo:lineno(@line)"/> | ||
| <xsl:attribute name="line"> | ||
| <xsl:value-of select="$line"/> | ||
| </xsl:attribute> | ||
| <xsl:if test="$line = '0'"> | ||
| <xsl:attribute name="context"> | ||
| <xsl:value-of select="eo:defect-context(.)"/> | ||
| </xsl:attribute> | ||
| </xsl:if> | ||
| <xsl:attribute name="severity"> | ||
| <xsl:text>warning</xsl:text> | ||
| </xsl:attribute> | ||
| <xsl:text>The name of the object </xsl:text> | ||
| <xsl:value-of select="eo:escape(@name)"/> | ||
| <xsl:text> must not contain the word 'test'</xsl:text> | ||
| </xsl:element> | ||
| </xsl:if> | ||
| </xsl:for-each> | ||
| </defects> | ||
| </xsl:template> | ||
| </xsl:stylesheet> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Test word | ||
|
|
||
| Names of objects in test files must not contain the word 'test'. If an object | ||
| is a unit test, or a helper inside a unit test, or lives in a file whose top | ||
| object name ends with `-tests`, its name should describe the behavior it | ||
| verifies instead of repeating the word 'test'. | ||
|
|
||
| Incorrect: | ||
|
|
||
| ```eo | ||
| # Tests for foo. | ||
| [] > foo-tests | ||
| # Test. | ||
| [] +> can-test-add | ||
| 42 > @ | ||
| ``` | ||
|
|
||
| Correct: | ||
|
|
||
| ```eo | ||
| # Tests for foo. | ||
| [] > foo-tests | ||
| # Test. | ||
| [] +> can-add-two-and-two | ||
| 42 > @ | ||
| ``` |
12 changes: 12 additions & 0 deletions
12
src/test/resources/org/eolang/lints/packs/single/test-word/allows-clean-test-names.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/tests/test-word.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='warning'])=0] | ||
| input: | | ||
| [] > foo-tests | ||
|
|
||
| [] +> can-add | ||
| 42 > @ |
11 changes: 11 additions & 0 deletions
11
...resources/org/eolang/lints/packs/single/test-word/allows-test-word-in-regular-object.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/tests/test-word.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='warning'])=0] | ||
| input: | | ||
| [] > app | ||
| testing-helper > testing-helper | ||
| 42 > @ |
14 changes: 14 additions & 0 deletions
14
...test/resources/org/eolang/lints/packs/single/test-word/catches-test-in-nested-object.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/tests/test-word.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='warning'])=1] | ||
| - /defects/defect[@line='4'] | ||
| input: | | ||
| [] > foo-tests | ||
|
|
||
| [] +> can-setup | ||
| tests-helper > tests-helper | ||
| 42 > @ |
13 changes: 13 additions & 0 deletions
13
src/test/resources/org/eolang/lints/packs/single/test-word/catches-test-in-test-object.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/tests/test-word.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='warning'])=1] | ||
| - /defects/defect[@line='3'] | ||
| input: | | ||
| [] > foo-tests | ||
|
|
||
| [] +> can-test-add | ||
| 42 > @ |
14 changes: 14 additions & 0 deletions
14
src/test/resources/org/eolang/lints/packs/single/test-word/catches-test-word-in-helper.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/tests/test-word.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='warning'])=1] | ||
| - /defects/defect[@line='4'] | ||
| input: | | ||
| [] > foo-tests | ||
|
|
||
| [] > can-run | ||
| tests-helper > tests-helper | ||
| 42 > @ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.