-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1285 from Barsik-sus/willbe_diff_tests
READY: (willbe): Update and refactor publish_need test cases in module entity.
- Loading branch information
Showing
7 changed files
with
126 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::*; | ||
|
||
use std::path::{ Path, PathBuf }; | ||
use assert_fs::{ TempDir, prelude::* }; | ||
use crates_tools::CrateArchive; | ||
use the_module::*; | ||
use _path::AbsolutePath; | ||
use package::Package; | ||
use diff::crate_diff; | ||
use the_module::version::{ Version, BumpOptions, version_bump }; | ||
|
||
const TEST_MODULE_PATH : &str = "../../test/"; | ||
|
||
#[ test ] | ||
fn no_changes() | ||
{ | ||
let tmp = &TempDir::new().unwrap(); | ||
let package_path = package_path( "c" ); | ||
|
||
let left = prepare( tmp, "left", &package_path ); | ||
let left_crate = crate_file_path( &left ); | ||
let left_archive = CrateArchive::read( &left_crate ).unwrap(); | ||
|
||
let right = prepare( tmp, "right", &package_path ); | ||
let right_crate = crate_file_path( &right ); | ||
let right_archive = CrateArchive::read( &right_crate ).unwrap(); | ||
|
||
let has_changes = crate_diff( &left_archive, &right_archive ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); | ||
|
||
assert!( !has_changes ); | ||
} | ||
|
||
#[ test ] | ||
fn with_changes() | ||
{ | ||
let tmp = &TempDir::new().unwrap(); | ||
let package_path = package_path( "c" ); | ||
|
||
let left = | ||
{ | ||
let left = prepare( tmp, "left", &package_path ); | ||
let left_crate = crate_file_path( &left ); | ||
CrateArchive::read( &left_crate ).unwrap() | ||
}; | ||
|
||
let right = | ||
{ | ||
let right = prepare( tmp, "right", &package_path ); | ||
|
||
let absolute = AbsolutePath::try_from( right.as_path() ).unwrap(); | ||
let right_package = Package::try_from( absolute ).unwrap(); | ||
let right_version = Version::try_from( &right_package.version().unwrap() ).unwrap(); | ||
|
||
let bump_options = BumpOptions | ||
{ | ||
crate_dir : CrateDir::try_from( right.clone() ).unwrap(), | ||
old_version : right_version.clone(), | ||
new_version : right_version.bump(), | ||
dependencies : vec![], | ||
dry : false, | ||
}; | ||
version_bump( bump_options ).unwrap(); | ||
|
||
let right_crate = crate_file_path( &right ); | ||
CrateArchive::read( &right_crate ).unwrap() | ||
}; | ||
|
||
let has_changes = crate_diff( &left, &right ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); | ||
|
||
assert!( has_changes ); | ||
} | ||
|
||
fn package_path< P : AsRef< Path > >( path : P ) -> PathBuf | ||
{ | ||
let root_path = Path::new( env!( "CARGO_MANIFEST_DIR" ) ).join( TEST_MODULE_PATH ); | ||
root_path.join( path ) | ||
} | ||
|
||
fn prepare( tmp : &TempDir, name : &str, manifest_dir_path : &Path ) -> PathBuf | ||
{ | ||
let dir = tmp.child( name ); | ||
dir.create_dir_all().unwrap(); | ||
dir.copy_from( manifest_dir_path, &[ "**" ] ).unwrap(); | ||
|
||
dir.to_path_buf() | ||
} | ||
|
||
fn crate_file_path( manifest_dir_path : &Path ) -> PathBuf | ||
{ | ||
_ = cargo::pack( cargo::PackOptions::former().path( manifest_dir_path ).dry( false ).form() ).expect( "Failed to package a package" ); | ||
|
||
let absolute = AbsolutePath::try_from( manifest_dir_path ).unwrap(); | ||
let package = Package::try_from( absolute ).unwrap(); | ||
manifest_dir_path | ||
.join( "target" ) | ||
.join( "package" ) | ||
.join( format!( "{}-{}.crate", package.name().unwrap(), package.version().unwrap() ) ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
use super::*; | ||
|
||
pub mod dependencies; | ||
pub mod diff; | ||
pub mod features; | ||
|
||
pub mod version; | ||
|
||
pub mod publish_need; | ||
|
||
pub mod dependencies; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters