Skip to content

Commit ef7ab23

Browse files
committed
Cleanup and fix C tests
1 parent 766ae8a commit ef7ab23

File tree

2 files changed

+54
-63
lines changed

2 files changed

+54
-63
lines changed

tmc-langs-make/src/main/java/fi/helsinki/cs/tmc/langs/make/CTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public CTestCase(String name, boolean passed, String message, List<String> point
4444
}
4545

4646
private boolean failedDueToValgrind(String valgrindTrace) {
47-
return failOnValgrindError && Strings.isNullOrEmpty(valgrindTrace);
47+
return failOnValgrindError && !Strings.isNullOrEmpty(valgrindTrace);
4848
}
4949

5050
/**

tmc-langs-make/src/test/java/fi/helsinki/cs/tmc/langs/make/CTestCaseTest.java

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,70 @@
66

77
import fi.helsinki.cs.tmc.langs.domain.TestResult;
88

9+
import com.google.common.collect.ImmutableList;
10+
911
import org.junit.Test;
1012

1113
import java.util.ArrayList;
12-
import java.util.List;
1314

1415
public class CTestCaseTest {
1516

16-
private CTestCase passing;
17-
private CTestCase failing;
18-
private CTestCase valgrindFail;
19-
private CTestCase bothFail;
20-
private CTestCase valgrindFailAllowed;
21-
22-
/**
23-
* Initializes variables used in tests.
24-
*/
25-
public CTestCaseTest() {
26-
List<String> points = new ArrayList<>();
27-
points.add("1.1");
28-
29-
this.passing = new CTestCase("test_passing", true, "", points);
30-
31-
this.failing =
32-
new CTestCase("test_failing", false, "Some tests failed", new ArrayList<String>());
33-
34-
this.valgrindFail = new CTestCase("test_valgrindFail", true, "", points);
35-
String valgrindTrace =
36-
"\n"
37-
+ "==20737== \n"
38-
+ "==20737== HEAP SUMMARY:\n"
39-
+ "==20737== in use at exit: 1,744 bytes in 31 blocks\n"
40-
+ "==20737== total heap usage: 46 allocs, 15 frees, 4,839 bytes "
41-
+ "allocated\n"
42-
+ "==20737== \n"
43-
+ "==20737== 32 bytes in 1 blocks are definitely lost in loss record "
44-
+ "27 of 31\n"
45-
+ "==20737== at 0x4C2AB80: malloc "
46-
+ "(in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\n"
47-
+ "==20737== by 0x4025A9: passing (source.c:11)\n"
48-
+ "==20737== by 0x401ADE: test_passing (test_source.c:14)\n"
49-
+ "==20737== by 0x405CC6: srunner_run "
50-
+ "(in /home/mession/Code/cprojects/Module_1/Task_1_4/test/test)\n"
51-
+ "==20737== by 0x401FAE: tmc_run_tests (tmc-check.c:122)\n"
52-
+ "==20737== by 0x401C71: main (test_source.c:35)\n"
53-
+ "==20737== \n"
54-
+ "==20737== LEAK SUMMARY:\n"
55-
+ "==20737== definitely lost: 32 bytes in 1 blocks\n"
56-
+ "==20737== indirectly lost: 0 bytes in 0 blocks\n"
57-
+ "==20737== possibly lost: 0 bytes in 0 blocks\n"
58-
+ "==20737== still reachable: 1,712 bytes in 30 blocks\n"
59-
+ "==20737== suppressed: 0 bytes in 0 blocks\n"
60-
+ "==20737== Reachable blocks (those to which a pointer was found) "
61-
+ "are not shown.\n"
62-
+ "==20737== To see them, rerun with: --leak-check=full "
63-
+ "--show-leak-kinds=all\n"
64-
+ "==20737== \n"
65-
+ "==20737== For counts of detected and suppressed errors, rerun with: -v\n"
66-
+ "==20737== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0"
67-
+ " from 0)";
68-
this.valgrindFail.setValgrindTrace(valgrindTrace);
69-
70-
this.bothFail = new CTestCase("test_bothFail", false, "Some tests failed", points);
71-
this.bothFail.setValgrindTrace(valgrindTrace);
72-
73-
this.valgrindFailAllowed =
74-
new CTestCase("test_valgrindFailAllowed", true, "", points, false);
75-
this.valgrindFailAllowed.setValgrindTrace(valgrindTrace);
17+
private static final ImmutableList<String> points = ImmutableList.of("1.1");
18+
19+
private static final CTestCase passing = new CTestCase("test_passing", true, "", points);
20+
private static final CTestCase failing = new CTestCase("test_failing", false, "Some tests failed", new ArrayList<String>());
21+
private static final CTestCase valgrindFail = new CTestCase("test_valgrindFail", true, "", points);
22+
private static final String valgrindTrace =
23+
"\n"
24+
+ "==20737== \n"
25+
+ "==20737== HEAP SUMMARY:\n"
26+
+ "==20737== in use at exit: 1,744 bytes in 31 blocks\n"
27+
+ "==20737== total heap usage: 46 allocs, 15 frees, 4,839 bytes "
28+
+ "allocated\n"
29+
+ "==20737== \n"
30+
+ "==20737== 32 bytes in 1 blocks are definitely lost in loss record "
31+
+ "27 of 31\n"
32+
+ "==20737== at 0x4C2AB80: malloc "
33+
+ "(in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\n"
34+
+ "==20737== by 0x4025A9: passing (source.c:11)\n"
35+
+ "==20737== by 0x401ADE: test_passing (test_source.c:14)\n"
36+
+ "==20737== by 0x405CC6: srunner_run "
37+
+ "(in /home/mession/Code/cprojects/Module_1/Task_1_4/test/test)\n"
38+
+ "==20737== by 0x401FAE: tmc_run_tests (tmc-check.c:122)\n"
39+
+ "==20737== by 0x401C71: main (test_source.c:35)\n"
40+
+ "==20737== \n"
41+
+ "==20737== LEAK SUMMARY:\n"
42+
+ "==20737== definitely lost: 32 bytes in 1 blocks\n"
43+
+ "==20737== indirectly lost: 0 bytes in 0 blocks\n"
44+
+ "==20737== possibly lost: 0 bytes in 0 blocks\n"
45+
+ "==20737== still reachable: 1,712 bytes in 30 blocks\n"
46+
+ "==20737== suppressed: 0 bytes in 0 blocks\n"
47+
+ "==20737== Reachable blocks (those to which a pointer was found) "
48+
+ "are not shown.\n"
49+
+ "==20737== To see them, rerun with: --leak-check=full "
50+
+ "--show-leak-kinds=all\n"
51+
+ "==20737== \n"
52+
+ "==20737== For counts of detected and suppressed errors, rerun with: -v\n"
53+
+ "==20737== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0"
54+
+ " from 0)";
55+
56+
57+
58+
59+
private static final CTestCase bothFail = new CTestCase("test_bothFail", false, "Some tests failed", points);
60+
private static final CTestCase valgrindFailAllowed = new CTestCase("test_valgrindFailAllowed", true, "", points, false);
61+
62+
63+
static {
64+
valgrindFail.setValgrindTrace(valgrindTrace);
65+
bothFail.setValgrindTrace(valgrindTrace);
66+
valgrindFailAllowed.setValgrindTrace(valgrindTrace);
7667
}
7768

7869
@Test
7970
public void testResultIsCorrectWithPassingTest() {
8071
TestResult testResult = this.passing.getTestResult();
81-
72+
System.out.println(this.passing.getTestResult());
8273
assertEquals("test_passing", testResult.getName());
8374
assertTrue(testResult.isSuccessful());
8475
assertEquals(1, testResult.points.size());

0 commit comments

Comments
 (0)