Skip to content

Commit ab383b5

Browse files
committed
impl error message for invalid testcases
1 parent 82f55ed commit ab383b5

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

src/handlers/execution.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub struct RuntimeError {
4949
pub std_output: Vec<String>,
5050
}
5151

52+
#[derive(Debug, Deserialize)]
53+
pub struct WrongTestcase {
54+
pub invalid_testcase: bool,
55+
pub runtime_error: String,
56+
}
57+
5258
#[derive(Debug, Deserialize)]
5359
pub struct LimitExceeded {
5460
pub status_code: u8,
@@ -69,6 +75,24 @@ pub struct LimitExceeded {
6975
pub state: String,
7076
}
7177

78+
impl fmt::Display for WrongTestcase {
79+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80+
let seperator = "-------------------------------";
81+
write!(
82+
f,
83+
"{}\n{}\n{}",
84+
if self.invalid_testcase {
85+
"Invalid Testcase!"
86+
} else {
87+
"Unknown Error!"
88+
}
89+
.red()
90+
.bold(),
91+
seperator.yellow(),
92+
self.runtime_error
93+
)
94+
}
95+
}
7296
impl fmt::Display for LimitExceeded {
7397
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7498
let seperator = "-------------------------------";

src/handlers/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum ExecutionResult {
2424
CompileError(CompileError),
2525
RuntimeError(RuntimeError),
2626
LimitExceeded(LimitExceeded),
27+
WrongTestcase(WrongTestcase),
2728
PendingResult(PendingResult),
2829
Unknown(Unknown),
2930
}

src/utils.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,34 @@ pub(crate) fn execute_testcases<P: AsRef<Path>>(
3939
ExecutionResult::PendingResult(pending) => {
4040
bail!(pending.state);
4141
}
42+
ExecutionResult::WrongTestcase(wrong_testcase) => bail!(wrong_testcase),
4243
ExecutionResult::Unknown(_) => {
4344
bail!("Unknown");
4445
}
4546
}
4647
}
47-
None => {
48-
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::Unknown(_) => {
66-
bail!("Unknown error");
67-
}
48+
None => match lc.execute_default(&code_file)? {
49+
ExecutionResult::Success(result) => {
50+
println!("{}", result);
51+
return Ok((result.is_correct(), code_file));
6852
}
69-
}
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+
},
7070
}
7171
}
7272

0 commit comments

Comments
 (0)