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

lpenz / ogle / 12680489996

08 Jan 2025 09:53PM UTC coverage: 15.129% (+6.4%) from 8.73%
12680489996

push

github

lpenz
stream: differentiate stdout and stderr

The actions are the same for now.

0 of 4 new or added lines in 2 files covered. (0.0%)

38 existing lines in 3 files now uncovered.

41 of 271 relevant lines covered (15.13%)

0.2 hits per line

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

93.18
/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")]
UNCOV
18
    pub period: u64,
×
19

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

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

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

33
impl Cli {
34
    pub fn get_command(&self) -> Command {
2✔
35
        let mut cmd = Command::new(&self.command[0]);
2✔
36
        cmd.args(self.command.iter().skip(1));
2✔
37
        cmd.stdin(Stdio::null());
2✔
38
        cmd.stdout(Stdio::piped());
2✔
39
        cmd.stderr(Stdio::piped());
2✔
40
        cmd
2✔
41
    }
2✔
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
#[tokio::test]
72
async fn get_command() -> Result<()> {
1✔
73
    let cli = Cli::try_parse_from(vec!["ogle", "true"])?;
1✔
74
    let mut cmd = cli.get_command();
1✔
75
    let exit = cmd.spawn()?.wait().await?;
1✔
76
    assert!(exit.success());
1✔
77
    let cli = Cli::try_parse_from(vec!["ogle", "false"])?;
1✔
78
    let mut cmd = cli.get_command();
1✔
79
    let exit = cmd.spawn()?.wait().await?;
1✔
80
    assert!(!exit.success());
1✔
81
    Ok(())
1✔
82
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc