Skip to content

Commit

Permalink
Add a --part argument
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Dec 1, 2023
1 parent 0f7dce1 commit 1733cb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions aoc/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct Opts {
/// Use a specific day
day: Option<usize>,

#[clap(short, long)]
/// Restrict running to one part (1 or 2)
part: Option<usize>,

#[clap(short, long)]
/// Show timing information
timing: bool,
Expand Down Expand Up @@ -50,6 +54,7 @@ fn pretty_duration(duration: Duration) -> String {
pub fn run_tests<F>(
register: F,
single_day: Option<usize>,
single_part: Option<usize>,
main_only: bool,
timings: bool,
) -> eyre::Result<String>
Expand All @@ -61,6 +66,9 @@ where
let mut runners = super::runners::RUNNERS.lock().unwrap();
let keys = runners.keys().copied().collect::<Vec<_>>();
for (day, part) in keys {
if single_part.is_some_and(|p| p != part) {
continue;
}
if single_day.map_or(true, |d| d == day) {
for (version, runner) in runners.remove(&(day, part)).unwrap() {
if main_only && version.is_some() {
Expand Down Expand Up @@ -99,6 +107,9 @@ where
if opts.input.is_some() && opts.all {
eyre::bail!("--all and --input are not compatible");
}
if opts.part.is_some_and(|p| p < 1 || p > 2) {
eyre::bail!("--part accepts argument must be 1 or 2");
}
unsafe {
super::input::OVERRIDE_INPUT = opts.input;
}
Expand All @@ -108,6 +119,7 @@ where
run_tests(
register,
(!opts.all).then_some(current_day),
opts.part,
opts.main_only,
opts.timing
)?
Expand Down
2 changes: 1 addition & 1 deletion aoc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn check_results<F: Fn(), P: AsRef<Path>>(
expected: P,
main_only: bool,
) -> eyre::Result<bool> {
let actual = super::run::run_tests(register, None, false, main_only)?;
let actual = super::run::run_tests(register, None, None, false, main_only)?;
let update = std::env::var(ENV_VAR).is_ok();
if update {
if !matches!(equal_content(&actual, &expected, false), Ok(true)) {
Expand Down

0 comments on commit 1733cb4

Please sign in to comment.