Add compile-test (#38)

This commit is contained in:
messense 2017-06-18 23:41:20 +08:00 committed by GitHub
parent 75d6684d25
commit 93b1dd8262
5 changed files with 50 additions and 1 deletions

View File

@ -23,6 +23,9 @@ num-traits = "0.1"
pyo3cls = { path = "pyo3cls" } pyo3cls = { path = "pyo3cls" }
# backtrace = "0.3" # backtrace = "0.3"
[dev-dependencies]
compiletest_rs = "*"
[build-dependencies] [build-dependencies]
regex = "0.2" regex = "0.2"

View File

@ -25,7 +25,7 @@ pub fn build_py_class(ast: &mut syn::DeriveInput, attr: String) -> Tokens {
} }
} }
}, },
_ => panic!("#[class] can only be used with notmal structs"), _ => panic!("#[class] can only be used with normal structs"),
} }
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_CLS_{}", ast.ident)); let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_CLS_{}", ast.ident));

View File

@ -0,0 +1,12 @@
#![feature(proc_macro)]
extern crate pyo3;
use pyo3::{py, PyResult, Python, PyModule};
#[py::class]
//~^ ERROR: custom attribute panicked
//~^^ HELP: #[class] can only be used with normal structs
enum MyClass {
A,
B,
}

View File

@ -0,0 +1,9 @@
#![feature(proc_macro)]
extern crate pyo3;
use pyo3::{py, PyResult, Python, PyModule};
#[py::modinit(rust2py)]
//~^ ERROR: custom attribute panicked
//~^^ HELP: #[modinit] can only be used with fn block
struct Rust2Py;

25
tests/compile_tests.rs Normal file
View File

@ -0,0 +1,25 @@
extern crate compiletest_rs as compiletest;
use std::path::PathBuf;
use std::env::var;
fn run_mode(mode: &'static str) {
let mut config = compiletest::default_config();
let cfg_mode = mode.parse().ok().expect("Invalid mode");
config.target_rustcflags = Some("-L target/debug/deps/".to_string());
config.mode = cfg_mode;
if let Ok(name) = var::<&str>("TESTNAME") {
let s : String = name.to_string();
config.filter = Some(s)
}
config.src_base = PathBuf::from(format!("tests/{}", mode));
compiletest::run_tests(&config);
}
#[test]
fn compile_tests() {
run_mode("compile-fail");
// run_mode("run-pass");
}