Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/resources/org/eolang/lints/tests/test-word.xsl
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>
26 changes: 26 additions & 0 deletions src/main/resources/org/eolang/motives/tests/test-word.md
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 > @
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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]
ignore-schema: true
document: |
<object author="tests">
<o line="1" name="foo-tests" pos="0">
<o line="3" name="+can-add" pos="2">
<o base="Q.number" line="4" name="φ" pos="4"/>
</o>
</o>
</object>
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'])=0]
ignore-schema: true
document: |
<object author="tests">
<o line="1" name="app" pos="0">
<o base="Q.org.testing" line="3" name="testing-helper" pos="2"/>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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='5']
ignore-schema: true
document: |
<object author="tests">
<o line="1" name="foo-tests" pos="0">
<o line="3" name="+can-setup" pos="2">
<o base="Q.number" line="5" name="tests-helper" pos="4"/>
</o>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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']
ignore-schema: true
document: |
<object author="tests">
<o line="1" name="foo-tests" pos="0">
<o line="3" name="+can-test-add" pos="2">
<o base="Q.number" line="4" name="φ" pos="4"/>
</o>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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='5']
ignore-schema: true
document: |
<object author="tests">
<o line="1" name="foo-tests" pos="0">
<o line="3" name="can-run" pos="2">
<o base="Q.number" line="5" name="tests-helper" pos="4"/>
</o>
</o>
</object>
Loading