-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from paxosglobal/jard-inc-runs
read positive outcomes file and filter mutants
- Loading branch information
Showing
6 changed files
with
79 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
// Copyright 2023 Paxos | ||
|
||
//! Logic for incremantal runs | ||
use crate::{ | ||
mutate::{Mutant, MutantHash}, | ||
options::Options, | ||
output::{PositiveOutcome, OUTDIR_NAME, POSITIVE_OUTCOMES_FILE}, | ||
}; | ||
use anyhow::{anyhow, Result}; | ||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use std::{collections::HashSet, fs}; | ||
|
||
use crate::{mutate::Mutant, output::PositiveOutcomes}; | ||
|
||
pub fn filter(mutants: Vec<Mutant>) -> (Option<PositiveOutcomes>, Vec<Mutant>) { | ||
let last_positive_outcomes = read_last_positive_outcomes(); | ||
// TODO Exclude mutants whose hash is in the last positive outcomes | ||
let mutants = mutants.into_iter().filter(|m| todo!()); | ||
|
||
(last_positive_outcomes, mutants.collect()) | ||
pub fn filter_by_last_positive_outcomes( | ||
mutants: Vec<Mutant>, | ||
dir: &Utf8PathBuf, | ||
options: &Options, | ||
) -> (Option<Vec<PositiveOutcome>>, Vec<Mutant>) { | ||
let read_path: &Utf8Path = options.output_in_dir.as_ref().map_or(dir, |p| p.as_path()); | ||
// TODO: add logging here for error cases | ||
let last_positive_outcomes = match read_last_positive_outcomes(read_path) { | ||
Ok(outcomes) => Some(outcomes), | ||
Err(_) => None, | ||
}; | ||
// if last_positive_outcomes is none the hash set will be empty thereby allowing all mutants to be considered | ||
let existing_mutants: HashSet<MutantHash> = last_positive_outcomes | ||
.iter() | ||
.flatten() | ||
.map(|o| o.mutant_hash()) | ||
.collect(); | ||
let mutants = mutants | ||
.into_iter() | ||
.filter(|m| !existing_mutants.contains(&m.calculate_hash())) | ||
.collect(); | ||
(last_positive_outcomes, mutants) | ||
} | ||
|
||
fn read_last_positive_outcomes() -> Option<PositiveOutcomes> { | ||
todo!() | ||
fn read_last_positive_outcomes(read_path: &Utf8Path) -> Result<Vec<PositiveOutcome>> { | ||
let path = read_path.join(OUTDIR_NAME).join(POSITIVE_OUTCOMES_FILE); | ||
let json_str = fs::read_to_string(path.clone()); | ||
match json_str { | ||
Ok(contents) => serde_json::from_str(&contents).map_err(|e| anyhow!("{}", e)), | ||
Err(e) => Err(anyhow!("{}", e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters