Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Require input marker in args when given corpus dir #3205

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/agent/coverage/examples/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::process::Command;
use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use anyhow::{bail, Result};
use clap::Parser;
use cobertura::CoberturaCoverage;
use coverage::allowlist::{AllowList, TargetAllowList};
Expand Down Expand Up @@ -68,6 +68,8 @@ fn main() -> Result<()> {
let loader = Arc::new(Loader::new());

if let Some(dir) = args.input_dir {
check_for_input_marker(&args.command)?;

for input in std::fs::read_dir(dir)? {
let input = input?.path();
let cmd = command(&args.command, Some(&input.to_string_lossy()));
Expand Down Expand Up @@ -108,6 +110,17 @@ fn main() -> Result<()> {
Ok(())
}

fn check_for_input_marker(argv: &[String]) -> Result<()> {
// Skip exe name, require input marker in args.
for arg in argv.iter().skip(1) {
if arg.contains(INPUT_MARKER) {
return Ok(());
}
}

bail!("input file template string not present in target args")
}

fn command(argv: &[String], input: Option<&str>) -> Command {
let mut cmd = Command::new(&argv[0]);

Expand Down