@@ -11,11 +11,11 @@ use std::io::{BufReader, Cursor, Read, Seek};
1111use std:: path:: { Path , PathBuf } ;
1212use std:: time:: Duration ;
1313use tmc_langs_framework:: {
14- command:: { OutputWithTimeout , TmcCommand } ,
14+ command:: TmcCommand ,
1515 domain:: {
1616 ExerciseDesc , RunResult , RunStatus , Strategy , TestDesc , TestResult , ValidationResult ,
1717 } ,
18- error:: FileIo ,
18+ error:: { CommandError , FileIo } ,
1919 io:: file_util,
2020 nom:: { bytes, character, combinator, sequence, IResult } ,
2121 plugin:: Language ,
@@ -160,12 +160,14 @@ impl LanguagePlugin for CSharpPlugin {
160160 file_util:: remove_file ( & exercise_desc_json_path) ?;
161161 }
162162
163- let mut command = TmcCommand :: new ( "dotnet" . to_string ( ) ) ;
164- command
165- . current_dir ( path)
166- . arg ( Self :: get_bootstrap_path ( ) ?)
167- . arg ( "--generate-points-file" ) ;
168- command. output_checked ( ) ?;
163+ let bootstrap_path = Self :: get_bootstrap_path ( ) ?;
164+ let _output = TmcCommand :: new_with_file_io ( "dotnet" ) ?
165+ . with ( |e| {
166+ e. cwd ( path)
167+ . arg ( bootstrap_path)
168+ . arg ( "--generate-points-file" )
169+ } )
170+ . output_checked ( ) ?;
169171
170172 let exercise_desc_json = file_util:: open_file ( & exercise_desc_json_path) ?;
171173 let json: HashMap < String , Vec < String > > =
@@ -193,30 +195,25 @@ impl LanguagePlugin for CSharpPlugin {
193195 file_util:: remove_file ( & test_results_path) ?;
194196 }
195197
196- let mut command = TmcCommand :: new ( "dotnet" . to_string ( ) ) ;
197- command
198- . current_dir ( path)
199- . arg ( Self :: get_bootstrap_path ( ) ?)
200- . arg ( "--run-tests" ) ;
198+ let bootstrap_path = Self :: get_bootstrap_path ( ) ?;
199+ let command = TmcCommand :: new_with_file_io ( "dotnet" ) ?
200+ . with ( |e| e. cwd ( path) . arg ( bootstrap_path) . arg ( "--run-tests" ) ) ;
201201 let output = if let Some ( timeout) = timeout {
202- command. wait_with_timeout ( timeout) ?
202+ command. output_with_timeout ( timeout)
203203 } else {
204- OutputWithTimeout :: Output ( command. output ( ) ? )
204+ command. output ( )
205205 } ;
206- log:: trace!( "stdout: {}" , String :: from_utf8_lossy( output. stdout( ) ) ) ;
207- log:: debug!( "stderr: {}" , String :: from_utf8_lossy( output. stderr( ) ) ) ;
208- let mut logs = HashMap :: new ( ) ;
209- logs. insert (
210- "stdout" . to_string ( ) ,
211- String :: from_utf8_lossy ( & output. stdout ( ) ) . into_owned ( ) ,
212- ) ;
213- logs. insert (
214- "stderr" . to_string ( ) ,
215- String :: from_utf8_lossy ( & output. stderr ( ) ) . into_owned ( ) ,
216- ) ;
217206
218207 match output {
219- OutputWithTimeout :: Output ( output) => {
208+ Ok ( output) => {
209+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
210+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
211+ log:: trace!( "stdout: {}" , stdout) ;
212+ log:: debug!( "stderr: {}" , stderr) ;
213+ let mut logs = HashMap :: new ( ) ;
214+ logs. insert ( "stdout" . to_string ( ) , stdout. into_owned ( ) ) ;
215+ logs. insert ( "stderr" . to_string ( ) , stderr. into_owned ( ) ) ;
216+
220217 if !output. status . success ( ) {
221218 return Ok ( RunResult {
222219 status : RunStatus :: CompileFailed ,
@@ -226,9 +223,13 @@ impl LanguagePlugin for CSharpPlugin {
226223 }
227224 Self :: parse_test_results ( & test_results_path, logs) . map_err ( |e| e. into ( ) )
228225 }
229- OutputWithTimeout :: Timeout { .. } => Ok ( RunResult {
230- status : RunStatus :: TestsFailed ,
231- test_results : vec ! [ TestResult {
226+ Err ( TmcError :: Command ( CommandError :: TimeOut { stdout, stderr, .. } ) ) => {
227+ let mut logs = HashMap :: new ( ) ;
228+ logs. insert ( "stdout" . to_string ( ) , stdout) ;
229+ logs. insert ( "stderr" . to_string ( ) , stderr) ;
230+ Ok ( RunResult {
231+ status : RunStatus :: TestsFailed ,
232+ test_results : vec ! [ TestResult {
232233 name: "Timeout test" . to_string( ) ,
233234 successful: false ,
234235 points: vec![ ] ,
@@ -237,8 +238,10 @@ impl LanguagePlugin for CSharpPlugin {
237238 . to_string( ) ,
238239 exception: vec![ ] ,
239240 } ] ,
240- logs,
241- } ) ,
241+ logs,
242+ } )
243+ }
244+ Err ( error) => Err ( error) ,
242245 }
243246 }
244247
0 commit comments