Skip to content

Commit f8543d5

Browse files
committed
C# plugin
1 parent 707d6e7 commit f8543d5

File tree

22 files changed

+704
-1
lines changed

22 files changed

+704
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members =[
33
"tmc-langs-abstraction",
44
"tmc-langs-cli",
55
"tmc-langs-core",
6+
"tmc-langs-csharp",
67
"tmc-langs-framework",
78
"tmc-langs-java",
89
"tmc-langs-make",

tmc-langs-csharp/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "tmc-langs-csharp"
3+
version = "0.1.0"
4+
authors = ["Daniel Martinez <daniel.x.martinez@helsinki.fi>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
tmc-langs-framework = { path = "../tmc-langs-framework" }
9+
walkdir = "2"
10+
dirs = "3"
11+
thiserror = "1"
12+
zip = "0.5"
13+
serde_json = "1"
14+
log = "0.4"
15+
serde = { version = "1", features = ["derive"] }
16+
17+
[dev-dependencies]
18+
tempfile = "3"

tmc-langs-csharp/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Environment variables
2+
3+
| var name | usage |
4+
| --------------------------- | ----------------------------------------------------------------------------- |
5+
| `TMC_CSHARP_BOOTSTRAP_PATH` | Overrides the path to the TMC C# bootstrap's TestMyCode.CSharp.Bootstrap.dll. |

tmc-langs-csharp/src/error.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Error type for C#
2+
use std::path::PathBuf;
3+
use std::process::ExitStatus;
4+
use thiserror::Error;
5+
use tmc_langs_framework::TmcError;
6+
7+
#[derive(Debug, Error)]
8+
pub enum CSharpError {
9+
#[error("Failed to create file {0}")]
10+
CreateFile(PathBuf, #[source] std::io::Error),
11+
#[error("Failed to write file {0}")]
12+
WriteFile(PathBuf, #[source] std::io::Error),
13+
#[error("Failed to read file {0}")]
14+
ReadFile(PathBuf, #[source] std::io::Error),
15+
#[error("Failed to remove file {0}")]
16+
RemoveFile(PathBuf, #[source] std::io::Error),
17+
#[error("Failed to create dir {0}")]
18+
CreateDir(PathBuf, #[source] std::io::Error),
19+
#[error("Failed to remove dir {0}")]
20+
RemoveDir(PathBuf, #[source] std::io::Error),
21+
22+
#[error("Failed to parse exercise description at {0}")]
23+
ParseExerciseDesc(PathBuf, #[source] serde_json::Error),
24+
#[error("Failed to parse test results at {0}")]
25+
ParseTestResults(PathBuf, #[source] serde_json::Error),
26+
27+
#[error("Could not locate cache directory")]
28+
CacheDir,
29+
#[error("Could not locate boostrap DLL at {0}")]
30+
MissingBootstrapDll(PathBuf),
31+
#[error("Error while handling tmc-csharp-runner zip")]
32+
Zip(#[source] zip::result::ZipError),
33+
#[error("Failed to run {0}")]
34+
RunFailed(&'static str, #[source] std::io::Error),
35+
#[error("Command {0} failed with return code {1}")]
36+
CommandFailed(&'static str, ExitStatus),
37+
}
38+
39+
impl From<CSharpError> for TmcError {
40+
fn from(err: CSharpError) -> Self {
41+
Self::Plugin(Box::new(err))
42+
}
43+
}

tmc-langs-csharp/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Language plugin for C#
2+
mod error;
3+
mod plugin;
4+
5+
pub use error::CSharpError;
6+
pub use plugin::{CSharpPlugin, CSharpStudentFilePolicy};
7+
use tmc_langs_framework::domain::TestResult;
8+
9+
use serde::Deserialize;
10+
11+
#[derive(Debug, Deserialize)]
12+
#[serde(rename_all = "PascalCase")]
13+
struct CSTestResult {
14+
name: String,
15+
passed: bool,
16+
message: String,
17+
points: Vec<String>,
18+
error_stack_trace: Vec<String>,
19+
}
20+
21+
impl From<CSTestResult> for TestResult {
22+
fn from(test_result: CSTestResult) -> Self {
23+
TestResult {
24+
name: test_result.name,
25+
successful: test_result.passed,
26+
message: test_result.message,
27+
exception: test_result.error_stack_trace,
28+
points: test_result.points,
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)