Skip to content

Commit

Permalink
refactor: run tests as integration test (#17)
Browse files Browse the repository at this point in the history
* refactor: run tests as integration test

* chore: Lint

* chore: Revert unit test move

---------

Co-authored-by: Dustin Blackman <[email protected]>
  • Loading branch information
orhun and Dustin Blackman authored Jan 1, 2024
1 parent 6951082 commit 4c5c49a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 62 deletions.
4 changes: 0 additions & 4 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ use which::which;
use crate::cargo_config;
use crate::metadata;

#[cfg(test)]
#[path = "binary_test.rs"]
mod binary_test;

pub fn cargo_install(
binary_package: metadata::BinaryPackage,
cache_path: path::PathBuf,
Expand Down
4 changes: 0 additions & 4 deletions src/cargo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use toml_edit::Document;

use crate::metadata;

#[cfg(test)]
#[path = "cargo_config_test.rs"]
mod cargo_config_test;

pub fn sync_aliases() -> Result<()> {
let mut toml_str = "".to_string();
let config_path = metadata::get_project_root()?.join(".cargo/config.toml");
Expand Down
4 changes: 0 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ use crate::cargo_config;
use crate::metadata;
use crate::shims;

#[cfg(test)]
#[path = "cli_integration_test.rs"]
mod cli_integration_test;

fn install_all_binaries() -> Result<()> {
let binary_packages = metadata::get_binary_packages()?;
for binary_package in binary_packages {
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]

pub mod binary;
pub mod cargo_config;
pub mod cli;
pub mod metadata;
pub mod shims;
11 changes: 1 addition & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]

use std::process;

use owo_colors::OwoColorize;

mod binary;
mod cargo_config;
mod cli;
mod metadata;
mod shims;

fn main() {
let res = cli::run();
let res = cargo_run_bin::cli::run();

// Only reached if run-bin code fails, otherwise process exits early from within
// binary::run.
Expand Down
8 changes: 4 additions & 4 deletions src/metadata_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::*;
use super::get_binary_packages;

mod get_binary_packages {
use super::*;

#[test]
fn it_returns_locked_packages() {
let binary_packages = get_binary_packages().unwrap();
let nextest = binary_packages.iter().find(|&e| {
return e.package == "cargo-nextest";
});
let nextest = binary_packages
.iter()
.find(|&e| return e.package == "cargo-nextest");

assert!(nextest.is_some());
let res = nextest.unwrap();
Expand Down
4 changes: 0 additions & 4 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use cfg_if::cfg_if;

use crate::metadata;

#[cfg(test)]
#[path = "shims_test.rs"]
mod shims_test;

#[cfg(target_family = "unix")]
fn create_shim(binary: &str, bin_path: path::PathBuf) -> Result<()> {
use std::os::unix::prelude::OpenOptionsExt;
Expand Down
28 changes: 12 additions & 16 deletions src/binary_test.rs → tests/binary_test.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use cfg_if::cfg_if;

use super::*;

mod install {
use super::*;
use crate::metadata;
use cargo_run_bin::binary::install;
use cargo_run_bin::metadata;
use cfg_if::cfg_if;

#[test]
fn it_returns_bin_path() {
let binary_packages = metadata::get_binary_packages().unwrap();
let nextest = binary_packages
.iter()
.find(|&e| {
return e.package == "cargo-nextest";
})
.find(|&e| e.package == "cargo-nextest")
.unwrap();

let cache_bin_path = install(nextest.clone()).unwrap();
Expand All @@ -29,7 +24,8 @@ mod install {
}

mod cargo_install {
use super::*;
use cargo_run_bin::binary::cargo_install;
use cargo_run_bin::metadata;

#[test]
fn it_builds_successfully() {
Expand Down Expand Up @@ -165,7 +161,8 @@ mod cargo_install {
}

mod binstall {
use super::*;
use cargo_run_bin::binary::binstall;
use cargo_run_bin::metadata;

#[test]
fn it_builds_successfully() {
Expand Down Expand Up @@ -213,17 +210,16 @@ mod binstall {
}

mod run {
use super::*;
use crate::metadata;
use cargo_run_bin::binary::install;
use cargo_run_bin::binary::run;
use cargo_run_bin::metadata;

#[test]
fn it_runs_help_successfully() {
let binary_packages = metadata::get_binary_packages().unwrap();
let nextest = binary_packages
.iter()
.find(|&e| {
return e.package == "cargo-nextest";
})
.find(|&e| e.package == "cargo-nextest")
.unwrap();
let cache_bin_path = install(nextest.clone()).unwrap();

Expand Down
10 changes: 4 additions & 6 deletions src/cargo_config_test.rs → tests/cargo_config_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::fs;

use super::*;

mod sync_aliases {
use super::*;
use std::fs;

use cargo_run_bin::cargo_config::sync_aliases;

#[test]
fn it_removes_and_adds_aliases() {
Expand All @@ -19,7 +17,7 @@ mod sync_aliases {
}

mod binstall_alias_exists {
use super::*;
use cargo_run_bin::cargo_config::binstall_alias_exists;

// Lazy happy path test.
#[test]
Expand Down
14 changes: 8 additions & 6 deletions src/cli_integration_test.rs → tests/cli_integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use assert_cmd::Command;

use crate::metadata;
use cargo_run_bin::metadata;

fn get_bin() -> String {
return metadata::get_project_root()
.unwrap()
.join("target/debug/cargo-bin")
.join(env!("CARGO_BIN_EXE_cargo-bin").replace(".exe", ""))
.to_str()
.unwrap()
.to_string();
}

mod direct {
use super::*;
use assert_cmd::Command;

use super::get_bin;

#[test]
fn it_syncs_aliases_successfully() {
Expand Down Expand Up @@ -84,7 +84,9 @@ mod direct {
}

mod bin_prefix {
use super::*;
use assert_cmd::Command;

use super::get_bin;

#[test]
fn it_syncs_aliases_successfully() {
Expand Down
6 changes: 2 additions & 4 deletions src/shims_test.rs → tests/shims_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::*;

mod sync_shims {
use super::super::metadata;
use super::*;
use cargo_run_bin::metadata;
use cargo_run_bin::shims::sync;

#[test]
#[cfg(target_family = "unix")]
Expand Down

0 comments on commit 4c5c49a

Please sign in to comment.