Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsmfm committed Jan 2, 2021
1 parent e4b457c commit 47ea611
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.3.0

- Consider xml structure `<testsuite><testcase file="./foo" time="0.1"></testcase></testsuite>` (e.g. rspec_junit_formatter)

## 0.2.0

- Make --tests-glob required
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "split-test"
version = "0.2.0"
version = "0.3.0"
authors = ["Fumiaki MATSUSHIMA <[email protected]>"]
edition = "2018"

Expand Down
78 changes: 68 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use quick_xml::de::from_reader;
use serde::Deserialize;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::fs::canonicalize;
use std::fs::File;
use std::io::BufReader;
Expand All @@ -29,15 +30,59 @@ struct Opt {
}

#[derive(Debug, Deserialize, PartialEq)]
struct Testsuites {
#[serde(rename = "testsuite", default)]
testsuites: Vec<Testsuite>,
struct TestResultXml {
#[serde(rename = "testsuite", alias = "testcase", default)]
test_results: Vec<TestResult>,
}

#[derive(Debug, Deserialize, PartialEq)]
struct Testsuite {
filepath: PathBuf,
struct TestResult {
#[serde(alias = "filepath", default)]
file: Option<PathBuf>,
time: f64,
#[serde(rename = "testsuite", alias = "testcase", default)]
test_results: Vec<TestResult>,
}

struct TestResultData {
file: Option<PathBuf>,
time: f64,
}

impl IntoIterator for TestResultXml {
type IntoIter = IntoIter;
type Item = TestResultData;

fn into_iter(self) -> Self::IntoIter {
IntoIter {
remaining: self.test_results.into_iter().collect(),
}
}
}

struct IntoIter {
remaining: VecDeque<TestResult>,
}

impl Iterator for IntoIter {
type Item = TestResultData;

fn next(&mut self) -> Option<Self::Item> {
self.remaining.pop_front().and_then(
|TestResult {
file,
time,
test_results,
}| {
self.remaining.extend(test_results);

Some(TestResultData {
file: file,
time: time,
})
},
)
}
}

struct Node<'a> {
Expand Down Expand Up @@ -80,14 +125,20 @@ fn get_test_file_results(

for xml_path in expand_globs(&vec![String::from(xml_glob)])? {
let reader = BufReader::new(File::open(xml_path)?);
let testsuites: Testsuites = from_reader(reader)?;

for suite in testsuites.testsuites {
let total_time = test_file_results.entry(suite.filepath).or_insert(0.0);
*total_time += suite.time;
let test_result_xml: TestResultXml = from_reader(reader)?;

for TestResultData { file, time } in test_result_xml {
file.map(|f| {
canonicalize(f).map(|normalized_file| {
let total_time = test_file_results.entry(normalized_file).or_insert(0.0);
*total_time += time;
})
});
}
}

debug!("{:?}", test_file_results);

Ok(test_file_results)
}

Expand Down Expand Up @@ -159,3 +210,10 @@ fn main() -> Result<()> {

Ok(())
}

/*
TODOS:
- Test <testsuites><testsuite file="/foo" time="0.1"></testsuite></testsuites>
- Test <testsuite><testcase file="./foo" time="0.1"></testcase></testsuite>
*/

0 comments on commit 47ea611

Please sign in to comment.