Skip to content

Commit

Permalink
test: refactor test modules structure
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 30, 2021
1 parent 3de62ba commit abc8f01
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 164 deletions.
118 changes: 118 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ assert_cmd = "1.0.3"
predicates = "1"
rand = "0.7.3"
indoc = "1.0.3"
speculoos = "0.7.0"

[features]
default = ["cli"]
Expand All @@ -55,3 +56,7 @@ required-features = ["clap"]
name = "coco"
path = "src/bin/coco.rs"
required-features = ["clap"]

[[test]]
name = "all"
path = "tests/common.rs"
14 changes: 7 additions & 7 deletions src/git/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use std::fmt::Formatter;

pub(crate) struct Statuses(pub Vec<Status>);

#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum Status {
Untracked(Changes),
UnCommitted(Changes),
}

#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum Changes {
New(String),
Renamed(String),
Expand Down Expand Up @@ -107,6 +107,7 @@ mod test {
use anyhow::Result;
use git2::Repository;
use git2::StatusOptions;
use speculoos::prelude::*;
use std::fs;
use tempfile::TempDir;

Expand All @@ -126,12 +127,11 @@ mod test {
.statuses(Some(&mut options))
.map_err(|err| anyhow!(err))?;

let statuses = Statuses::from(git_statuses);
let statuses = Statuses::from(git_statuses).0;

assert!(statuses
.0
.contains(&super::Status::Untracked(Changes::New("file".into()))));
assert_eq!(statuses.0.len(), 1);
assert_that(&statuses.iter())
.contains(&super::Status::Untracked(Changes::New("file".into())));
assert_that(&statuses).has_length(1);
Ok(())
}
}
17 changes: 8 additions & 9 deletions tests/coco_commit.rs → tests/coco_tests/commit.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use crate::helpers::*;

use anyhow::Result;
use assert_cmd::prelude::*;
use std::process::Command;

pub mod helper;
use helper::run_test_with_context;

#[test]
#[cfg(not(tarpaulin))]
fn commit_ok() -> Result<()> {
run_test_with_context(|context| {
// Arrange
helper::git_init()?;
git_init()?;
std::fs::write(context.test_dir.join("test_file"), "content")?;
helper::git_add()?;
git_add()?;

// Act
Command::cargo_bin("coco")?
Expand All @@ -33,7 +32,7 @@ fn commit_ok() -> Result<()> {
fn unstaged_changes_commit_err() -> Result<()> {
run_test_with_context(|context| {
// Arrange
helper::git_init()?;
git_init()?;
std::fs::write(context.test_dir.join("test_file"), "content")?;

// Act
Expand All @@ -55,9 +54,9 @@ fn unstaged_changes_commit_err() -> Result<()> {
fn untracked_changes_commit_ok() -> Result<()> {
run_test_with_context(|context| {
// Arrange
helper::git_init()?;
git_init()?;
std::fs::write(context.test_dir.join("staged"), "content")?;
helper::git_add()?;
git_add()?;
std::fs::write(context.test_dir.join("untracked"), "content")?;

// Act
Expand All @@ -79,7 +78,7 @@ fn untracked_changes_commit_ok() -> Result<()> {
fn empty_commit_err() -> Result<()> {
run_test_with_context(|_context| {
// Arrange
helper::git_init()?;
git_init()?;

// Act
Command::cargo_bin("coco")?
Expand Down
1 change: 1 addition & 0 deletions tests/coco_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod commit;
Loading

0 comments on commit abc8f01

Please sign in to comment.