Fixed tests.

This commit is contained in:
ClementTsang 2019-09-14 22:29:40 -04:00
parent 4846175638
commit 2435b9d90c
3 changed files with 45 additions and 42 deletions

View File

@ -1,5 +1,7 @@
# rustop
[![Build Status](https://travis-ci.com/ClementTsang/rustop.svg?token=1wvzVgp94E1TZyPNs8JF&branch=master)](https://travis-ci.com/ClementTsang/rustop)
A top clone, written in Rust. Inspired by both [gtop](https://github.com/aksakalli/gtop) and [gotop](https://github.com/cjbassi/gotop)
## Installation
@ -31,5 +33,3 @@ Currently, I'm unable to test on MacOS, so I'm not sure how well this will work,
## Why
I was looking to try writing more things in Rust, and I love the gotop tool. And thus, this project was born.
Also, yes, I realize that gotop has a Rust rewrite branch... I found out about that when I was nearly ready to release the first version.

43
tests/arg_rate_tests.rs Normal file
View File

@ -0,0 +1,43 @@
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*;
use std::process::Command; // Run programs // Used for writing assertions
#[test]
fn valid_rate_argument() {
}
#[test]
fn test_small_rate() -> Result<(), Box<dyn std::error::Error>> {
Command::new("./target/debug/rustop")
.arg("-r")
.arg("249")
.assert()
.failure()
.stderr(predicate::str::contains("rate to be greater than 250"));
Ok(())
}
#[test]
fn test_negative_rate() -> Result<(), Box<dyn std::error::Error>> {
// This test should auto fail due to how clap works
Command::new("./target/debug/rustop")
.arg("-r")
.arg("-1000")
.assert()
.failure()
.stderr(predicate::str::contains("wasn't expected, or isn't valid in this context"));
Ok(())
}
#[test]
fn test_invalid_rate() -> Result<(), Box<dyn std::error::Error>> {
Command::new("./target/debug/rustop")
.arg("-r")
.arg("100-1000")
.assert()
.failure()
.stderr(predicate::str::contains("invalid digit"));
Ok(())
}

View File

@ -1,40 +0,0 @@
use std::process::Command; // Run programs
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions
#[test]
fn test_small_rate -> Result<(), Box<std::error::Error>> {
let mut cmd = Command::main_binary()?;
cmd.arg("-r")
.arg("249");
cmd.assert()
.failure()
.stderr(predicate::str::contains("rate"));
Ok(())
}
#[test]
fn test_negative_rate -> Result<(), Box<std::error::Error>> {
// This test should auto fail due to how clap works
let mut cmd = Command::main_binary()?;
cmd.arg("-r")
.arg("-1000");
cmd.assert()
.failure()
.stderr(predicate::str::contains("valid"));
Ok(())
}
#[test]
fn test_invalid_rate -> Result<(), Box<std::error::Error>> {
let mut cmd = Command::main_binary()?;
cmd.arg("-r")
.arg("1000 - 100");
cmd.assert()
.failure()
.stderr(predicate::str::contains("digit"));
Ok(())
}