Skip to content

Commit 2a843c0

Browse files
devarsh-mavaniromani
authored andcommitted
Issue #13345: Enabled example tests for TrailingCommentCheck
1 parent 3015216 commit 2a843c0

File tree

9 files changed

+113
-68
lines changed

9 files changed

+113
-68
lines changed

src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckExamplesTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
package com.puppycrawl.tools.checkstyle.checks;
2121

22-
import org.junit.jupiter.api.Disabled;
22+
import static com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck.MSG_KEY;
23+
2324
import org.junit.jupiter.api.Test;
2425

2526
import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
2627

27-
@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
2828
public class TrailingCommentCheckExamplesTest extends AbstractExamplesModuleTestSupport {
2929
@Override
3030
protected String getPackageLocation() {
@@ -34,36 +34,37 @@ protected String getPackageLocation() {
3434
@Test
3535
public void testExample1() throws Exception {
3636
final String[] expected = {
37-
37+
"17:16: " + getCheckMessage(MSG_KEY),
3838
};
3939

40-
verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
40+
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
4141
}
4242

4343
@Test
4444
public void testExample2() throws Exception {
4545
final String[] expected = {
46-
46+
"21:16: " + getCheckMessage(MSG_KEY),
47+
"24:8: " + getCheckMessage(MSG_KEY),
4748
};
4849

49-
verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
50+
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
5051
}
5152

5253
@Test
5354
public void testExample3() throws Exception {
5455
final String[] expected = {
55-
56+
"22:10: " + getCheckMessage(MSG_KEY),
5657
};
5758

58-
verifyWithInlineConfigParser(getPath("Example3.txt"), expected);
59+
verifyWithInlineConfigParser(getPath("Example3.java"), expected);
5960
}
6061

6162
@Test
6263
public void testExample4() throws Exception {
6364
final String[] expected = {
64-
65+
"25:10: " + getCheckMessage(MSG_KEY),
6566
};
6667

67-
verifyWithInlineConfigParser(getPath("Example4.txt"), expected);
68+
verifyWithInlineConfigParser(getPath("Example4.java"), expected);
6869
}
6970
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="TrailingComment"/>
5+
</module>
6+
</module>
7+
*/
8+
9+
package com.puppycrawl.tools.checkstyle.checks.trailingcomment;
10+
11+
// xdoc section -- start
12+
public class Example1 {
13+
public static void main(String[] args) {
14+
int x = 10;
15+
// OK
16+
if (/* OK */ x > 5) {}
17+
int a = 5; // violation
18+
doSomething(
19+
"param1"
20+
); // OK, by default such trailing of method/code-block ending is allowed
21+
22+
}
23+
24+
private static void doSomething(String param) {
25+
}
26+
}
27+
// xdoc section -- end

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example1.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="TrailingComment">
5+
<property name="format" value="^\s*$"/>
6+
</module>
7+
</module>
8+
</module>
9+
*/
10+
11+
package com.puppycrawl.tools.checkstyle.checks.trailingcomment;
12+
13+
import java.util.Random;
14+
15+
// xdoc section -- start
16+
public class Example2 {
17+
public static void main(String[] args) {
18+
int x = new Random().nextInt(100);
19+
// OK
20+
if (/* OK, this comment does not end the line */ x > 5) {}
21+
int a = 5; // violation, line content before comment should match pattern "^\s*$"
22+
doSomething(
23+
"param1"
24+
); // violation, line content before comment should match pattern "^\s*$"
25+
}
26+
27+
private static void doSomething(String param) {
28+
}
29+
}
30+
// xdoc section -- end

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example2.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.txt renamed to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
</module>
1313
*/
1414

15+
package com.puppycrawl.tools.checkstyle.checks.trailingcomment;
16+
1517
// xdoc section -- start
16-
public class Test {
18+
public class Example3 {
1719
int a; // SUPPRESS CHECKSTYLE
1820
int b; // NOPMD
1921
int c; // NOSONAR

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.txt renamed to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
</module>
1616
*/
1717

18+
package com.puppycrawl.tools.checkstyle.checks.trailingcomment;
19+
1820
// xdoc section -- start
19-
public class Test {
21+
public class Example4 {
2022
int a; // SUPPRESS CHECKSTYLE - OK, comment starts with " SUPPRESS CHECKSTYLE"
2123
int b; // NOPMD - OK, comment starts with " NOPMD"
2224
int c; // NOSONAR - OK, comment starts with " NOSONAR"

src/xdocs/checks/misc/trailingcomment.xml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,21 @@ d = e / f; // Another comment for this line
115115
Example:
116116
</p>
117117
<source>
118-
// OK
119-
if (/* OK */ x &gt; 5) {}
120-
int a = 5; // violation
121-
doSomething(
122-
param1
123-
); // OK, by default such trailing of method/code-block ending is allowed
118+
public class Example1 {
119+
public static void main(String[] args) {
120+
int x = 10;
121+
// OK
122+
if (/* OK */ x &gt; 5) {}
123+
int a = 5; // violation
124+
doSomething(
125+
&quot;param1&quot;
126+
); // OK, by default such trailing of method/code-block ending is allowed
127+
128+
}
129+
130+
private static void doSomething(String param) {
131+
}
132+
}
124133
</source>
125134

126135
<p id="Example2-config">
@@ -140,12 +149,20 @@ doSomething(
140149
Example:
141150
</p>
142151
<source>
143-
// OK
144-
if (/* OK, this comment does not end the line */ x &gt; 5) {}
145-
int a = 5; // violation, line content before comment should match pattern &quot;^\s*$&quot;
146-
doSomething(
147-
param1
148-
); // violation, line content before comment should match pattern &quot;^\s*$&quot;
152+
public class Example2 {
153+
public static void main(String[] args) {
154+
int x = new Random().nextInt(100);
155+
// OK
156+
if (/* OK, this comment does not end the line */ x &gt; 5) {}
157+
int a = 5; // violation, line content before comment should match pattern &quot;^\s*$&quot;
158+
doSomething(
159+
&quot;param1&quot;
160+
); // violation, line content before comment should match pattern &quot;^\s*$&quot;
161+
}
162+
163+
private static void doSomething(String param) {
164+
}
165+
}
149166
</source>
150167

151168
<p id="Example3-config">
@@ -171,7 +188,7 @@ doSomething(
171188
Example for trailing comments check to suppress specific trailing comment:
172189
</p>
173190
<source>
174-
public class Test {
191+
public class Example3 {
175192
int a; // SUPPRESS CHECKSTYLE
176193
int b; // NOPMD
177194
int c; // NOSONAR
@@ -204,7 +221,7 @@ public class Test {
204221
Example:
205222
</p>
206223
<source>
207-
public class Test {
224+
public class Example4 {
208225
int a; // SUPPRESS CHECKSTYLE - OK, comment starts with &quot; SUPPRESS CHECKSTYLE&quot;
209226
int b; // NOPMD - OK, comment starts with &quot; NOPMD&quot;
210227
int c; // NOSONAR - OK, comment starts with &quot; NOSONAR&quot;

src/xdocs/checks/misc/trailingcomment.xml.template

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ d = e / f; // Another comment for this line
8686
</p>
8787
<macro name="example">
8888
<param name="path"
89-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example1.txt"/>
89+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example1.java"/>
9090
<param name="type" value="config"/>
9191
</macro>
9292

@@ -95,7 +95,7 @@ d = e / f; // Another comment for this line
9595
</p>
9696
<macro name="example">
9797
<param name="path"
98-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example1.txt"/>
98+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example1.java"/>
9999
<param name="type" value="code"/>
100100
</macro>
101101

@@ -104,7 +104,7 @@ d = e / f; // Another comment for this line
104104
</p>
105105
<macro name="example">
106106
<param name="path"
107-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example2.txt"/>
107+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example2.java"/>
108108
<param name="type" value="config"/>
109109
</macro>
110110

@@ -113,7 +113,7 @@ d = e / f; // Another comment for this line
113113
</p>
114114
<macro name="example">
115115
<param name="path"
116-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example2.txt"/>
116+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example2.java"/>
117117
<param name="type" value="code"/>
118118
</macro>
119119

@@ -124,7 +124,7 @@ d = e / f; // Another comment for this line
124124
</p>
125125
<macro name="example">
126126
<param name="path"
127-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.txt"/>
127+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.java"/>
128128
<param name="type" value="config"/>
129129
</macro>
130130

@@ -133,7 +133,7 @@ d = e / f; // Another comment for this line
133133
</p>
134134
<macro name="example">
135135
<param name="path"
136-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.txt"/>
136+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example3.java"/>
137137
<param name="type" value="code"/>
138138
</macro>
139139

@@ -143,7 +143,7 @@ d = e / f; // Another comment for this line
143143
</p>
144144
<macro name="example">
145145
<param name="path"
146-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.txt"/>
146+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.java"/>
147147
<param name="type" value="config"/>
148148
</macro>
149149

@@ -152,7 +152,7 @@ d = e / f; // Another comment for this line
152152
</p>
153153
<macro name="example">
154154
<param name="path"
155-
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.txt"/>
155+
value="resources/com/puppycrawl/tools/checkstyle/checks/trailingcomment/Example4.java"/>
156156
<param name="type" value="code"/>
157157
</macro>
158158

0 commit comments

Comments
 (0)