@@ -18,79 +18,36 @@ pub(crate) fn execute_testcases<P: AsRef<Path>>(
1818 CodeFile :: from_dir ( "." ) ?
1919 } ;
2020
21- match testcases {
21+ let eval_res = match testcases {
2222 Some ( testcases) => {
2323 let data_input = std:: fs:: read_to_string ( testcases) ?;
24-
25- match lc. execute ( & code_file, data_input) ? {
26- ExecutionResult :: Success ( result) => {
27- println ! ( "{}" , result) ;
28- return Ok ( ( result. is_correct ( ) , code_file) ) ;
29- }
30- ExecutionResult :: LimitExceeded ( limit_exceeded) => {
31- bail ! ( limit_exceeded) ; // TODO(nozwock): impl Display for these, so you can do `fail_state => bail!(fail_state),`
32- }
33- ExecutionResult :: CompileError ( compile_error) => {
34- bail ! ( compile_error) ;
35- }
36- ExecutionResult :: RuntimeError ( runtime_error) => {
37- bail ! ( runtime_error) ;
38- }
39- ExecutionResult :: PendingResult ( pending) => {
40- bail ! ( pending. state) ;
41- }
42- ExecutionResult :: WrongTestcase ( wrong_testcase) => bail ! ( wrong_testcase) ,
43- ExecutionResult :: Unknown ( _) => {
44- bail ! ( "Unknown" ) ;
45- }
46- }
24+ lc. execute ( & code_file, data_input)
25+ }
26+ None => lc. execute_default ( & code_file) ,
27+ } ?;
28+ match eval_res {
29+ ExecutionResult :: Success ( result) => {
30+ println ! ( "{}" , result) ;
31+ Ok ( ( result. is_correct ( ) , code_file) )
4732 }
48- None => match lc. execute_default ( & code_file) ? {
49- ExecutionResult :: Success ( result) => {
50- println ! ( "{}" , result) ;
51- return Ok ( ( result. is_correct ( ) , code_file) ) ;
52- }
53- ExecutionResult :: LimitExceeded ( limit_exceeded) => {
54- bail ! ( limit_exceeded) ;
55- }
56- ExecutionResult :: CompileError ( compile_error) => {
57- bail ! ( compile_error) ;
58- }
59- ExecutionResult :: RuntimeError ( runtime_error) => {
60- bail ! ( runtime_error) ;
61- }
62- ExecutionResult :: PendingResult ( pending) => {
63- bail ! ( pending. state) ;
64- }
65- ExecutionResult :: WrongTestcase ( wrong_testcase) => bail ! ( wrong_testcase) ,
66- ExecutionResult :: Unknown ( _) => {
67- bail ! ( "Unknown error" ) ;
68- }
69- } ,
33+ ExecutionResult :: LimitExceeded ( limit_exceeded) => bail ! ( limit_exceeded) ,
34+ ExecutionResult :: CompileError ( compile_error) => bail ! ( compile_error) ,
35+ ExecutionResult :: RuntimeError ( runtime_error) => bail ! ( runtime_error) ,
36+ ExecutionResult :: PendingResult ( pending) => bail ! ( pending. state) ,
37+ ExecutionResult :: WrongTestcase ( wrong_testcase) => bail ! ( wrong_testcase) ,
38+ ExecutionResult :: Unknown ( _) => bail ! ( "Unknown error occured" ) ,
7039 }
7140}
7241
7342pub ( crate ) fn submit ( lc : & LeetCode < Authorized > , code_file : CodeFile ) -> Result < ( ) > {
7443 match lc. submit ( & code_file) ? {
7544 SubmissionResult :: Success ( success) => println ! ( "{}" , success) ,
76- SubmissionResult :: LimitExceeded ( wrong) => {
77- bail ! ( wrong)
78- }
79- SubmissionResult :: PendingResult ( state) => {
80- bail ! ( state. state)
81- }
82- SubmissionResult :: CompileError ( compile_err) => {
83- bail ! ( compile_err)
84- }
85- SubmissionResult :: RuntimeError ( runtime_error) => {
86- bail ! ( runtime_error)
87- }
88- SubmissionResult :: Wrong ( wrong) => {
89- bail ! ( wrong)
90- }
91- SubmissionResult :: Unknown ( _) => {
92- bail ! ( "Unknown error" )
93- }
45+ SubmissionResult :: LimitExceeded ( wrong) => bail ! ( wrong) ,
46+ SubmissionResult :: PendingResult ( state) => bail ! ( state. state) ,
47+ SubmissionResult :: CompileError ( compile_err) => bail ! ( compile_err) ,
48+ SubmissionResult :: RuntimeError ( runtime_error) => bail ! ( runtime_error) ,
49+ SubmissionResult :: Wrong ( wrong) => bail ! ( wrong) ,
50+ SubmissionResult :: Unknown ( _) => bail ! ( "Unknown error" ) ,
9451 } ;
9552
9653 Ok ( ( ) )
0 commit comments