installation_testing/hg.rs
1pub mod vcs {
2 use std::path::Path;
3 use std::{fs::remove_dir_all, process::Command};
4
5 pub struct Hg {
6 repository: String,
7 url: String,
8 }
9
10 impl Hg {
11 ///
12 /// Git constructor
13 ///
14 /// - `repo` The repository install path
15 /// - `uri` The repository remote url
16 ///
17 /// ```
18 ///
19 /// use std::process::Command;
20 /// use installation_testing::hg::vcs::Hg;
21 ///
22 /// let mut cargo = Command::new("ls");
23 ///
24 /// let test = cargo.arg("-l");
25 /// let mut checker = Hg::new("https://www.selenic.com/repo/hello","/tmp/zuul");
26 ///
27 /// checker.run(test).clean();
28 /// ```
29 ///
30 pub fn new(uri: &str, repo: &str) -> Hg {
31 Self {
32 repository: repo.to_string(),
33 url: uri.to_string(),
34 }
35 .get()
36 }
37
38 ///
39 /// # Get the remote repository
40 ///
41 fn get(self) -> Hg {
42 if Path::new(self.repository.as_str()).is_dir() {
43 remove_dir_all(self.repository.as_str())
44 .expect("failed to remove the last repository");
45 }
46 assert!(Command::new("hg")
47 .arg("clone")
48 .arg(self.url.as_str())
49 .arg(self.repository.as_str())
50 .spawn()
51 .expect("Failed to clone repository")
52 .wait()
53 .expect("msg")
54 .success());
55
56 self
57 }
58
59 pub fn run(&mut self, command: &mut Command) -> &mut Hg {
60 command
61 .current_dir(self.repository.as_str())
62 .spawn()
63 .expect("failed")
64 .wait()
65 .expect("");
66 self
67 }
68
69 ///
70 /// # remove the local repository
71 ///
72 pub fn clean(&mut self) -> bool {
73 remove_dir_all(self.repository.as_str()).expect("Failed to remove the directory");
74 true
75 }
76 }
77}