Skip to content

Commit d3837bc

Browse files
committed
fixes to the parser in framework and notests plugin
1 parent ba54438 commit d3837bc

File tree

11 files changed

+137
-43
lines changed

11 files changed

+137
-43
lines changed

plugins/csharp/src/plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tmc_langs_framework::{
1717
},
1818
error::{CommandError, FileIo},
1919
file_util,
20-
nom::{bytes, character, combinator, sequence, IResult},
20+
nom::{bytes, character, combinator, error::VerboseError, sequence, IResult},
2121
plugin::Language,
2222
zip::ZipArchive,
2323
LanguagePlugin, TmcError,
@@ -353,7 +353,7 @@ impl LanguagePlugin for CSharpPlugin {
353353
vec![PathBuf::from("test")]
354354
}
355355

356-
fn points_parser(i: &str) -> IResult<&str, &str> {
356+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
357357
combinator::map(
358358
sequence::delimited(
359359
sequence::tuple((

plugins/java/src/ant_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tmc_langs_framework::{
1414
command::TmcCommand,
1515
domain::{ExerciseDesc, RunResult, StyleValidationResult},
1616
file_util,
17-
nom::IResult,
17+
nom::{error::VerboseError, IResult},
1818
plugin::{Language, LanguagePlugin},
1919
TmcError,
2020
};
@@ -126,7 +126,7 @@ impl LanguagePlugin for AntPlugin {
126126
Ok(())
127127
}
128128

129-
fn points_parser(i: &str) -> IResult<&str, &str> {
129+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
130130
Self::java_points_parser(i)
131131
}
132132

plugins/java/src/java_plugin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tmc_langs_framework::{
1111
command::TmcCommand,
1212
domain::{ExerciseDesc, RunResult, RunStatus, StyleValidationResult, TestDesc, TestResult},
1313
file_util,
14-
nom::{bytes, character, combinator, sequence, IResult},
14+
nom::{bytes, character, combinator, error::VerboseError, sequence, IResult},
1515
plugin::{Language, LanguagePlugin},
1616
};
1717
use walkdir::WalkDir;
@@ -254,7 +254,7 @@ pub(crate) trait JavaPlugin: LanguagePlugin {
254254
}
255255

256256
/// Parses @Points("1.1") point annotations.
257-
fn java_points_parser(i: &str) -> IResult<&str, &str> {
257+
fn java_points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
258258
combinator::map(
259259
sequence::delimited(
260260
sequence::tuple((
@@ -363,7 +363,7 @@ mod test {
363363
unimplemented!()
364364
}
365365

366-
fn points_parser<'a>(i: &'a str) -> IResult<&'a str, &'a str> {
366+
fn points_parser(i: &str) -> IResult<&str, &str, nom::error::VerboseError<&str>> {
367367
Self::java_points_parser(i)
368368
}
369369
}

plugins/java/src/maven_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tmc_langs_framework::{
1616
command::TmcCommand,
1717
domain::{ExerciseDesc, RunResult, StyleValidationResult},
1818
file_util,
19-
nom::IResult,
19+
nom::{error::VerboseError, IResult},
2020
plugin::{Language, LanguagePlugin},
2121
TmcError,
2222
};
@@ -133,7 +133,7 @@ impl LanguagePlugin for MavenPlugin {
133133
vec![PathBuf::from("src/test")]
134134
}
135135

136-
fn points_parser(i: &str) -> IResult<&str, &str> {
136+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
137137
Self::java_points_parser(i)
138138
}
139139
}

plugins/make/src/plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tmc_langs_framework::{
1616
domain::{ExerciseDesc, RunResult, RunStatus, TestDesc},
1717
error::{CommandError, FileIo},
1818
file_util,
19-
nom::{bytes, character, combinator, sequence, IResult},
19+
nom::{bytes, character, combinator, error::VerboseError, sequence, IResult},
2020
plugin::LanguagePlugin,
2121
subprocess::PopenError,
2222
zip::ZipArchive,
@@ -348,7 +348,7 @@ impl LanguagePlugin for MakePlugin {
348348
vec![PathBuf::from("test")]
349349
}
350350

351-
fn points_parser(i: &str) -> IResult<&str, &str> {
351+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
352352
combinator::map(
353353
sequence::delimited(
354354
sequence::tuple((

plugins/notests/src/plugin.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88
use tmc_langs_framework::{
99
anyhow,
1010
domain::{ExerciseDesc, RunResult, RunStatus, TestDesc, TestResult},
11-
nom::IResult,
11+
nom::{self, error::VerboseError, IResult},
1212
zip::ZipArchive,
1313
LanguagePlugin, StudentFilePolicy, TmcError,
1414
};
@@ -102,8 +102,9 @@ impl LanguagePlugin for NoTestsPlugin {
102102
vec![PathBuf::from("test")]
103103
}
104104

105-
fn points_parser(_: &str) -> IResult<&str, &str> {
106-
Ok(("", ""))
105+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
106+
// does not match any characters
107+
nom::combinator::value("", nom::character::complete::one_of(""))(i)
107108
}
108109
}
109110

@@ -228,4 +229,26 @@ no-tests: false
228229
);
229230
assert!(!NoTestsPlugin::is_exercise_type_correct(temp_dir.path()));
230231
}
232+
233+
#[test]
234+
fn parses_empty() {
235+
init();
236+
237+
let temp = tempfile::tempdir().unwrap();
238+
file_to(&temp, "test/.keep", r#""#);
239+
240+
let points = NoTestsPlugin::get_available_points(temp.path()).unwrap();
241+
assert!(points.is_empty());
242+
243+
let temp = tempfile::tempdir().unwrap();
244+
file_to(
245+
&temp,
246+
"test/.keep",
247+
r#"
248+
"#,
249+
);
250+
251+
let points = NoTestsPlugin::get_available_points(temp.path()).unwrap();
252+
assert!(points.is_empty());
253+
}
231254
}

plugins/python3/src/plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tmc_langs_framework::{
1515
domain::{ExerciseDesc, RunResult, RunStatus, TestDesc, TestResult},
1616
error::CommandError,
1717
file_util,
18-
nom::{branch, bytes, character, combinator, sequence, IResult},
18+
nom::{branch, bytes, character, combinator, error::VerboseError, sequence, IResult},
1919
plugin::LanguagePlugin,
2020
TmcError, TmcProjectYml,
2121
};
@@ -334,7 +334,7 @@ impl LanguagePlugin for Python3Plugin {
334334
vec![PathBuf::from("test"), PathBuf::from("tmc")]
335335
}
336336

337-
fn points_parser(i: &str) -> IResult<&str, &str> {
337+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
338338
combinator::map(
339339
sequence::delimited(
340340
sequence::tuple((

plugins/r/src/plugin.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tmc_langs_framework::{
1313
command::TmcCommand,
1414
domain::{ExerciseDesc, RunResult, TestDesc},
1515
file_util,
16-
nom::{bytes, character, combinator, sequence, IResult},
16+
nom::{bytes, character, combinator, error::VerboseError, sequence, IResult},
1717
zip::ZipArchive,
1818
LanguagePlugin, TmcError,
1919
};
@@ -151,7 +151,7 @@ impl LanguagePlugin for RPlugin {
151151
vec![PathBuf::from("tests")]
152152
}
153153

154-
fn points_parser(i: &str) -> IResult<&str, &str> {
154+
fn points_parser(i: &str) -> IResult<&str, &str, VerboseError<&str>> {
155155
combinator::map(
156156
sequence::delimited(
157157
sequence::tuple((
@@ -475,4 +475,23 @@ test("sample", c("r1.1"), {
475475
"#;
476476
assert_eq!(RPlugin::points_parser(target).unwrap().1, "W1A.1.2");
477477
}
478+
479+
#[test]
480+
fn parsing_regression_test() {
481+
init();
482+
483+
let temp = tempfile::tempdir().unwrap();
484+
file_to(
485+
&temp,
486+
"tests/testthat/testExercise.R",
487+
r#"library('testthat')
488+
"#,
489+
);
490+
491+
let res = RPlugin::get_available_points(temp.path());
492+
if let Err(TmcError::PointParse(_, e)) = res {
493+
log::info!("{:#}", e);
494+
}
495+
panic!()
496+
}
478497
}

tmc-langs-framework/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ serde_yaml = "0.8"
1717
zip = "0.5"
1818
schemars = "0.8"
1919
once_cell = "1"
20-
nom = "6"
20+
nom = { version = "6", features = ["alloc"] }
2121
funty = "=1.1.0" # temporary workaround, remove later
2222
subprocess = "0.2"
2323
tempfile = "3"

tmc-langs-framework/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub enum TmcError {
2727
Canonicalize(PathBuf, #[source] std::io::Error),
2828
#[error("File {0} not in given project root {1}")]
2929
FileNotInProject(PathBuf, PathBuf),
30-
#[error("Error while parsing available points: {0}")]
31-
PointParse(String),
30+
#[error("Error while parsing available points from {0}")]
31+
PointParse(PathBuf, #[source] nom::error::VerboseError<String>),
3232

3333
#[error("Path {0} contained no file name")]
3434
NoFileName(PathBuf),

0 commit comments

Comments
 (0)