Skip to content

Commit b8bc007

Browse files
chansukepetrochenkov
authored andcommitted
Separate librustc_metadata module
1 parent b926679 commit b8bc007

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

src/librustc_metadata/dynamic_lib.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -74,55 +74,7 @@ impl DynamicLibrary {
7474
}
7575

7676
#[cfg(test)]
77-
mod tests {
78-
use super::*;
79-
use std::mem;
80-
81-
#[test]
82-
fn test_loading_atoi() {
83-
if cfg!(windows) {
84-
return
85-
}
86-
87-
// The C library does not need to be loaded since it is already linked in
88-
let lib = match DynamicLibrary::open(None) {
89-
Err(error) => panic!("Could not load self as module: {}", error),
90-
Ok(lib) => lib
91-
};
92-
93-
let atoi: extern fn(*const libc::c_char) -> libc::c_int = unsafe {
94-
match lib.symbol("atoi") {
95-
Err(error) => panic!("Could not load function atoi: {}", error),
96-
Ok(atoi) => mem::transmute::<*mut u8, _>(atoi)
97-
}
98-
};
99-
100-
let argument = CString::new("1383428980").unwrap();
101-
let expected_result = 0x52757374;
102-
let result = atoi(argument.as_ptr());
103-
if result != expected_result {
104-
panic!("atoi({:?}) != {} but equaled {} instead", argument,
105-
expected_result, result)
106-
}
107-
}
108-
109-
#[test]
110-
fn test_errors_do_not_crash() {
111-
use std::path::Path;
112-
113-
if !cfg!(unix) {
114-
return
115-
}
116-
117-
// Open /dev/null as a library to get an error, and make sure
118-
// that only causes an error, and not a crash.
119-
let path = Path::new("/dev/null");
120-
match DynamicLibrary::open(Some(&path)) {
121-
Err(_) => {}
122-
Ok(_) => panic!("Successfully opened the empty library.")
123-
}
124-
}
125-
}
77+
mod tests;
12678

12779
#[cfg(unix)]
12880
mod dl {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use super::*;
2+
use std::mem;
3+
4+
#[test]
5+
fn test_loading_atoi() {
6+
if cfg!(windows) {
7+
return
8+
}
9+
10+
// The C library does not need to be loaded since it is already linked in
11+
let lib = match DynamicLibrary::open(None) {
12+
Err(error) => panic!("Could not load self as module: {}", error),
13+
Ok(lib) => lib
14+
};
15+
16+
let atoi: extern fn(*const libc::c_char) -> libc::c_int = unsafe {
17+
match lib.symbol("atoi") {
18+
Err(error) => panic!("Could not load function atoi: {}", error),
19+
Ok(atoi) => mem::transmute::<*mut u8, _>(atoi)
20+
}
21+
};
22+
23+
let argument = CString::new("1383428980").unwrap();
24+
let expected_result = 0x52757374;
25+
let result = atoi(argument.as_ptr());
26+
if result != expected_result {
27+
panic!("atoi({:?}) != {} but equaled {} instead", argument,
28+
expected_result, result)
29+
}
30+
}
31+
32+
#[test]
33+
fn test_errors_do_not_crash() {
34+
use std::path::Path;
35+
36+
if !cfg!(unix) {
37+
return
38+
}
39+
40+
// Open /dev/null as a library to get an error, and make sure
41+
// that only causes an error, and not a crash.
42+
let path = Path::new("/dev/null");
43+
match DynamicLibrary::open(Some(&path)) {
44+
Err(_) => {}
45+
Ok(_) => panic!("Successfully opened the empty library.")
46+
}
47+
}

0 commit comments

Comments
 (0)