Skip to content

Commit

Permalink
generate tests according to .meta/tests.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Sep 9, 2023
1 parent 4d9fc34 commit 0d0ebaf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 21 additions & 0 deletions rust-tooling/src/exercise_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,24 @@ fn test_deserialize_all() {
.expect("should deserialize practice exercise config");
}
}

/// Returns the uuids of the tests excluded in .meta/tests.toml
pub fn get_excluded_tests(slug: &str) -> Vec<String> {
crate::fs_utils::cd_into_repo_root();
let path = std::path::PathBuf::from("exercises/practice")
.join(slug)
.join(".meta/tests.toml");
let contents = std::fs::read_to_string(&path).unwrap();

let mut excluded_tests = Vec::new();

// shitty toml parser
for case in contents.split("\n[").skip(1) {
let (uuid, rest) = case.split_once(']').unwrap();
if rest.contains("include = false") {
excluded_tests.push(uuid.to_string());
}
}

excluded_tests
}
12 changes: 8 additions & 4 deletions rust-tooling/src/exercise_generation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use convert_case::{Case, Casing};

use crate::problem_spec::{get_canonical_data, SingleTestCase, TestCase};
use crate::{problem_spec::{get_canonical_data, SingleTestCase, TestCase}, exercise_config::get_excluded_tests};

pub struct GeneratedExercise {
pub gitignore: String,
Expand All @@ -13,14 +13,14 @@ pub struct GeneratedExercise {

pub fn new(slug: &str) -> GeneratedExercise {
let crate_name = slug.replace('-', "_");
let canonical_data = get_canonical_data(slug);

GeneratedExercise {
gitignore: GITIGNORE.into(),
manifest: generate_manifest(&crate_name),
lib_rs: generate_lib_rs(&crate_name),
example: EXAMPLE_RS.into(),
test_header: generate_test_header(&crate_name),
test_cases: generate_tests(canonical_data.cases),
test_cases: generate_tests(slug),
}
}

Expand Down Expand Up @@ -105,9 +105,13 @@ fn generate_single_test_case(case: SingleTestCase, is_first: bool) -> String {
)
}

fn generate_tests(cases: Vec<TestCase>) -> String {
fn generate_tests(slug: &str) -> String {
let cases = get_canonical_data(slug).cases;
let excluded_tests = get_excluded_tests(slug);

let mut single_cases = Vec::new();
extend_single_cases(&mut single_cases, cases);
single_cases.retain(|case| !excluded_tests.contains(&case.uuid));

let mut buffer = String::new();

Expand Down

0 comments on commit 0d0ebaf

Please sign in to comment.