/
GnuMakeGccParserTest.java
183 lines (159 loc) · 7.49 KB
/
GnuMakeGccParserTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package edu.hm.hafner.analysis.parser;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import org.junit.jupiter.api.Test;
import edu.hm.hafner.analysis.AbstractIssueParserTest;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Priority;
import edu.hm.hafner.analysis.assertj.SoftAssertions;
import static edu.hm.hafner.analysis.assertj.SoftAssertions.*;
/**
* Tests the class {@link GnuMakeGccParser}.
*
* @author vichak
*/
@SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion")
class GnuMakeGccParserTest extends AbstractIssueParserTest {
private static final String WARNING_CATEGORY = "Warning";
private static final String ERROR_CATEGORY = "Error";
GnuMakeGccParserTest() {
super("gnuMakeGcc.txt");
}
/**
* Checks that the root of the path is not changed on non-windows systems.
*/
@Test
void checkCorrectPathNonWindows() {
checkOsSpecificPath("Ubuntu", "/c");
}
/**
* Checks that the root of the path is fixed if it is unix-type while running on windows.
*/
@Test
void checkCorrectPathWindows() {
checkOsSpecificPath("Windows NT", "c:");
}
/**
* Checks that paths of the type "/c/anything" are changed to "c:/anything" on windows but no other OS.
*/
private void checkOsSpecificPath(final String os, final String rootDir) {
Report warnings = new GnuMakeGccParser(os).parse(getDefaultFile(), StandardCharsets.UTF_8);
assertSoftly(softly -> {
softly.assertThat(warnings.get(14))
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(20)
.hasLineEnd(20)
.hasMessage("I'm warning you! He's got huge, sharp... er... He can leap about.")
.hasFileName(rootDir + "/dir5/grail.cpp");
});
}
@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
Iterator<Issue> iterator = report.iterator();
softly.assertThat(report).hasSize(15);
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(451)
.hasLineEnd(451)
.hasMessage("'void yyunput(int, char*)' defined but not used")
.hasFileName("/dir1/testhist.l");
softly.assertThat(iterator.next())
.hasPriority(Priority.HIGH)
.hasCategory(ERROR_CATEGORY)
.hasLineStart(73)
.hasLineEnd(73)
.hasMessage("implicit typename is deprecated, please see the documentation for details")
.hasFileName("/u1/drjohn/bfdist/packages/RegrTest/V00-03-01/RgtAddressLineScan.cc");
softly.assertThat(iterator.next())
.hasPriority(Priority.HIGH)
.hasCategory(ERROR_CATEGORY)
.hasLineStart(4)
.hasLineEnd(4)
.hasMessage("foo.h: No such file or directory")
.hasFileName("/dir1/foo.cc");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(678)
.hasLineEnd(678)
.hasMessage("missing initializer for member sigaltstack::ss_sp")
.hasFileName("/dir1/../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(678)
.hasLineEnd(678)
.hasMessage("missing initializer for member sigaltstack::ss_flags")
.hasFileName("/dir1/../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(678)
.hasLineEnd(678)
.hasMessage("missing initializer for member sigaltstack::ss_size")
.hasFileName("/dir1/../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(52)
.hasLineEnd(52)
.hasMessage("large integer implicitly truncated to unsigned type")
.hasFileName("/dir1/src/test_simple_sgs_message.cxx");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(352)
.hasLineEnd(352)
.hasMessage("'s2.mepSector2::lubrications' may be used uninitialized in this function")
.hasFileName("/dir1/dir2/main/mep.cpp");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(6)
.hasLineEnd(6)
.hasMessage("passing 'Test' chooses 'int' over 'unsigned int'")
.hasFileName("/dir1/dir2/warnings.cc");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(6)
.hasLineEnd(6)
.hasMessage("in call to 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]'")
.hasFileName("/dir1/dir2/warnings.cc");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(33)
.hasLineEnd(33)
.hasMessage("#warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.")
.hasFileName("/usr/include/c++/4.3/backward/backward_warning.h");
softly.assertThat(iterator.next())
.hasPriority(Priority.HIGH)
.hasCategory(ERROR_CATEGORY)
.hasLineStart(8)
.hasLineEnd(8)
.hasMessage("'bar' was not declared in this scope")
.hasFileName("/dir1/dir2/dir3/fo:oo.cpp");
softly.assertThat(iterator.next())
.hasPriority(Priority.HIGH)
.hasCategory(ERROR_CATEGORY)
.hasLineStart(12)
.hasLineEnd(12)
.hasMessage("expected ';' before 'return'")
.hasFileName("/dir1/dir2/dir3/fo:oo.cpp");
softly.assertThat(iterator.next())
.hasPriority(Priority.NORMAL)
.hasCategory(WARNING_CATEGORY)
.hasLineStart(5)
.hasLineEnd(5)
.hasMessage("Your code is bad, and you should feel bad!")
.hasFileName("/dir4/zoidberg.c");
}
@Override
protected GnuMakeGccParser createParser() {
return new GnuMakeGccParser();
}
}