]>
git.proxmox.com Git - cargo.git/blob - tests/testsuite/plugins.rs
318a295245e9c7fe4a8b58c201562008160dc820
4 use cargotest
::{is_nightly, rustc_host}
;
5 use cargotest
::support
::{execs, project}
;
6 use hamcrest
::assert_that
;
9 fn plugin_to_the_max() {
14 let foo
= project("foo")
37 fn main() { foo_lib::foo(); }
50 let _bar
= project("bar")
70 #![feature(plugin_registrar, rustc_private)]
72 extern crate rustc_plugin;
75 use rustc_plugin::Registry;
78 pub fn foo(_reg: &mut Registry) {
79 println!("{}", baz::baz());
84 let _baz
= project("baz")
95 crate_type = ["dylib"]
98 .file("src/lib.rs", "pub fn baz() -> i32 { 1 }")
101 assert_that(foo
.cargo("build"), execs().with_status(0));
102 assert_that(foo
.cargo("doc"), execs().with_status(0));
106 fn plugin_with_dynamic_native_dependency() {
111 let workspace
= project("ws")
116 members = ["builder", "foo"]
121 let build
= project("ws/builder")
132 crate-type = ["dylib"]
139 pub extern fn foo() {}
144 let foo
= project("ws/foo")
183 use std::path::PathBuf;
187 let src = PathBuf::from(env::var("SRC").unwrap());
188 println!("cargo:rustc-flags=-L {}/deps", src.parent().unwrap().display());
195 #![feature(plugin_registrar, rustc_private)]
196 extern crate rustc_plugin;
198 use rustc_plugin::Registry;
200 #[cfg_attr(not(target_env = "msvc"), link(name = "builder"))]
201 #[cfg_attr(target_env = "msvc", link(name = "builder.dll"))]
205 pub fn bar(_reg: &mut Registry) {
212 assert_that(build
.cargo("build"), execs().with_status(0));
214 let src
= workspace
.root().join("target/debug");
215 let lib
= fs
::read_dir(&src
)
217 .map(|s
| s
.unwrap().path())
219 let lib
= lib
.file_name().unwrap().to_str().unwrap();
220 lib
.starts_with(env
::consts
::DLL_PREFIX
) && lib
.ends_with(env
::consts
::DLL_SUFFIX
)
225 foo
.cargo("build").env("SRC", &lib
).arg("-v"),
226 execs().with_status(0),
231 fn plugin_integration() {
232 let p
= project("foo")
248 .file("build.rs", "fn main() {}")
249 .file("src/lib.rs", "")
250 .file("tests/it_works.rs", "")
253 assert_that(p
.cargo("test").arg("-v"), execs().with_status(0));
257 fn doctest_a_plugin() {
258 let p
= project("foo")
268 bar = { path = "bar" }
299 assert_that(p
.cargo("test").arg("-v"), execs().with_status(0));
304 fn native_plugin_dependency_with_custom_ar_linker() {
305 let target
= rustc_host();
307 let _foo
= project("foo")
320 .file("src/lib.rs", "")
323 let bar
= project("bar")
336 .file("src/lib.rs", "")
342 ar = "nonexistent-ar"
343 linker = "nonexistent-linker"
351 bar
.cargo("build").arg("--verbose"),
352 execs().with_stderr_contains(
354 [COMPILING] foo v0.0.1 ([..])
355 [RUNNING] `rustc [..] -C ar=nonexistent-ar -C linker=nonexistent-linker [..]`
356 [ERROR] [..]linker[..]
363 fn panic_abort_plugins() {
368 let p
= project("bar")
381 foo = { path = "foo" }
384 .file("src/lib.rs", "")
400 #![feature(rustc_private)]
406 assert_that(p
.cargo("build"), execs().with_status(0));
410 fn shared_panic_abort_plugins() {
415 let p
= project("top")
428 foo = { path = "foo" }
429 bar = { path = "bar" }
450 bar = { path = "../bar" }
456 #![feature(rustc_private)]
470 .file("bar/src/lib.rs", "")
473 assert_that(p
.cargo("build"), execs().with_status(0));