4
4
import fi .helsinki .cs .tmc .data .TestRunResult ;
5
5
import fi .helsinki .cs .tmc .model .TmcProjectInfo ;
6
6
import fi .helsinki .cs .tmc .model .UserVisibleException ;
7
- import fi .helsinki .cs .tmc .utilities .BgTask ;
8
- import fi .helsinki .cs .tmc .utilities .BgTaskListener ;
9
7
import fi .helsinki .cs .tmc .utilities .process .ProcessResult ;
10
8
import fi .helsinki .cs .tmc .utilities .process .ProcessRunner ;
11
9
import java .io .File ;
12
10
import java .io .IOException ;
13
11
import java .util .Arrays ;
14
12
import java .util .concurrent .Callable ;
15
13
import java .util .logging .Level ;
16
- import static java .util .logging .Level .INFO ;
17
- import static java .util .logging .Level .WARNING ;
18
14
import java .util .logging .Logger ;
19
15
import org .netbeans .api .project .Project ;
20
16
import org .openide .filesystems .FileObject ;
@@ -26,52 +22,48 @@ public class MakefileExerciseRunner extends AbstractExerciseRunner {
26
22
private static final Logger log = Logger .getLogger (MakefileExerciseRunner .class .getName ());
27
23
28
24
@ Override
29
- public Callable <Integer > getCompilingTask (TmcProjectInfo projectInfo ) {
30
- log .log (Level .INFO , "Compiling project {0}" , projectInfo .getProjectName ());
31
- Project project = projectInfo .getProject ();
32
- FileObject makeFile = project .getProjectDirectory ().getFileObject ("Makefile" );
33
- File workDir = projectInfo .getProjectDirAsFile ();
34
-
35
- if (makeFile == null ) {
36
- log .log (INFO , "Project has no Makefile" );
37
- throw new RuntimeException ("Project has no Makefile" );
38
- }
39
- String [] command = {"make" , "test" };
40
-
25
+ public Callable <TestRunResult > getTestRunningTask (final TmcProjectInfo projectInfo ) {
41
26
final InputOutput io = IOProvider .getDefault ().getIO (projectInfo .getProjectName (), false );
42
- final ProcessRunner runner = new ProcessRunner ( command , workDir , io );
43
- return new Callable <Integer >() {
27
+
28
+ return new Callable <TestRunResult >() {
44
29
@ Override
45
- public Integer call () throws Exception {
30
+ public TestRunResult call () throws Exception {
31
+ log .log (Level .INFO , "Compiling project {0}" , projectInfo .getProjectName ());
32
+ Project project = projectInfo .getProject ();
33
+ FileObject makeFile = project .getProjectDirectory ().getFileObject ("Makefile" );
34
+
35
+ if (makeFile == null ) {
36
+ log .info ("Project has no Makefile" );
37
+ throw new RuntimeException ("Project has no Makefile" );
38
+ }
39
+
40
+ File workDir = projectInfo .getProjectDirAsFile ();
41
+ String [] command = {"make" , "test" };
42
+
43
+ final ProcessRunner runner = new ProcessRunner (command , workDir , io );
44
+
46
45
try {
47
46
ProcessResult result = runner .call ();
48
47
int ret = result .statusCode ;
49
48
if (ret != 0 ) {
50
49
io .select ();
50
+ log .log (Level .INFO , "Compile resulted in non-zero exit code {0}" , result .statusCode );
51
+ return new TestRunResult (false );
51
52
}
52
- return ret ;
53
+
54
+ log .info ("Running tests" );
55
+ return runTests (projectInfo , true );
53
56
} catch (Exception ex ) {
54
- log .log (INFO , "Compilation failed, {0}" , ex .getMessage ());
55
57
io .select ();
56
58
throw ex ;
57
59
}
58
60
}
59
61
};
60
62
}
61
63
62
- @ Override
63
- public Callable <TestRunResult > getTestRunningTask (final TmcProjectInfo projectInfo ) {
64
- return new Callable <TestRunResult >() {
65
- @ Override
66
- public TestRunResult call () throws Exception {
67
- return runTests (projectInfo , true );
68
- }
69
- };
70
- }
71
-
72
64
// TODO: use make
73
65
private TestRunResult runTests (final TmcProjectInfo projectInfo , final boolean withValgrind ) throws Exception {
74
- log .log (INFO , "Running tests {0}" , projectInfo .getProjectName ());
66
+ log .log (Level . INFO , "Running tests {0}" , projectInfo .getProjectName ());
75
67
final File testDir = projectInfo .getProjectDirAsFile ();
76
68
String [] command ;
77
69
@@ -83,7 +75,7 @@ private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean w
83
75
command = new String []{testDir .getAbsolutePath ()
84
76
+ File .separatorChar + "test" + File .separatorChar + "test" };
85
77
}
86
- log .log (INFO , "Running tests for project {0} with command {1}" ,
78
+ log .log (Level . INFO , "Running tests for project {0} with command {1}" ,
87
79
new Object []{projectInfo .getProjectName (), Arrays .deepToString (command )});
88
80
89
81
ProcessRunner runner = new ProcessRunner (command , testDir , IOProvider .getDefault ()
@@ -94,11 +86,11 @@ private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean w
94
86
runner .call ();
95
87
log .info ("Running tests completed" );
96
88
} catch (IOException e ) {
97
- log .log (INFO , "IOException while running tests, kinda wanted. {0}" , e .getMessage ());
89
+ log .log (Level . INFO , "IOException while running tests, kinda wanted. {0}" , e .getMessage ());
98
90
if (withValgrind ) {
99
91
return runTests (projectInfo , false );
100
92
} else {
101
- log .log (WARNING , "Failed to run tests for project: \" {0}\" with command: \" {1}\" .\n \" {2}\" " ,
93
+ log .log (Level . WARNING , "Failed to run tests for project: \" {0}\" with command: \" {1}\" .\n \" {2}\" " ,
102
94
new Object []{projectInfo .getProjectName (), Arrays .deepToString (command ), e .getMessage ()});
103
95
throw new UserVisibleException ("Failed to run tests:\n " + e .getMessage ());
104
96
}
@@ -111,10 +103,10 @@ private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean w
111
103
Exercise exercise = projectMediator .tryGetExerciseForProject (projectInfo , courseDb );
112
104
113
105
if (exercise != null ) {
114
- log .log (INFO , "Parsing exercises with valgrind strategy {0}" , exercise .getValgrindStrategy ());
106
+ log .log (Level . INFO , "Parsing exercises with valgrind strategy {0}" , exercise .getValgrindStrategy ());
115
107
return resultParser .parseCTestResults (resultsFile , valgrindLog , exercise .getValgrindStrategy ());
116
108
} else {
117
- log .log (INFO , "Parsing exercises with out valgrind strategy" );
109
+ log .log (Level . INFO , "Parsing exercises with out valgrind strategy" );
118
110
return resultParser .parseCTestResults (resultsFile , valgrindLog , null );
119
111
}
120
112
}
0 commit comments