Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 1b4a8b0

Browse files
committed
use PathBuf for unmocked_commands
1 parent 6b050db commit 1b4a8b0

5 files changed

Lines changed: 24 additions & 23 deletions

File tree

src/protocol/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl Protocol {
349349
#[derive(Debug, PartialEq)]
350350
pub struct Protocols {
351351
pub protocols: Vec<Protocol>,
352-
pub unmocked_commands: Vec<Vec<u8>>,
352+
pub unmocked_commands: Vec<PathBuf>,
353353
pub interpreter: Option<Vec<u8>>,
354354
}
355355

@@ -381,7 +381,7 @@ impl Protocols {
381381
if let Ok(unmocked_commands) = object.expect_field("unmockedCommands") {
382382
for unmocked_command in unmocked_commands.expect_array()? {
383383
self.unmocked_commands
384-
.push(unmocked_command.expect_str()?.as_bytes().to_vec());
384+
.push(PathBuf::from(unmocked_command.expect_str()?));
385385
}
386386
}
387387
Ok(())
@@ -454,7 +454,7 @@ impl Protocols {
454454
self.unmocked_commands
455455
.iter()
456456
.map(|unmocked_command| {
457-
Ok(Yaml::String(String::from_utf8(unmocked_command.to_vec())?))
457+
Ok(Yaml::String(path_to_string(unmocked_command)?.to_string()))
458458
})
459459
.collect::<R<Vec<Yaml>>>()?,
460460
),
@@ -833,7 +833,7 @@ mod load {
833833
"
834834
)?
835835
.unmocked_commands
836-
.map(|command| String::from_utf8(command).unwrap()),
836+
.map(|path| path.to_string_lossy().to_string()),
837837
vec!["foo"]
838838
);
839839
Ok(())
@@ -1071,7 +1071,7 @@ mod serialize {
10711071
#[test]
10721072
fn includes_unmocked_commands() -> R<()> {
10731073
let mut protocols = Protocols::new(vec![Protocol::new(vec![])]);
1074-
protocols.unmocked_commands = vec![b"sed".to_vec()];
1074+
protocols.unmocked_commands = vec![PathBuf::from("sed")];
10751075
roundtrip(protocols)
10761076
}
10771077
}

src/protocol_checker/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::PathBuf;
1919
pub struct ProtocolChecker {
2020
context: Context,
2121
pub protocol: Protocol,
22-
pub unmocked_commands: Vec<Vec<u8>>,
22+
pub unmocked_commands: Vec<PathBuf>,
2323
pub result: CheckerResult,
2424
temporary_executables: Vec<ShortTempFile>,
2525
}
@@ -28,7 +28,7 @@ impl ProtocolChecker {
2828
pub fn new(
2929
context: &Context,
3030
protocol: Protocol,
31-
unmocked_commands: &[Vec<u8>],
31+
unmocked_commands: &[PathBuf],
3232
) -> ProtocolChecker {
3333
ProtocolChecker {
3434
context: context.clone(),
@@ -103,7 +103,7 @@ impl SyscallMock for ProtocolChecker {
103103
if !self
104104
.unmocked_commands
105105
.iter()
106-
.any(|c| protocol::compare_executables(&c, &executable))
106+
.any(|c| protocol::compare_executables(&c.as_os_str().as_bytes(), &executable))
107107
{
108108
let mock_executable_path = self.handle_step(protocol::Command {
109109
executable,

src/recorder/hole_recorder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::tracer::SyscallMock;
99
use crate::{ExitCode, R};
1010
use libc::user_regs_struct;
1111
use nix::unistd::Pid;
12-
use std::path::Path;
12+
use std::path::{Path, PathBuf};
1313

1414
pub enum HoleRecorder {
1515
Checker {
@@ -24,7 +24,7 @@ pub enum HoleRecorder {
2424
impl HoleRecorder {
2525
pub fn new(
2626
context: &Context,
27-
unmocked_commands: &[Vec<u8>],
27+
unmocked_commands: &[PathBuf],
2828
protocol: Protocol,
2929
) -> HoleRecorder {
3030
HoleRecorder::Checker {

src/recorder/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use crate::tracer::SyscallMock;
88
use crate::R;
99
use libc::user_regs_struct;
1010
use nix::unistd::Pid;
11+
use std::os::unix::ffi::OsStrExt;
12+
use std::path::PathBuf;
1113

1214
pub struct Recorder {
1315
protocol: Protocol,
1416
command: Option<Command>,
15-
unmocked_commands: Vec<Vec<u8>>,
17+
unmocked_commands: Vec<PathBuf>,
1618
}
1719

1820
impl Recorder {
@@ -24,7 +26,7 @@ impl Recorder {
2426
}
2527
}
2628

27-
pub fn new(protocol: Protocol, unmocked_commands: &[Vec<u8>]) -> Recorder {
29+
pub fn new(protocol: Protocol, unmocked_commands: &[PathBuf]) -> Recorder {
2830
Recorder {
2931
protocol,
3032
command: None,
@@ -43,11 +45,10 @@ impl SyscallMock for Recorder {
4345
executable: Vec<u8>,
4446
arguments: Vec<Vec<u8>>,
4547
) -> R<()> {
46-
if !self
47-
.unmocked_commands
48-
.iter()
49-
.any(|unmocked_command| compare_executables(&unmocked_command, &executable))
50-
{
48+
let is_unmocked_command = self.unmocked_commands.iter().any(|unmocked_command| {
49+
compare_executables(unmocked_command.as_os_str().as_bytes(), &executable)
50+
});
51+
if !is_unmocked_command {
5152
self.command = Some(Command {
5253
executable,
5354
arguments,

src/recorder/protocol_result.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::tracer::stdio_redirecting::CaptureStderr;
99
use crate::tracer::Tracer;
1010
use crate::{ExitCode, R};
1111
use std::fs::OpenOptions;
12-
use std::path::Path;
12+
use std::path::{Path, PathBuf};
1313

1414
#[derive(Debug, PartialEq)]
1515
pub enum ProtocolResult {
@@ -44,15 +44,15 @@ impl ProtocolResult {
4444
interpreter: &Option<Vec<u8>>,
4545
program: &Path,
4646
protocols: Vec<Protocol>,
47-
unmocked_commands: &[Vec<u8>],
47+
unmocked_commands: &[PathBuf],
4848
) -> R<Vec<ProtocolResult>> {
4949
let mut results = vec![];
5050
for protocol in protocols.into_iter() {
5151
results.push(run_against_protocol(
5252
context,
5353
&interpreter,
5454
program,
55-
&unmocked_commands,
55+
unmocked_commands,
5656
protocol,
5757
)?);
5858
}
@@ -62,7 +62,7 @@ impl ProtocolResult {
6262
pub fn handle_results(
6363
context: &Context,
6464
protocols_file: &Path,
65-
unmocked_commands: Vec<Vec<u8>>,
65+
unmocked_commands: Vec<PathBuf>,
6666
results: &[ProtocolResult],
6767
) -> R<ExitCode> {
6868
let checker_results = CheckerResults(
@@ -85,7 +85,7 @@ impl ProtocolResult {
8585
fn handle_recorded(
8686
context: &Context,
8787
protocols_file: &Path,
88-
unmocked_commands: Vec<Vec<u8>>,
88+
unmocked_commands: Vec<PathBuf>,
8989
results: &[ProtocolResult],
9090
checker_results: &CheckerResults,
9191
) -> R<()> {
@@ -117,7 +117,7 @@ fn run_against_protocol(
117117
context: &Context,
118118
interpreter: &Option<Vec<u8>>,
119119
program: &Path,
120-
unmocked_commands: &[Vec<u8>],
120+
unmocked_commands: &[PathBuf],
121121
protocol: Protocol,
122122
) -> R<ProtocolResult> {
123123
macro_rules! run_against_mock {

0 commit comments

Comments
 (0)