|
|
@ -92,63 +92,30 @@ impl<_C: CommandRunner, C: Borrow<_C>, P: AsRef<Path>, S: AsRef<str>, B: AsRef<s |
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::Checkout;
|
|
|
|
use super::{Checkout, Symbol};
|
|
|
|
use crate::async_utils::run;
|
|
|
|
use crate::async_utils::sleep;
|
|
|
|
use crate::command_runner::CommandRunner;
|
|
|
|
use crate::symbols::Symbol;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::ffi::{OsStr, OsString};
|
|
|
|
use std::io::Result as IoResult;
|
|
|
|
use std::os::unix::process::ExitStatusExt;
|
|
|
|
use std::process::{ExitStatus, Output};
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
|
|
|
|
struct DummyCommandRunner {
|
|
|
|
pub args: RefCell<Vec<Vec<OsString>>>,
|
|
|
|
}
|
|
|
|
#[async_trait(?Send)]
|
|
|
|
impl CommandRunner for DummyCommandRunner {
|
|
|
|
async fn run(&self, program: &str, args: &[&OsStr], stdin: &[u8]) -> IoResult<Output> {
|
|
|
|
assert_eq!(program, "git");
|
|
|
|
assert_eq!(stdin, b"");
|
|
|
|
sleep(Duration::from_millis(50)).await;
|
|
|
|
self
|
|
|
|
.args
|
|
|
|
.borrow_mut()
|
|
|
|
.push(args.iter().map(|a| a.to_os_string()).collect());
|
|
|
|
Ok(Output {
|
|
|
|
status: ExitStatus::from_raw(0),
|
|
|
|
stdout: vec![],
|
|
|
|
stderr: vec![],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use crate::command_runner::MockCommandRunner;
|
|
|
|
use mockall::Sequence;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() {
|
|
|
|
let c = DummyCommandRunner {
|
|
|
|
args: RefCell::new(vec![]),
|
|
|
|
};
|
|
|
|
let checkout: Checkout<DummyCommandRunner, _, _, _, _> =
|
|
|
|
Checkout::new(".", "source", "branch", &c);
|
|
|
|
let start = Instant::now();
|
|
|
|
let mut seq = Sequence::new();
|
|
|
|
let mut c = MockCommandRunner::new();
|
|
|
|
c.expect_get_output()
|
|
|
|
.times(1)
|
|
|
|
.withf(|cmd, args| cmd == "git" && args == ["-C", ".", "rev-list", "-1", "HEAD"])
|
|
|
|
.returning(|_, _| Ok("".into()));
|
|
|
|
c.expect_get_output()
|
|
|
|
.times(1)
|
|
|
|
.in_sequence(&mut seq)
|
|
|
|
.withf(|cmd, args| cmd == "git" && args == ["-C", ".", "fetch", "source", "branch"])
|
|
|
|
.returning(|_, _| Ok("".into()));
|
|
|
|
c.expect_get_output()
|
|
|
|
.times(1)
|
|
|
|
.in_sequence(&mut seq)
|
|
|
|
.withf(|cmd, args| cmd == "git" && args == ["-C", ".", "rev-list", "-1", "FETCH_HEAD"])
|
|
|
|
.returning(|_, _| Ok("".into()));
|
|
|
|
let checkout = Checkout::new(".", "source", "branch", c);
|
|
|
|
assert!(run(checkout.target_reached()).unwrap());
|
|
|
|
let end = Instant::now();
|
|
|
|
let mut args = c.args.into_inner();
|
|
|
|
let first_two_args = &mut args[0..2];
|
|
|
|
first_two_args.sort_unstable();
|
|
|
|
assert_eq!(
|
|
|
|
first_two_args,
|
|
|
|
[
|
|
|
|
["-C", ".", "fetch", "source", "branch"],
|
|
|
|
["-C", ".", "rev-list", "-1", "HEAD"],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
assert_eq!(args[2], ["-C", ".", "rev-list", "-1", "FETCH_HEAD"]);
|
|
|
|
|
|
|
|
assert!((end - start).as_millis() >= 100);
|
|
|
|
assert!((end - start).as_millis() < 150);
|
|
|
|
}
|
|
|
|
}
|