• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lpenz / ogle / 12966770574

25 Jan 2025 04:55PM UTC coverage: 38.626% (-0.07%) from 38.693%
12966770574

push

github

lpenz
timewrap: new wrapper in its own module; keep it as a String no more

13 of 65 new or added lines in 5 files covered. (20.0%)

163 of 422 relevant lines covered (38.63%)

1.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.34
/src/cli.rs
1
// Copyright (C) 2020 Leandro Lisboa Penz <lpenz@lpenz.org>
2
// This file is subject to the terms and conditions defined in
3
// file 'LICENSE', which is part of this source code package.
4

5
use std::process::Stdio;
6
use tokio::process::Command;
7

8
use clap::Parser;
9

10
#[cfg(test)]
11
use color_eyre::Result;
12

13
#[derive(Parser, Debug)]
14
#[command(author, version, about, long_about = None)]
15
pub struct Cli {
16
    /// Period to sleep between executions
17
    #[arg(short, long, default_value = "1")]
NEW
18
    pub period: u32,
×
19

20
    /// Loop until the command exists with success
21
    #[arg(short = 'z', long = "until-success")]
22
    pub until_success: bool,
×
23

24
    /// Loop until the command exists with a failure
25
    #[arg(short = 'e', long = "until-failure")]
26
    pub until_failure: bool,
×
27

28
    /// The command to run
29
    #[clap(value_parser, required = true)]
30
    pub command: Vec<String>,
13✔
31
}
32

33
impl Cli {
34
    pub fn get_command(&self) -> Command {
8✔
35
        let mut cmd = Command::new(&self.command[0]);
8✔
36
        cmd.args(self.command.iter().skip(1));
8✔
37
        cmd.stdin(Stdio::null());
8✔
38
        cmd.stdout(Stdio::piped());
8✔
39
        cmd.stderr(Stdio::piped());
8✔
40
        cmd
8✔
41
    }
8✔
42
}
43

44
#[test]
45
fn empty() {
1✔
46
    let cli = Cli::try_parse_from(vec!["ogle"]);
1✔
47
    assert!(cli.is_err());
1✔
48
}
1✔
49

50
#[test]
51
fn dashes() -> Result<()> {
1✔
52
    let cli = Cli::try_parse_from(vec!["ogle", "--"]);
1✔
53
    assert!(cli.is_err());
1✔
54
    let cli = Cli::try_parse_from(vec!["ogle", "--", "ls", "-l"])?;
1✔
55
    assert_eq!(cli.command[0], "ls");
1✔
56
    assert_eq!(cli.command[1], "-l");
1✔
57
    assert_eq!(cli.command.len(), 2);
1✔
58
    assert_eq!(cli.period, 1);
1✔
59
    Ok(())
1✔
60
}
1✔
61

62
#[test]
63
fn period() -> Result<()> {
1✔
64
    let cli = Cli::try_parse_from(vec!["ogle", "-p", "5", "--", "ls", "-l"])?;
1✔
65
    assert_eq!(cli.period, 5);
1✔
66
    let cli = Cli::try_parse_from(vec!["ogle", "--period", "7", "--", "ls", "-l"])?;
1✔
67
    assert_eq!(cli.period, 7);
1✔
68
    Ok(())
1✔
69
}
1✔
70

71
#[test]
72
fn until() -> Result<()> {
1✔
73
    let cli = Cli::try_parse_from(vec!["ogle", "-z", "--", "true"])?;
1✔
74
    assert!(cli.until_success);
1✔
75
    assert!(!cli.until_failure);
1✔
76
    let cli = Cli::try_parse_from(vec!["ogle", "-e", "--", "true"])?;
1✔
77
    assert!(!cli.until_success);
1✔
78
    assert!(cli.until_failure);
1✔
79
    Ok(())
1✔
80
}
1✔
81

82
#[tokio::test]
83
async fn get_command() -> Result<()> {
1✔
84
    let cli = Cli::try_parse_from(vec!["ogle", "true"])?;
1✔
85
    let mut cmd = cli.get_command();
1✔
86
    let exit = cmd.spawn()?.wait().await?;
1✔
87
    assert!(exit.success());
1✔
88
    let cli = Cli::try_parse_from(vec!["ogle", "false"])?;
1✔
89
    let mut cmd = cli.get_command();
1✔
90
    let exit = cmd.spawn()?.wait().await?;
1✔
91
    assert!(!exit.success());
1✔
92
    Ok(())
1✔
93
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc