sagiegurari / cargo-make
1
use super::*;
2
use envmnt;
3

4
#[test]
5
#[ignore]
6 2
fn get_cargo_home_env() {
7 2
    let directory_path = env::current_dir().unwrap();
8 2
    let directory = directory_path.to_str().unwrap();
9 2
    envmnt::set("CARGO_HOME", directory);
10

11 2
    let output = get_cargo_home().unwrap();
12 2
    envmnt::remove("CARGO_HOME");
13

14 2
    assert_eq!(output, directory);
15 2
}
16

17
#[test]
18
#[ignore]
19 2
fn get_cargo_home_no_env() {
20 2
    envmnt::remove("CARGO_HOME");
21

22 2
    let output = get_cargo_home().unwrap();
23

24 2
    assert!(output.contains(".cargo"));
25 2
}
26

27
#[test]
28
#[ignore]
29 2
fn get_cargo_home_file() {
30 2
    let directory_path = env::current_dir().unwrap();
31 2
    let directory = directory_path.to_str().unwrap();
32 2
    let file_path = Path::new(directory).join("Cargo.toml");
33 2
    envmnt::set("CARGO_HOME", file_path);
34

35 2
    let output = get_cargo_home();
36 2
    envmnt::remove("CARGO_HOME");
37

38 2
    assert!(output.is_none());
39 2
}
40

41
#[test]
42 8
fn load_crates_toml_valid() {
43 8
    let cwd = envmnt::get_or_panic("CARGO_MAKE_WORKING_DIRECTORY");
44 8
    let file_path = Path::new(&cwd).join("src/lib/test/test_files");
45 8
    let directory = file_path.to_str().unwrap();
46 8
    let info_option = load_crates_toml(&directory);
47

48 8
    assert!(info_option.is_some());
49 8
    let info = info_option.unwrap();
50 8
    assert!(info.v1.is_some());
51 8
    assert_eq!(info.v1.unwrap().len(), 3);
52 8
}
53

54
#[test]
55 8
fn load_crates_toml_file_not_found() {
56 8
    let cwd = envmnt::get_or_panic("CARGO_MAKE_WORKING_DIRECTORY");
57 8
    let info_option = load_crates_toml(&cwd);
58

59 8
    assert!(info_option.is_none());
60 8
}
61

62
#[test]
63 8
fn get_crate_version_from_info_no_info() {
64 8
    let info = CratesRegistryInfo { v1: None };
65 8
    let version = get_crate_version_from_info("cargo-make", &info);
66

67 8
    assert!(version.is_none());
68 8
}
69

70
#[test]
71 8
fn get_crate_version_from_info_empty_info() {
72 8
    let info = CratesRegistryInfo {
73 8
        v1: Some(HashMap::new()),
74
    };
75 8
    let version = get_crate_version_from_info("cargo-make", &info);
76

77 8
    assert!(version.is_none());
78 8
}
79

80
#[test]
81 8
fn get_crate_version_from_info_not_found() {
82 8
    let mut map = HashMap::new();
83 8
    map.insert("1 1 1".to_string(), vec![]);
84 8
    map.insert("2 2 2".to_string(), vec![]);
85 8
    let info = CratesRegistryInfo { v1: Some(map) };
86 8
    let version = get_crate_version_from_info("cargo-make", &info);
87

88 8
    assert!(version.is_none());
89 8
}
90

91
#[test]
92 8
fn get_crate_version_from_info_found_invalid_line() {
93 8
    let mut map = HashMap::new();
94 8
    map.insert("1 1 1".to_string(), vec![]);
95 8
    map.insert("cargo-make".to_string(), vec![]);
96 8
    map.insert("2 2 2".to_string(), vec![]);
97 8
    let info = CratesRegistryInfo { v1: Some(map) };
98 8
    let version = get_crate_version_from_info("cargo-make", &info);
99

100 8
    assert!(version.is_none());
101 8
}
102

103
#[test]
104 8
fn get_crate_version_from_info_found_invalid_version() {
105 8
    let mut map = HashMap::new();
106 8
    map.insert("1 1 1".to_string(), vec![]);
107 8
    map.insert("cargo-make abc 2".to_string(), vec![]);
108 8
    map.insert("2 2 2".to_string(), vec![]);
109 8
    let info = CratesRegistryInfo { v1: Some(map) };
110 8
    let version = get_crate_version_from_info("cargo-make", &info);
111

112 8
    assert!(version.is_none());
113 8
}
114

115
#[test]
116 8
fn get_crate_version_from_info_valid() {
117 8
    let mut map = HashMap::new();
118 8
    map.insert("1 1 1".to_string(), vec![]);
119 8
    map.insert("cargo-make 1.2.3 2".to_string(), vec![]);
120 8
    map.insert("2 2 2".to_string(), vec![]);
121 8
    let info = CratesRegistryInfo { v1: Some(map) };
122 8
    let version = get_crate_version_from_info("cargo-make", &info);
123

124 8
    let semver_version = version.unwrap();
125 8
    assert_eq!(semver_version.major, 1);
126 8
    assert_eq!(semver_version.minor, 2);
127 8
    assert_eq!(semver_version.patch, 3);
128 8
}
129

130
#[test]
131 8
fn is_min_version_valid_for_versions_equal() {
132 8
    let valid = is_min_version_valid_for_versions(
133 8
        &Version::parse("1.2.3").unwrap(),
134 8
        &Version::parse("1.2.3").unwrap(),
135 8
    );
136

137 8
    assert!(valid);
138 8
}
139

140
#[test]
141 8
fn is_min_version_valid_for_versions_false_major() {
142 8
    let valid = is_min_version_valid_for_versions(
143 8
        &Version::parse("2.2.3").unwrap(),
144 8
        &Version::parse("1.2.3").unwrap(),
145 8
    );
146

147 8
    assert!(!valid);
148 8
}
149

150
#[test]
151 8
fn is_min_version_valid_for_versions_false_minor() {
152 8
    let valid = is_min_version_valid_for_versions(
153 8
        &Version::parse("1.3.3").unwrap(),
154 8
        &Version::parse("1.2.3").unwrap(),
155 8
    );
156

157 8
    assert!(!valid);
158 8
}
159

160
#[test]
161 8
fn is_min_version_valid_for_versions_false_patch() {
162 8
    let valid = is_min_version_valid_for_versions(
163 8
        &Version::parse("1.2.4").unwrap(),
164 8
        &Version::parse("1.2.3").unwrap(),
165 8
    );
166

167 8
    assert!(!valid);
168 8
}
169

170
#[test]
171 8
fn is_min_version_valid_for_versions_true_major() {
172 8
    let valid = is_min_version_valid_for_versions(
173 8
        &Version::parse("1.2.3").unwrap(),
174 8
        &Version::parse("2.2.3").unwrap(),
175 8
    );
176

177 8
    assert!(valid);
178 8
}
179

180
#[test]
181 8
fn is_min_version_valid_for_versions_true_minor() {
182 8
    let valid = is_min_version_valid_for_versions(
183 8
        &Version::parse("1.2.3").unwrap(),
184 8
        &Version::parse("1.3.3").unwrap(),
185 8
    );
186

187 8
    assert!(valid);
188 8
}
189

190
#[test]
191 8
fn is_min_version_valid_for_versions_true_patch() {
192 8
    let valid = is_min_version_valid_for_versions(
193 8
        &Version::parse("1.2.3").unwrap(),
194 8
        &Version::parse("1.2.4").unwrap(),
195 8
    );
196

197 8
    assert!(valid);
198 8
}
199

200
#[test]
201 8
fn is_min_version_valid_not_found() {
202 8
    let valid = is_min_version_valid("bad_crate", "1.2.3");
203

204 8
    assert!(valid);
205 8
}
206

207
#[test]
208 8
fn is_min_version_valid_invalid_version() {
209 8
    let valid = is_min_version_valid("cargo-make", "bad_version");
210

211 8
    assert!(valid);
212 8
}
213

214
#[test]
215 8
fn is_min_version_valid_old_version() {
216 8
    let valid = is_min_version_valid("cargo-make", "0.0.1");
217

218 8
    assert!(valid);
219 8
}
220

221
#[test]
222 8
fn is_min_version_valid_newer_version() {
223 8
    let valid = is_min_version_valid("cargo-make", "10000.0.0");
224

225 8
    assert!(!valid);
226 8
}
227

228
#[test]
229 8
fn is_min_version_valid_same_version() {
230 8
    let version = get_crate_version("cargo-make").unwrap();
231 8
    let mut version_string = String::new();
232 8
    version_string.push_str(&version.major.to_string());
233 8
    version_string.push_str(".");
234 8
    version_string.push_str(&version.minor.to_string());
235 8
    version_string.push_str(".");
236 8
    version_string.push_str(&version.patch.to_string());
237

238 8
    let valid = is_min_version_valid("cargo-make", &version_string);
239

240 8
    assert!(valid);
241 8
}

Read our documentation on viewing source code .

Loading