Collect traces from last prop-test run on failure
This commit is contained in:
parent
d4069148c7
commit
0e0bed3c9d
|
@ -220,12 +220,18 @@ impl PropertyTest {
|
||||||
pub fn run<U>(self, seed: u32, n: usize) -> TestResult<U, PlutusData> {
|
pub fn run<U>(self, seed: u32, n: usize) -> TestResult<U, PlutusData> {
|
||||||
let mut labels = BTreeMap::new();
|
let mut labels = BTreeMap::new();
|
||||||
|
|
||||||
let (counterexample, iterations) =
|
let (traces, counterexample, iterations) =
|
||||||
match self.run_n_times(n, Prng::from_seed(seed), None, &mut labels) {
|
match self.run_n_times(n, Prng::from_seed(seed), None, &mut labels) {
|
||||||
None => (None, n),
|
None => (Vec::new(), None, n),
|
||||||
Some((remaining, counterexample)) => {
|
Some((remaining, counterexample)) => (
|
||||||
(Some(counterexample.value), n - remaining + 1)
|
self.eval(&counterexample.value)
|
||||||
}
|
.logs()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|s| PropertyTest::extract_label(s).is_none())
|
||||||
|
.collect(),
|
||||||
|
Some(counterexample.value),
|
||||||
|
n - remaining + 1,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
TestResult::PropertyTestResult(PropertyTestResult {
|
TestResult::PropertyTestResult(PropertyTestResult {
|
||||||
|
@ -233,6 +239,7 @@ impl PropertyTest {
|
||||||
counterexample,
|
counterexample,
|
||||||
iterations,
|
iterations,
|
||||||
labels,
|
labels,
|
||||||
|
traces,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,13 +276,13 @@ impl PropertyTest {
|
||||||
|
|
||||||
let mut result = self.eval(&value);
|
let mut result = self.eval(&value);
|
||||||
|
|
||||||
for label in result.logs() {
|
for s in result.logs() {
|
||||||
// NOTE: There may be other log outputs that interefere with labels. So *by
|
// NOTE: There may be other log outputs that interefere with labels. So *by
|
||||||
// convention*, we treat as label strings that starts with a NUL byte, which
|
// convention*, we treat as label strings that starts with a NUL byte, which
|
||||||
// should be a guard sufficient to prevent inadvertent clashes.
|
// should be a guard sufficient to prevent inadvertent clashes.
|
||||||
if label.starts_with('\0') {
|
if let Some(label) = PropertyTest::extract_label(&s) {
|
||||||
labels
|
labels
|
||||||
.entry(label.split_at(1).1.to_string())
|
.entry(label)
|
||||||
.and_modify(|count| *count += 1)
|
.and_modify(|count| *count += 1)
|
||||||
.or_insert(1);
|
.or_insert(1);
|
||||||
}
|
}
|
||||||
|
@ -327,6 +334,14 @@ impl PropertyTest {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.eval(ExBudget::max())
|
.eval(ExBudget::max())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_label(s: &str) -> Option<String> {
|
||||||
|
if s.starts_with('\0') {
|
||||||
|
Some(s.split_at(1).1.to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----- PRNG -----------------------------------------------------------------
|
/// ----- PRNG -----------------------------------------------------------------
|
||||||
|
@ -830,8 +845,10 @@ impl<U, T> TestResult<U, T> {
|
||||||
|
|
||||||
pub fn traces(&self) -> &[String] {
|
pub fn traces(&self) -> &[String] {
|
||||||
match self {
|
match self {
|
||||||
TestResult::UnitTestResult(UnitTestResult { ref traces, .. }) => traces.as_slice(),
|
TestResult::UnitTestResult(UnitTestResult { ref traces, .. })
|
||||||
TestResult::PropertyTestResult(..) => &[],
|
| TestResult::PropertyTestResult(PropertyTestResult { ref traces, .. }) => {
|
||||||
|
traces.as_slice()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,6 +926,7 @@ pub struct PropertyTestResult<T> {
|
||||||
pub counterexample: Option<T>,
|
pub counterexample: Option<T>,
|
||||||
pub iterations: usize,
|
pub iterations: usize,
|
||||||
pub labels: BTreeMap<String, usize>,
|
pub labels: BTreeMap<String, usize>,
|
||||||
|
pub traces: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T> Send for PropertyTestResult<T> {}
|
unsafe impl<T> Send for PropertyTestResult<T> {}
|
||||||
|
@ -926,6 +944,7 @@ impl PropertyTestResult<PlutusData> {
|
||||||
iterations: self.iterations,
|
iterations: self.iterations,
|
||||||
test: self.test,
|
test: self.test,
|
||||||
labels: self.labels,
|
labels: self.labels,
|
||||||
|
traces: self.traces,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue