objectionary / objectionary/lints
`bad-test-name` never checks `-`-prefixed throwing tests, so `[] -> it-works` passes while `[] +> it-works` is flagged
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 14
- Forks
- 39
- Avg merge
- 22h 54m
- Merged PRs (30d)
- 90
Description
What happens
bad-test-name.xsl selects test objects with an ad-hoc starts-with(@name, '+')
instead of the shared eo:test-name() function:
<xsl:for-each select="/object//o[starts-with(@name, '+')]">
<xsl:variable name="regexp" select="'^(can|cannot|accepts|rejects|stops-on)-'"/>
<xsl:if test="not(matches(eo:escape-plus(@name), $regexp))">
The EO parser marks a truthy test attribute (+> name) with a + prefix and a
throwing test attribute (-> name) with a - prefix. org/eolang/funcs/test-name.xsl
states that "Both kinds are tests":
<xsl:function name="eo:test-name" as="xs:boolean">
<xsl:param name="name"/>
<xsl:sequence select="starts-with($name, '+') or starts-with($name, '-')"/>
</xsl:function>
The motive of the lint says the rule applies to every unit test object:
Every unit test object must be named to describe the behavior it verifies, starting
with one of these prefixes:can-,cannot-,accepts-,rejects-, orstops-on-.
Because the for-each only sees +-prefixed names, a throwing test never reaches the
regexp and any name it carries is accepted. stops-on- in the allowed prefix list is
the idiomatic name for a throwing test, so the very objects that prefix targets are the
ones the rule skips.
test-name.xsl was introduced in f632e25 and used to replace starts-with(@name, '+')
in seven lints, including the sibling misc/incorrect-test-object-name.xsl.
bad-test-name.xsl was merged three hours earlier the same day (ca9cef9) and was not
part of that change, so it still carries the old check.
Steps to reproduce
truthy.eo:
[] > foo
[] > bar
[] +> it-works
throwing.eo, identical except for the test marker:
[] > foo
[] > bar
[] -> it-works
Run new Source(new EoSyntax(new InputOf(Paths.get(file))).parsed()).defects() on each
and filter for bad-test-name.
The parser produces name="+it-works" for the first file and name="-it-works" for the
second; the objects are otherwise identical.
Observed
truthy.eo:
[bad-test-name/S WARNING]:4 The name of the test object "+it-works" must start with one of the prefixes "can-,⌴cannot-,⌴accepts-,⌴rejects-,⌴stops-on-"
throwing.eo: no bad-test-name defect at all.
Expected behavior
bad-test-name should apply the prefix rule to throwing tests as well, so
[] -> it-works is reported just like [] +> it-works.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/resources/org/eolang/lints/tests/bad-test-name.xsl and compare its test-object selector with org/eolang/funcs/test-name.xsl and the sibling misc/incorrect-test-object-name.xsl. Run the Source(...).defects() reproduction for truthy.eo and throwing.eo; done when both test markers are checked and the throwing case reports bad-test-name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, xml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100