|
6 | 6 |
|
7 | 7 | import fi.helsinki.cs.tmc.langs.domain.TestResult;
|
8 | 8 |
|
| 9 | +import com.google.common.collect.ImmutableList; |
| 10 | + |
9 | 11 | import org.junit.Test;
|
10 | 12 |
|
11 | 13 | import java.util.ArrayList;
|
12 |
| -import java.util.List; |
13 | 14 |
|
14 | 15 | public class CTestCaseTest {
|
15 | 16 |
|
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); |
76 | 67 | }
|
77 | 68 |
|
78 | 69 | @Test
|
79 | 70 | public void testResultIsCorrectWithPassingTest() {
|
80 | 71 | TestResult testResult = this.passing.getTestResult();
|
81 |
| - |
| 72 | + System.out.println(this.passing.getTestResult()); |
82 | 73 | assertEquals("test_passing", testResult.getName());
|
83 | 74 | assertTrue(testResult.isSuccessful());
|
84 | 75 | assertEquals(1, testResult.points.size());
|
|
0 commit comments