22
22
import java .io .File ;
23
23
import java .util .Collection ;
24
24
import java .util .Collections ;
25
+ import java .util .List ;
25
26
import org .assertj .core .api .Assertions ;
26
27
import org .junit .Assert ;
27
28
import org .junit .jupiter .api .Test ;
29
+ import org .sonar .plugins .python .api .PythonCheck ;
28
30
import org .sonar .plugins .python .api .PythonSubscriptionCheck ;
29
31
import org .sonar .plugins .python .api .PythonVisitorContext ;
30
32
import org .sonar .python .SubscriptionVisitor ;
31
33
import org .sonar .python .TestPythonVisitorRunner ;
32
34
import org .sonar .python .checks .utils .PythonCheckVerifier ;
33
35
36
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
37
+
34
38
class FileHeaderCopyrightCheckTest {
35
39
36
40
@ Test
@@ -55,57 +59,63 @@ void test_noncompliant() {
55
59
void test_NoCopyright () {
56
60
PythonCheckVerifier .verifyNoIssue ("src/test/resources/checks/fileHeaderCopyright/headerNoCopyright.py" , new FileHeaderCopyrightCheck ());
57
61
PythonCheckVerifier .verifyNoIssue ("src/test/resources/checks/fileHeaderCopyright/emptyFileNoCopyright.py" , new FileHeaderCopyrightCheck ());
62
+ PythonCheckVerifier .verifyNoIssue ("src/test/resources/checks/fileHeaderCopyright/emptyFileWithLineBreakNoCopyright.py" , new FileHeaderCopyrightCheck ());
58
63
}
59
64
60
65
61
66
@ Test
62
67
void test_copyright_docstring () {
63
68
FileHeaderCopyrightCheck fileHeaderCopyrightCheck = new FileHeaderCopyrightCheck ();
64
- fileHeaderCopyrightCheck .headerFormat = "\" \" \" \n " +
65
- " SonarQube, open source software quality management tool.\n " +
66
- " Copyright (C) 2008-2018 SonarSource\n " +
67
- " mailto:contact AT sonarsource DOT com\n " +
68
- "\n " +
69
- " SonarQube is free software; you can redistribute it and/or\n " +
70
- " modify it under the terms of the GNU Lesser General Public\n " +
71
- " License as published by the Free Software Foundation; either\n " +
72
- " version 3 of the License, or (at your option) any later version.\n " +
73
- "\n " +
74
- " SonarQube is distributed in the hope that it will be useful,\n " +
75
- " but WITHOUT ANY WARRANTY; without even the implied warranty of\n " +
76
- " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n " +
77
- " Lesser General Public License for more details.\n " +
78
- "\n " +
79
- " You should have received a copy of the GNU Lesser General Public License\n " +
80
- " along with this program; if not, write to the Free Software Foundation,\n " +
81
- " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n " +
82
- "\" \" \" " ;
69
+ fileHeaderCopyrightCheck .headerFormat = """
70
+ ""\"
71
+ SonarQube, open source software quality management tool.
72
+ Copyright (C) 2008-2018 SonarSource
73
+ mailto:contact AT sonarsource DOT com
74
+
75
+ SonarQube is free software; you can redistribute it and/or
76
+ modify it under the terms of the GNU Lesser General Public
77
+ License as published by the Free Software Foundation; either
78
+ version 3 of the License, or (at your option) any later version.
79
+
80
+ SonarQube is distributed in the hope that it will be useful,
81
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83
+ Lesser General Public License for more details.
84
+
85
+ You should have received a copy of the GNU Lesser General Public License
86
+ along with this program; if not, write to the Free Software Foundation,
87
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
88
+ ""\"""" ;
83
89
PythonCheckVerifier .verifyNoIssue ("src/test/resources/checks/fileHeaderCopyright/docstring.py" , fileHeaderCopyrightCheck );
84
90
}
85
91
86
92
@ Test
87
93
void test_copyright_docstring_noncompliant () {
88
94
FileHeaderCopyrightCheck fileHeaderCopyrightCheck = new FileHeaderCopyrightCheck ();
89
- fileHeaderCopyrightCheck .headerFormat = "\" \" \" \n " +
90
- " SonarQube, open source software quality management tool.\n " +
91
- " Copyright (C) 2008-2018 SonarSource\n " +
92
- " mailto:contact AT sonarsource DOT com\n " +
93
- "\n " +
94
- " SonarQube is free software; you can redistribute it and/or\n " +
95
- " modify it under the terms of the GNU Lesser General Public\n " +
96
- " License as published by the Free Software Foundation; either\n " +
97
- " version 3 of the License, or (at your option) any later version.\n " +
98
- "\n " +
99
- " SonarQube is distributed in the hope that it will be useful,\n " +
100
- " but WITHOUT ANY WARRANTY; without even the implied warranty of\n " +
101
- " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n " +
102
- " Lesser General Public License for more details.\n " +
103
- "\n " +
104
- " You should have received a copy of the GNU Lesser General Public License\n " +
105
- " along with this program; if not, write to the Free Software Foundation,\n " +
106
- " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n " +
107
- "\" \" \" " ;
95
+ fileHeaderCopyrightCheck .headerFormat = """
96
+ ""\"
97
+ SonarQube, open source software quality management tool.
98
+ Copyright (C) 2008-2018 SonarSource
99
+ mailto:contact AT sonarsource DOT com
100
+
101
+ SonarQube is free software; you can redistribute it and/or
102
+ modify it under the terms of the GNU Lesser General Public
103
+ License as published by the Free Software Foundation; either
104
+ version 3 of the License, or (at your option) any later version.
105
+
106
+ SonarQube is distributed in the hope that it will be useful,
107
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
108
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109
+ Lesser General Public License for more details.
110
+
111
+ You should have received a copy of the GNU Lesser General Public License
112
+ along with this program; if not, write to the Free Software Foundation,
113
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
114
+ ""\"""" ;
108
115
PythonCheckVerifier .verify ("src/test/resources/checks/fileHeaderCopyright/docstringNonCompliant.py" , fileHeaderCopyrightCheck );
116
+
117
+ List <PythonCheck .PreciseIssue > issues = PythonCheckVerifier .issues ("src/test/resources/checks/fileHeaderCopyright/emptyFileNoCopyright.py" , fileHeaderCopyrightCheck );
118
+ assertEquals (1 , issues .size ());
109
119
}
110
120
111
121
@ Test
@@ -116,8 +126,10 @@ void test_searchPattern() {
116
126
PythonCheckVerifier .verify ("src/test/resources/checks/fileHeaderCopyright/copyrightNonCompliant.py" , fileHeaderCopyrightCheck );
117
127
PythonCheckVerifier .verify ("src/test/resources/checks/fileHeaderCopyright/searchPatternNonCompliant.py" , fileHeaderCopyrightCheck );
118
128
PythonCheckVerifier .verifyNoIssue ("src/test/resources/checks/fileHeaderCopyright/searchPattern.py" , fileHeaderCopyrightCheck );
119
- fileHeaderCopyrightCheck .headerFormat = "" ;
120
- PythonCheckVerifier .verify ("src/test/resources/checks/fileHeaderCopyright/searchPatternNonCompliant.py" , fileHeaderCopyrightCheck );
129
+
130
+ List <PythonCheck .PreciseIssue > issues = PythonCheckVerifier .issues ("src/test/resources/checks/fileHeaderCopyright/emptyFileNoCopyright.py" ,
131
+ fileHeaderCopyrightCheck );
132
+ assertEquals (1 , issues .size ());
121
133
}
122
134
123
135
@ Test
0 commit comments