Skip to content

Commit 6f39bb6

Browse files
authored
bug(#632): wrong-test-order lint (#784)
* bug(#632): add wrong-test-order lint to enforce proper test placement in EO code * bug(#632): motive * bug(#632): disable depends on RUN_WORKFLOW * bug(#632): disable depends on RUN_WORKFLOW * ci: update java versions in maven workflow matrix and add exclusions * ci: remove extra spaces in java version matrix for consistency * ci: replace env with vars in workflow conditionals to use repository variables * empty commit to restart pipelines * ci: add cleanup step to remove eolang dependencies before maven build * ci: increase deep workflow timeout from 20 to 30 minutes * empty commit to restart pipelines
1 parent 7b2485d commit 6f39bb6

File tree

13 files changed

+156
-4
lines changed

13 files changed

+156
-4
lines changed

.github/workflows/deep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name: deep
1212
- master
1313
jobs:
1414
deep:
15-
timeout-minutes: 20
15+
timeout-minutes: 30
1616
runs-on: ubuntu-24.04
1717
steps:
1818
- uses: actions/checkout@v5

.github/workflows/hone.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ name: hone
1010
pull_request:
1111
branches:
1212
- master
13+
env:
14+
RUN_WORKFLOW: false
1315
jobs:
1416
hone:
1517
timeout-minutes: 45
@@ -19,7 +21,7 @@ jobs:
1921
# this issue: https://github.com/objectionary/hone-maven-plugin/issues/297. Also, the plugin run
2022
# is time-consuming, we should enable it only after the plugin will have stable execution time,
2123
# in order to not disturb the development in this repository.
22-
if: false
24+
if: ${{ vars.RUN_WORKFLOW == 'true' }}
2325
steps:
2426
- uses: actions/checkout@v5
2527
- uses: actions/setup-java@v5

.github/workflows/jmh.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ name: jmh
77
pull_request:
88
branches:
99
- master
10+
env:
11+
RUN_WORKFLOW: false
1012
jobs:
1113
jmh:
1214
timeout-minutes: 45
1315
runs-on: ubuntu-24.04
14-
if: false
16+
if: ${{ vars.RUN_WORKFLOW == 'true' }}
1517
steps:
1618
- name: Run JMH Benchmark Action
1719
uses: volodya-lombrozo/jmh-benchmark-action@v1

.github/workflows/mvn.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-24.04, windows-2022, macos-15]
19-
java: [11, 21]
19+
java: [17, 23]
20+
exclude:
21+
- os: windows-2022
22+
java: 17
23+
- os: macos-15
24+
java: 17
2025
runs-on: ${{ matrix.os }}
2126
steps:
2227
- uses: actions/checkout@v5
@@ -29,5 +34,8 @@ jobs:
2934
path: ~/.m2/repository
3035
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
3136
restore-keys: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-
37+
- uses: JesseTG/[email protected]
38+
with:
39+
path: ~/.m2/repository/org/eolang
3240
- run: mvn clean install -PskipITs --errors --batch-mode
3341
- run: mvn test --errors --batch-mode
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
4+
* SPDX-License-Identifier: MIT
5+
-->
6+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="wrong-test-order" version="2.0">
7+
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
8+
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
9+
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
10+
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
11+
<xsl:output encoding="UTF-8" method="xml"/>
12+
<xsl:template match="/">
13+
<defects>
14+
<xsl:for-each select="/object//o[starts-with(@name, '+')]">
15+
<xsl:variable name="next" select="following-sibling::*[1]"/>
16+
<xsl:if test="$next[self::o] and not(starts-with($next/@name, '+'))">
17+
<xsl:element name="defect">
18+
<xsl:variable name="line" select="eo:lineno(@line)"/>
19+
<xsl:attribute name="line">
20+
<xsl:value-of select="$line"/>
21+
</xsl:attribute>
22+
<xsl:if test="$line = '0'">
23+
<xsl:attribute name="context">
24+
<xsl:value-of select="eo:defect-context(.)"/>
25+
</xsl:attribute>
26+
</xsl:if>
27+
<xsl:attribute name="severity">
28+
<xsl:text>warning</xsl:text>
29+
</xsl:attribute>
30+
<xsl:text>The unit test wrongly ordered: </xsl:text>
31+
<xsl:value-of select="eo:escape(eo:escape-plus(@name))"/>
32+
</xsl:element>
33+
</xsl:if>
34+
</xsl:for-each>
35+
</defects>
36+
</xsl:template>
37+
</xsl:stylesheet>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Wrong test order
2+
3+
Unit tests must be located after live objects:
4+
5+
Incorrect:
6+
7+
```eo
8+
[] > foo
9+
[] +> runs-something
10+
[] > bar
11+
```
12+
13+
Correct:
14+
15+
```eo
16+
[] > foo
17+
[] > bar
18+
[] +> runs-something
19+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/tests/wrong-test-order.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=1]
8+
- /defects/defect[@line='3']
9+
input: |
10+
[] > foo
11+
[] > bar
12+
[] +> runs-program
13+
[] > boom
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/tests/wrong-test-order.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=0]
8+
input: |
9+
[] > foo
10+
[] > a
11+
[] > x
12+
[] > y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/tests/wrong-test-order.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=0]
8+
input: |
9+
[] > main
10+
[] +> testing
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/tests/wrong-test-order.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=0]
8+
input: |
9+
[] > at
10+
[] +> test
11+
[] +> another-test

0 commit comments

Comments
 (0)