-
Notifications
You must be signed in to change notification settings - Fork 30
/
diff.rs
98 lines (78 loc) · 2.84 KB
/
diff.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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() ) )
}