Skip to content

Commit

Permalink
Merge pull request #1285 from Barsik-sus/willbe_diff_tests
Browse files Browse the repository at this point in the history
READY: (willbe): Update and refactor publish_need test cases in module entity.
  • Loading branch information
Wandalen authored Apr 15, 2024
2 parents 11dd96a + df428a9 commit 65af586
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod private
use std::borrow::Cow;
use std::fs::{ OpenOptions };
use std::io::{ Read, Seek, SeekFrom, Write };
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use convert_case::{ Case, Casing };
use regex::Regex;
use crate::action::readme_health_table_renew::find_example_file;
Expand Down
1 change: 0 additions & 1 deletion module/move/willbe/src/entity/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod private
{
use crate::*;
use std::collections::{ BTreeSet, HashSet };
use error_tools::err;
// aaa : for Petro : don't use cargo_metadata and Package directly, use facade
// aaa : ✅
use error_tools::for_app::{ bail, Result };
Expand Down
17 changes: 16 additions & 1 deletion module/move/willbe/src/entity/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub( crate ) mod private
{
io::{ self, Read },
fs,
path::Path,
path::{ Path, PathBuf },
};
use wtools::error::
{
Expand Down Expand Up @@ -53,6 +53,21 @@ pub( crate ) mod private
Ok( Self( crate_dir_path ) )
}
}

impl TryFrom< PathBuf > for CrateDir
{
type Error = CrateDirError;

fn try_from( crate_dir_path : PathBuf ) -> Result< Self, Self::Error >
{
if !crate_dir_path.join( "Cargo.toml" ).exists()
{
return Err( CrateDirError::Validation( "The path is not a crate directory path".into() ) );
}

Ok( Self( AbsolutePath::try_from( crate_dir_path ).unwrap() ) )
}
}

impl CrateDir
{
Expand Down
98 changes: 98 additions & 0 deletions module/move/willbe/tests/inc/entity/diff.rs
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() ) )
}
7 changes: 2 additions & 5 deletions module/move/willbe/tests/inc/entity/mod.rs
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;
134 changes: 0 additions & 134 deletions module/move/willbe/tests/inc/entity/publish_need.rs

This file was deleted.

18 changes: 9 additions & 9 deletions module/move/willbe/tests/inc/package.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::*;
use the_module::
{
Workspace,
_path::AbsolutePath,
package::PublishPlan,
};
use willbe::package::perform_packages_publish;

// use super::*;
// use the_module::
// {
// Workspace,
// _path::AbsolutePath,
// package::PublishPlan,
// };
// use willbe::package::perform_packages_publish;
//
// #[ test ]
// fn plan_publish_many_packages()
// {
Expand Down

0 comments on commit 65af586

Please sign in to comment.