Skip to content

Commit e5adb06

Browse files
nucularmood471061c
authored andcommitted
Fix issue with library linking when building windows
Fixed issue with library linking when building on Windows Fixed library linking issue and redundant folder spawning on Windows by disabling the default enabled debug_and_release debug_and_release_target CONFIG variable options. Windows compatibility for passing single lib same point Fixes to qtplugin Checkstyle fix
1 parent 49528dd commit e5adb06

File tree

51 files changed

+211
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+211
-136
lines changed

tmc-langs-qmake/src/main/java/fi/helsinki/cs/tmc/langs/qmake/QTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public final class QTestCase {
1616
/**
1717
* Create a test case for QT tests.
1818
*
19-
* @param name
20-
* @param passed
19+
* @param name Name of the test
20+
* @param passed Passed status
2121
* @param message for failed assertion
2222
* @param points for test case
2323
*/

tmc-langs-qmake/src/main/java/fi/helsinki/cs/tmc/langs/qmake/QTestResultParser.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ public final class QTestResultParser {
3838

3939
private static final Logger log = LoggerFactory.getLogger(QTestResultParser.class);
4040

41-
private final List<TestResult> tests;
41+
private List<TestResult> tests;
4242

43-
public QTestResultParser(Path testResults) {
44-
this.tests = parseTestCases(testResults);
43+
public QTestResultParser() {
4544
}
4645

46+
public void loadTests(Path testResult) {
47+
this.tests = parseTestCases(testResult);
48+
}
49+
4750
private List<TestResult> parseTestCases(Path testOutput) {
4851
Document doc;
4952
try {
@@ -93,7 +96,7 @@ private Document prepareDocument(Path testOutput)
9396

9497
/**
9598
* Parses Qt testlib XML output, as generated with -o filename.xml,xml.
96-
*
99+
* <p>
97100
* Points are mapped to test cases with Message node type 'qinfo'. These
98101
* messages contain: prefix "TMC:" test case name: "test_function_name"
99102
* points separated by period: ".1"
@@ -103,13 +106,15 @@ private Document prepareDocument(Path testOutput)
103106
*
104107
* When the testcase assertion(s) has passed, there will be an Incident node
105108
* with type "pass" and no Description node.
106-
*
109+
* </p>
107110
* <TestFunction name="test_function_name">
108111
* <Message type="qinfo" file="" line="0">
109112
* <Description><![CDATA[TMC:test_function_name.1]]></Description>
110113
* </Message>
111114
* <Incident type="fail" file="test_source.cpp" line="420">
112-
* <Description><![CDATA['!strcmp(hello_msg(), "Helo, world!" )' returned FALSE. ()]]></Description>
115+
* <Description>
116+
* <![CDATA['!strcmp(hello_msg(), "Helo, world!" )' returned FALSE. ()]]>
117+
* </Description>
113118
* </Incident>
114119
* <Duration msecs="0.135260"/>
115120
* </TestFunction>
@@ -147,31 +152,31 @@ private List<TestResult> createQtTestResults(NodeList nodeList) {
147152
}
148153

149154
/**
150-
*
155+
* <p>
151156
* Parse potential points from testcase.
152-
*
157+
* </p>
153158
*/
154159
private List<String> parsePoints(Element testcase) {
155160
List<String> points = new ArrayList<>();
156161
NodeList messages = testcase.getElementsByTagName("Message");
157162
for (int i = 0; i < messages.getLength(); i++) {
163+
// Convert node to element, messages.item(i) returns a node
158164
Element message = (Element) messages.item(i);
159165
Element desc = (Element) message.getElementsByTagName("Description").item(0);
160166
String text = desc.getTextContent();
161167
if (text.matches("^(TMC:.*)")) {
162168
String[] split = text.split("\\.");
163-
points.add(split[1]);
169+
String result = split[1];
170+
for (int j = 2; j < split.length; j++) {
171+
result += "." + split[j];
172+
}
173+
points.add(result);
164174
}
165175
}
166176

167177
return points;
168178
}
169179

170-
/**
171-
* Returns the test results of the tests in this file.
172-
*
173-
* @return
174-
*/
175180
public List<TestResult> getTestResults() {
176181
return this.tests;
177182
}
@@ -189,7 +194,7 @@ private Status getResultStatus() {
189194
/**
190195
* Returns the run result of this file.
191196
*
192-
* @return
197+
* @return Runresults
193198
*/
194199
public RunResult result() {
195200
return new RunResult(

tmc-langs-qmake/src/main/java/fi/helsinki/cs/tmc/langs/qmake/QmakePlugin.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ public final class QmakePlugin extends AbstractLanguagePlugin {
4949

5050
private static final Path TMC_TEST_RESULTS = Paths.get("tmc_test_results.xml");
5151

52-
// POINT(exercise_name, 1)
52+
// Finds pattern 'POINT(exercise_name, 1)'
5353
private static final Pattern POINT_PATTERN
5454
= Pattern.compile("POINT\\(\\s*(\\w+),\\s*(\\w+)\\s*\\)\\s*;");
55+
// Pattern to find comments
5556
private static final Pattern COMMENT_PATTERN
56-
= Pattern.compile("(^[^\"\\r\\n]*\\/\\*{1,2}.*?\\*\\/|(^[^\"\\r\\n]*\\/\\/[^\\r\\n]*))", Pattern.MULTILINE | Pattern.DOTALL);
57+
= Pattern.compile("(^[^\"\\r\\n]*\\/\\*{1,2}.*?\\*\\/"
58+
+ "|(^[^\"\\r\\n]*\\/\\/[^\\r\\n]*))", Pattern.MULTILINE | Pattern.DOTALL);
5759

5860
private static final RunResult EMPTY_FAILURE
5961
= new RunResult(
@@ -84,8 +86,7 @@ public String getPluginName() {
8486
* be named after the directory.
8587
*/
8688
private Path getProFile(Path basePath) {
87-
Path proFile = new File(basePath.toFile().getName() + ".pro").toPath();
88-
return basePath.resolve(proFile);
89+
return Paths.get(basePath.toString() + "/" + basePath.getFileName() + ".pro");
8990
}
9091

9192
@Override
@@ -115,7 +116,7 @@ public boolean isExerciseTypeCorrect(Path path) {
115116
* <p>
116117
* The project root path must be specified for the {@link StudentFilePolicy}
117118
* to read any configuration files such as <tt>.tmcproject.yml</tt>.
118-
*
119+
* </p>
119120
* @param projectPath The project's root path
120121
*/
121122
@Override
@@ -144,24 +145,25 @@ public RunResult runTests(Path path) {
144145
log.error("Failed to get test output at {}", testResults);
145146
return filledFailure(test.get());
146147
}
147-
148-
return new QTestResultParser(testResults).result();
148+
QTestResultParser parser = new QTestResultParser();
149+
parser.loadTests(testResults);
150+
return parser.result();
149151
}
150152

151153
return EMPTY_FAILURE;
152154
}
153155

154156
private Optional<RunResult> build(Path path) {
155-
Optional<RunResult> result = buildWithQmake(path);
156-
if (result.isPresent()) {
157+
Optional<RunResult> error = buildWithQmake(path);
158+
if (error.isPresent()) {
157159
log.warn("Failed to compile project with qmake");
158-
return result;
160+
return error;
159161
}
160162

161-
result = buildWithMake(path);
162-
if (result.isPresent()) {
163+
error = buildWithMake(path);
164+
if (error.isPresent()) {
163165
log.warn("Failed to compile project with make");
164-
return result;
166+
return error;
165167
}
166168

167169
return Optional.absent();
@@ -199,12 +201,12 @@ private Optional<RunResult> buildWithMake(Path dir) {
199201
return checkBuildResult(result);
200202
}
201203

202-
private Optional<RunResult> checkBuildResult(Optional<ProcessResult> result) {
203-
if (result.isPresent()) {
204-
if (result.get().statusCode == 0) {
204+
private Optional<RunResult> checkBuildResult(Optional<ProcessResult> error) {
205+
if (error.isPresent()) {
206+
if (error.get().statusCode == 0) {
205207
return Optional.absent();
206208
}
207-
return Optional.of(filledFailure(result.get()));
209+
return Optional.of(filledFailure(error.get()));
208210
}
209211
return Optional.of(EMPTY_FAILURE);
210212
}
@@ -216,7 +218,6 @@ public void clean(Path path) {
216218
log.info("Cleaned project");
217219
} else {
218220
log.warn("Cleaning project was not successful");
219-
220221
}
221222
}
222223

@@ -225,11 +226,12 @@ private Optional<ProcessResult> run(String[] command, Path dir) {
225226

226227
try {
227228
return Optional.of(runner.call());
228-
} catch (Exception e) {
229+
} catch (IOException | InterruptedException e) {
229230
log.error("Running command {} failed {}", Arrays.deepToString(command), e);
231+
return Optional.absent();
230232
}
231233

232-
return Optional.absent();
234+
233235
}
234236

235237
private RunResult filledFailure(ProcessResult processResult) {
@@ -244,13 +246,13 @@ private RunResult filledFailure(ProcessResult processResult) {
244246
/**
245247
* TODO: This is copy paste from tmc-langs regex branch. Regex branch method
246248
* 'availablePoints' does not parse test names at this time.
247-
*
249+
* <p>
248250
* POINT_PATTERN matches the #define macro in the tests, for example:
249251
*
250252
* POINT(test_name2, suite_point);
251253
*
252254
* POINT(test_name, 1);
253-
*
255+
* </p>
254256
* etc.
255257
*/
256258
public Optional<ImmutableList<TestDesc>> availablePoints(final Path rootPath) {
@@ -282,7 +284,6 @@ protected Optional<ImmutableList<TestDesc>> findAvailablePoints(final Path rootP
282284
}
283285
return Optional.of(ImmutableList.copyOf(descs));
284286
} catch (IOException e) {
285-
// We could scan the exercise but that could be a security risk
286287
return Optional.absent();
287288
}
288289
}

tmc-langs-qmake/src/test/java/fi/helsinki/cs/tmc/langs/qmake/QTestResultParserTest.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package fi.helsinki.cs.tmc.langs.qmake;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.junit.Assert.fail;
7+
38
import fi.helsinki.cs.tmc.langs.domain.RunResult;
49
import fi.helsinki.cs.tmc.langs.domain.TestResult;
510
import fi.helsinki.cs.tmc.langs.utils.TestUtils;
11+
12+
import org.junit.Test;
13+
614
import java.io.IOException;
715
import java.io.PrintWriter;
816
import java.nio.file.Path;
917
import java.util.ArrayList;
1018
import java.util.Arrays;
1119
import java.util.List;
12-
import org.junit.Test;
13-
import static org.junit.Assert.*;
1420

1521
public class QTestResultParserTest {
1622

@@ -20,14 +26,16 @@ public class QTestResultParserTest {
2026

2127
public QTestResultParserTest() {
2228
passing = new QTestCase("passing", true, "Passed", Arrays.asList(new String[]{"1"}));
23-
failing = new QTestCase("failing", false, "This test should've failed", Arrays.asList(new String[]{"2"}));
29+
failing = new QTestCase("failing", false, "This test should've failed",
30+
Arrays.asList(new String[]{"2"}));
2431
another = new QTestCase("another", true, "Passed", Arrays.asList(new String[]{"3"}));
2532
}
2633

2734
@Test(expected = IllegalStateException.class)
2835
public void testParsingWithNoTests() throws Exception {
29-
Path empty_test_output = TestUtils.initTempFileWithContent("empty_test_output", "xml", "");
30-
QTestResultParser qtparser = new QTestResultParser(empty_test_output);
36+
Path emptyTestOutput = TestUtils.initTempFileWithContent("empty_test_output", "xml", "");
37+
QTestResultParser qtparser = new QTestResultParser();
38+
qtparser.loadTests(emptyTestOutput);
3139
assertTrue(qtparser.getTestResults().isEmpty());
3240
}
3341

@@ -136,7 +144,10 @@ private QTestResultParser createResultParser(List<QTestCase> testCases) {
136144
} catch (Exception e) {
137145
fail("Error creating or parsing output file: " + e.getMessage());
138146
}
139-
return new QTestResultParser(testPath);
147+
QTestResultParser qtparser = new QTestResultParser();
148+
qtparser.loadTests(testPath);
149+
150+
return qtparser;
140151
}
141152

142153
private Path constructTestOutput(List<QTestCase> testCases) throws IOException {
@@ -148,7 +159,9 @@ private Path constructTestOutput(List<QTestCase> testCases) throws IOException {
148159
pw.println("<TestFunction name=\"" + t.getName() + "\">");
149160
for (String point : t.getPoints()) {
150161
pw.println("<Message type=\"qinfo\" file=\"\" line=\"0\">");
151-
pw.println("<Description><![CDATA[TMC:" + t.getName() + "." + point + "]]></Description>");
162+
pw.println("<Description><![CDATA[TMC:" + t.getName()
163+
+ "." + point
164+
+ "]]></Description>");
152165
pw.println("</Message>");
153166
}
154167

tmc-langs-qmake/src/test/java/fi/helsinki/cs/tmc/langs/qmake/QmakePluginTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package fi.helsinki.cs.tmc.langs.qmake;
22

3-
import com.google.common.base.Optional;
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
47
import fi.helsinki.cs.tmc.langs.domain.ExerciseDesc;
58
import fi.helsinki.cs.tmc.langs.domain.RunResult;
69
import fi.helsinki.cs.tmc.langs.utils.TestUtils;
710

11+
import com.google.common.base.Optional;
12+
813
import org.junit.Test;
914

1015
import java.nio.file.Path;
11-
import static org.junit.Assert.assertEquals;
12-
import static org.junit.Assert.assertFalse;
13-
import static org.junit.Assert.assertTrue;
16+
1417

1518
public class QmakePluginTest {
1619

tmc-langs-qmake/src/test/resources/failing_compile_single_lib_compiling/failing_compile_single_lib_compiling.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
#This additional CONFIG variable option will allow libraries
2-
#to be correctly linked when building projects using Windows.
3-
4-
win32 {
5-
CONFIG -= debug_and_release debug_and_release_target
6-
}
7-
81
TEMPLATE = subdirs
92
SUBDIRS += \
103
test_case_app \

tmc-langs-qmake/src/test/resources/failing_compile_single_lib_compiling/test_case_app/test_case_app.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ QT -= gui
33
CONFIG += c++11 console
44
CONFIG -= app_bundle
55

6+
win32 {
7+
CONFIG -= debug_and_release debug_and_release_target
8+
}
9+
610
DEFINES += QT_DEPRECATED_WARNINGS
711

812
SOURCES += main.cpp

tmc-langs-qmake/src/test/resources/failing_compile_single_lib_compiling/test_case_lib/test_case_lib.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ TARGET = test_case_lib
44
TEMPLATE = lib
55
CONFIG += staticlib
66

7+
win32 {
8+
CONFIG -= debug_and_release debug_and_release_target
9+
}
10+
711
DEFINES += QT_DEPRECATED_WARNINGS
812

913
SOURCES += \

tmc-langs-qmake/src/test/resources/failing_compile_single_lib_compiling/test_case_test_runner/test_case_test_runner.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ QT -= gui
44
CONFIG += c++11 console testcase
55
CONFIG -= app_bundle
66

7+
win32 {
8+
CONFIG -= debug_and_release debug_and_release_target
9+
}
10+
711
DEFINES += QT_DEPRECATED_WARNINGS
812

913
SOURCES += main.cpp \

tmc-langs-qmake/src/test/resources/failing_nolib/failing_nolib.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
#This additional CONFIG variable option will allow libraries
2-
#to be correctly linked when building projects using Windows.
3-
4-
win32 {
5-
CONFIG -= debug_and_release debug_and_release_target
6-
}
7-
81
TEMPLATE = subdirs
92
SUBDIRS += \
103
test_case_app \

0 commit comments

Comments
 (0)