Skip to content

Commit

Permalink
chore(tests): update CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omarabid committed Feb 4, 2024
1 parent dd90c5c commit 44d90db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 0 additions & 2 deletions core/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ pub fn helpme() -> Result<()> {
.as_ref()
.ok_or_else(|| GitonError::EmptyResponse(String::from("No content returned")))?;

dbg!(returned_command);

// decode returned response
let decoded_command = crate::decode::decode_gpt_response(returned_command.to_string())?;

Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ fn main() -> Result<()> {
// Match Commands
let cli_match = cli::cli_match();

dbg!(&cli_match);

match cli_match {
Ok(_) => {}
Err(e) => {
Expand Down
39 changes: 36 additions & 3 deletions tests/test_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,48 @@ use predicates::prelude::*;

use std::process::Command;

// CLI Test
//
// Test the CLI interface of the application. This is done by running the binary
// and expecting that the execution is passed to Git.
//
// In this case, we expect the initial output to be the usage of Git.
#[test]
fn test_cli() {
let expected_initial = "usage: git [-v | --version]";

let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");
//cmd.assert().failure();

cmd.assert()
.stdout(predicate::str::contains(expected_initial));
}

// CLI Version Test
//
// This is a similar test to the previous one, but we are testing the ability to
// pass the `version` argument to the binary.
#[test]
fn test_version() {
let expected_version = "giton 1.0.0\n";
let expected_initial = "git version";

let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");

cmd.arg("version")
.assert()
.stdout(predicate::str::contains(expected_initial));
}

// CLI Passthrough Test
//
// This tests the ability to call Clap commands. The command tested here is
// `onconfig`.
#[test]
fn test_passthrough() {
let expected_initial = "+------------+-----------------------------------------------------+";

let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");
//cmd.arg("--version").assert().stdout(expected_version);

cmd.arg("onconfig")
.assert()
.stdout(predicate::str::contains(expected_initial));
}

0 comments on commit 44d90db

Please sign in to comment.