update
This commit is contained in:
parent
e16b92f526
commit
26ea87b295
2
req.yml
2
req.yml
|
|
@ -43,5 +43,5 @@ topics:
|
|||
The tool must be able to scan text files for requirement IDs and create a summary of the test status of the defined requirements.
|
||||
The IDs must be in one of the following formats, where <ID> is a placeholder for the real id:
|
||||
additional_info:
|
||||
- "<ID>: success"
|
||||
- "<ID>: passed"
|
||||
- "<ID>: failed"
|
||||
|
|
|
|||
71
src/main.rs
71
src/main.rs
|
|
@ -35,24 +35,17 @@ fn nl() -> String {
|
|||
|
||||
fn check_requirements(
|
||||
test_results: &str,
|
||||
output: &mut Vec<String>,
|
||||
output: &mut IndexMap<String, bool>,
|
||||
requirements: &IndexMap<String, Requirement>,
|
||||
allowed_requirements: &Regex,
|
||||
) {
|
||||
for (id, requirement) in requirements {
|
||||
for (id, _) in dbg!(requirements) {
|
||||
if allowed_requirements.is_match(id) {
|
||||
let status = if test_results.contains(&format!("{} succeeded", id.trim())) {
|
||||
":white_check_mark:"
|
||||
} else if test_results.contains(&format!("{} failed", id.trim())) {
|
||||
":x:"
|
||||
} else {
|
||||
":warning:"
|
||||
if test_results.contains(&format!("{}: failed", id.trim())) {
|
||||
output.insert(id.trim().to_string(), false);
|
||||
} else if test_results.contains(&format!("{}: passed", id.trim())) {
|
||||
output.entry(id.trim().to_string()).or_insert(true);
|
||||
};
|
||||
output.push(format!(
|
||||
"- _{}_ - {}: {status}",
|
||||
id.trim(),
|
||||
requirement.name
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,14 +65,14 @@ fn has_valid_topics(mut topics: Values<String, Topic>, allowed_requirements: &Re
|
|||
}
|
||||
|
||||
fn check_topics(
|
||||
test_results: &str,
|
||||
test_results: &[PathBuf],
|
||||
output: &mut Vec<String>,
|
||||
topics: &IndexMap<String, Topic>,
|
||||
allowed_requirements: &Regex,
|
||||
level: usize,
|
||||
) {
|
||||
) -> anyhow::Result<()> {
|
||||
if !has_valid_topics(topics.values(), allowed_requirements) {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
for (id, topic) in topics {
|
||||
if !has_valid_topics(topic.subtopics.values(), allowed_requirements)
|
||||
|
|
@ -93,15 +86,37 @@ fn check_topics(
|
|||
id.trim(),
|
||||
topic.name
|
||||
));
|
||||
|
||||
let mut test_status = IndexMap::new();
|
||||
for test_result in test_results {
|
||||
let test_result = std::fs::read_to_string(test_result)?;
|
||||
if !topic.requirements.is_empty() {
|
||||
check_requirements(
|
||||
&test_result,
|
||||
&mut test_status,
|
||||
&topic.requirements,
|
||||
allowed_requirements,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !topic.requirements.is_empty() {
|
||||
check_requirements(
|
||||
test_results,
|
||||
output,
|
||||
&topic.requirements,
|
||||
allowed_requirements,
|
||||
);
|
||||
for (id, req) in &topic.requirements {
|
||||
let status = if let Some(status) = test_status.get(id) {
|
||||
if *status {
|
||||
":white_check_mark:"
|
||||
} else {
|
||||
":x:"
|
||||
}
|
||||
} else {
|
||||
":warning:"
|
||||
};
|
||||
output.push(format!("- _{}_ - {}: {status}", id.trim(), req.name));
|
||||
}
|
||||
|
||||
output.push(nl());
|
||||
}
|
||||
|
||||
if !topic.subtopics.is_empty() {
|
||||
check_topics(
|
||||
test_results,
|
||||
|
|
@ -109,10 +124,11 @@ fn check_topics(
|
|||
&topic.subtopics,
|
||||
allowed_requirements,
|
||||
level + 1,
|
||||
);
|
||||
)?;
|
||||
output.push(nl());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_requirements(output: &mut Vec<String>, requirements: &IndexMap<String, Requirement>) {
|
||||
|
|
@ -171,12 +187,14 @@ enum Command {
|
|||
allowed_requirements: String,
|
||||
/// The path to the requirements file
|
||||
requirements: PathBuf,
|
||||
/// The path to the test output file
|
||||
test_results: PathBuf,
|
||||
/// The path to the test output files
|
||||
#[arg(required=true, num_args=1..)]
|
||||
test_results: Vec<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version)]
|
||||
struct Args {
|
||||
#[clap(subcommand)]
|
||||
command: Command,
|
||||
|
|
@ -297,10 +315,9 @@ fn main() -> anyhow::Result<()> {
|
|||
test_results,
|
||||
} => {
|
||||
let re = Regex::new(&allowed_requirements).unwrap();
|
||||
let test_results = std::fs::read_to_string(test_results)?;
|
||||
let project: Project = parse(&std::fs::read_to_string(requirements)?)?;
|
||||
let mut output = vec![format!("# Test Results - {}", project.name)];
|
||||
check_topics(&test_results, &mut output, &project.topics, &re, 2);
|
||||
check_topics(&test_results, &mut output, &project.topics, &re, 2)?;
|
||||
|
||||
let output = output.join("\n");
|
||||
println!("{output}");
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
REQ-1.1.1 succeeded
|
||||
REQ-1.2.1 succeeded
|
||||
REQ-1.2.2 failed
|
||||
REQ-2.1.1 succeeded
|
||||
REQ-2.1.2 succeeded
|
||||
REQ-2.1.3 failed
|
||||
REQ-2.2.1 succeeded
|
||||
REQ-2.2.2 succeeded
|
||||
REQ-2.2.3 failed
|
||||
REQ-3.1.1 succeeded
|
||||
REQ-3.1.2 succeeded
|
||||
REQ-3.1.3 failed
|
||||
REQ-3.1.4 succeeded
|
||||
REQ-3.2.1 succeeded
|
||||
REQ-3.2.2 failed
|
||||
REQ-3.2.3 succeeded
|
||||
REQ-1.1: passed
|
||||
REQ-1.2: passed
|
||||
REQ-3.1: passed
|
||||
REQ-3.2: passed
|
||||
REQ-3.3: failed
|
||||
|
|
|
|||
Loading…
Reference in New Issue