This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
forked from rustwasm/wasm-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense.rs
152 lines (121 loc) · 5.74 KB
/
license.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
extern crate failure;
extern crate wasm_pack;
use std::fs;
use utils::{self, fixture};
use wasm_pack::license;
use wasm_pack::manifest::CrateData;
#[test]
fn it_copies_a_license_default_path() {
let fixture = fixture::single_license();
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path, None);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE");
let pkg_license_path = out_dir.join("LICENSE");
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
}
#[test]
fn it_copies_a_license_provided_path() {
let fixture = fixture::single_license();
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path, None);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE");
let pkg_license_path = out_dir.join("LICENSE");
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
}
#[test]
fn it_copies_all_licenses_default_path() {
let fixture = fixture::dual_license();
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path, None);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE-WTFPL");
let pkg_license_path = out_dir.join("LICENSE-WTFPL");
let crate_license_path_2 = fixture.path.join("LICENSE-MIT");
let pkg_license_path_2 = out_dir.join("LICENSE-MIT");
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
assert!(fs::metadata(&crate_license_path_2).is_ok());
assert!(fs::metadata(&pkg_license_path_2).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
let crate_license_2 = utils::file::read_file(&crate_license_path_2).unwrap();
let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap();
assert_eq!(crate_license_2, pkg_license_2);
}
#[test]
fn it_copies_all_licenses_provided_path() {
let fixture = fixture::dual_license();
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path, None);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE-WTFPL");
let pkg_license_path = out_dir.join("LICENSE-WTFPL");
let crate_license_path_2 = fixture.path.join("LICENSE-MIT");
let pkg_license_path_2 = out_dir.join("LICENSE-MIT");
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
assert!(fs::metadata(&crate_license_path_2).is_ok());
assert!(fs::metadata(&pkg_license_path_2).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
let crate_license_2 = utils::file::read_file(&crate_license_path_2).unwrap();
let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap();
assert_eq!(crate_license_2, pkg_license_2);
}
#[test]
fn it_copies_a_non_standard_license_provided_path() {
let license_file = "NON-STANDARD-LICENSE";
let fixture = fixture::non_standard_license(license_file);
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path, None);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join(license_file);
let pkg_license_path = out_dir.join(license_file);
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
}