Skip to content

Commit 6ef3a64

Browse files
committed
add test_proc_macro library and use it in the test
1 parent f8f05b0 commit 6ef3a64

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ proc-macro2 = "0.4.29"
99
dylib = "0.0.3"
1010
goblin = "0.0.22"
1111
syn = "0.15.33"
12-
tempfile = "3"
12+
tempfile = "3"
13+
test_proc_macro = { path = "./test_proc_macro"}

src/main.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,29 @@ fn compile_proc_macro(dir: &PathBuf) -> io::Result<PathBuf> {
123123
}
124124
}
125125

126+
fn find_test_proc_macro() -> io::Result<PathBuf> {
127+
let mut test_exe = std::env::current_exe()?;
128+
test_exe.pop();
129+
130+
for entry in fs::read_dir(&test_exe)? {
131+
let entry = entry?;
132+
let name = entry.file_name().to_str().unwrap().to_string();
133+
if entry.path().is_file()
134+
&& name.starts_with("libtest_proc_macro")
135+
&& name.ends_with(".so") {
136+
return Ok(entry.path());
137+
}
138+
}
139+
140+
Err(io::Error::from(ErrorKind::NotFound))
141+
}
142+
126143
#[test]
127144
fn test_getset_expansion() -> io::Result<()> {
128-
let tmp_dir = TempDir::new()?;
129-
setup_temp_proc_macro_project(&tmp_dir.path().to_path_buf())?;
130-
let proc_macro_lib = canonicalize(compile_proc_macro(&tmp_dir.path().to_path_buf())?)?;
145+
// let tmp_dir = TempDir::new()?;
146+
// setup_temp_proc_macro_project(&tmp_dir.path().to_path_buf())?;
147+
// let proc_macro_lib = canonicalize(compile_proc_macro(&tmp_dir.path().to_path_buf())?)?;
148+
let proc_macro_lib = find_test_proc_macro()?;
131149

132150
let symbol_name = find_registrar_symbol(&proc_macro_lib).expect(
133151
&format!("Cannot find registrar symbol in file {:?}", &proc_macro_lib)

test_proc_macro/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "test_proc_macro"
3+
version = "0.1.0"
4+
5+
[lib]
6+
proc-macro = true
7+
8+
[dependencies]

test_proc_macro/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern crate proc_macro;
2+
3+
use proc_macro::TokenStream;
4+
5+
#[proc_macro]
6+
pub fn make_answer_macro(input: TokenStream) -> TokenStream {
7+
"fn answer() -> u32 { 42 }".parse().unwrap()
8+
}

0 commit comments

Comments
 (0)