Skip to content

Commit 87b5cbc

Browse files
committed
expand helpers tests with new test module tests/helpers
Signed-off-by: onur-ozkan <[email protected]>
1 parent 3ea3c38 commit 87b5cbc

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

src/bootstrap/src/tests/builder.rs

-16
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@ fn alias_and_path_for_library() {
156156
assert_eq!(first(cache.all::<doc::Std>()), &[doc_std!(A => A, stage = 0)]);
157157
}
158158

159-
#[test]
160-
fn test_beta_rev_parsing() {
161-
use crate::utils::helpers::extract_beta_rev;
162-
163-
// single digit revision
164-
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
165-
// multiple digits
166-
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
167-
// nightly channel (no beta revision)
168-
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
169-
// stable channel (no beta revision)
170-
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
171-
// invalid string
172-
assert_eq!(extract_beta_rev("invalid"), None);
173-
}
174-
175159
mod defaults {
176160
use super::{configure, first, run_build};
177161
use crate::core::builder::*;

src/bootstrap/src/tests/helpers.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::utils::helpers::{extract_beta_rev, hex_encode, make};
2+
use std::{env, path::PathBuf};
3+
4+
#[test]
5+
fn test_make() {
6+
for (host, make_path) in vec![
7+
("dragonfly", PathBuf::from("gmake")),
8+
("netbsd", PathBuf::from("gmake")),
9+
("freebsd", PathBuf::from("gmake")),
10+
("openbsd", PathBuf::from("gmake")),
11+
("linux", PathBuf::from("make")),
12+
// for checking the default
13+
("_", PathBuf::from("make")),
14+
] {
15+
assert_eq!(make(host), make_path);
16+
}
17+
}
18+
19+
#[cfg(unix)]
20+
#[test]
21+
fn test_absolute_unix() {
22+
use crate::utils::helpers::absolute_unix;
23+
24+
// Test an absolute path
25+
let path = PathBuf::from("/home/user/file.txt");
26+
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("/home/user/file.txt"));
27+
28+
// Test an absolute path with double leading slashes
29+
let path = PathBuf::from("//root//file.txt");
30+
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("//root/file.txt"));
31+
32+
// Test a relative path
33+
let path = PathBuf::from("relative/path");
34+
assert_eq!(absolute_unix(&path).unwrap(), env::current_dir().unwrap().join("relative/path"));
35+
}
36+
37+
#[test]
38+
fn test_beta_rev_parsing() {
39+
// single digit revision
40+
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
41+
// multiple digits
42+
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
43+
// nightly channel (no beta revision)
44+
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
45+
// stable channel (no beta revision)
46+
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
47+
// invalid string
48+
assert_eq!(extract_beta_rev("invalid"), None);
49+
}
50+
51+
#[test]
52+
fn test_string_to_hex_encode() {
53+
let input_string = "Hello, World!";
54+
let hex_string = hex_encode(input_string);
55+
assert_eq!(hex_string, "48656c6c6f2c20576f726c6421");
56+
}

src/bootstrap/src/utils/helpers.rs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use crate::LldMode;
2020

2121
pub use crate::utils::dylib::{dylib_path, dylib_path_var};
2222

23+
#[cfg(test)]
24+
#[path = "../tests/helpers.rs"]
25+
mod tests;
26+
2327
/// A helper macro to `unwrap` a result except also print out details like:
2428
///
2529
/// * The file/line of the panic

0 commit comments

Comments
 (0)