Skip to content

Commit

Permalink
Add a proc-macro UI test example to the test project
Browse files Browse the repository at this point in the history
Taken from work on rust-lang/rust-clippy#3741.

I think this is a useful test to have because it tests

* the `run-pass` header
* the `aux-build` header, building auxiliary files
* the `no-prefer-dynamic` header
* proc-macro crate interactions with all of the above
* running of UI tests that include auxiliary files

There's no tests for any of the above right now.
  • Loading branch information
phansch committed Aug 21, 2019
1 parent 3cbd33a commit 4f1f614
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
12 changes: 12 additions & 0 deletions test-project/tests/nightly/auxiliary/simple_proc_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::{TokenStream};

#[proc_macro]
pub fn macro_test(input_stream: TokenStream) -> TokenStream {
TokenStream::new()
}
13 changes: 13 additions & 0 deletions test-project/tests/nightly/some-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-pass
// aux-build:simple_proc_macro.rs

#![feature(proc_macro_hygiene)]

extern crate simple_proc_macro;
use simple_proc_macro::macro_test;

fn main() {
println!("hi");
macro_test!(2);
}

17 changes: 10 additions & 7 deletions test-project/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ extern crate compiletest_rs as compiletest;

use std::path::PathBuf;

fn run_mode(mode: &'static str) {

fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) {
let mut config = compiletest::Config::default().tempdir();
let cfg_mode = mode.parse().expect("Invalid mode");

config.mode = cfg_mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));

let dir = custom_dir.unwrap_or(mode);
config.src_base = PathBuf::from(format!("tests/{}", dir));
config.target_rustcflags = Some("-L target/debug -L target/debug/deps".to_string());
config.clean_rmeta();

Expand All @@ -17,10 +18,12 @@ fn run_mode(mode: &'static str) {

#[test]
fn compile_test() {
run_mode("compile-fail");
run_mode("run-pass");
run_mode("ui");
run_mode("compile-fail", None);
run_mode("run-pass", None);
run_mode("ui", None);

#[cfg(not(feature = "stable"))]
run_mode("pretty");
run_mode("pretty", None);
#[cfg(not(feature = "stable"))]
run_mode("ui", Some("nightly"));
}

0 comments on commit 4f1f614

Please sign in to comment.