about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorKeegan McAllister <kmcallister@mozilla.com>2015-01-02 18:26:00 -0800
committerKeegan McAllister <kmcallister@mozilla.com>2015-01-05 18:21:14 -0800
commitd0163d3311f0afe7b8dc3b70dba8aa32f318225c (patch)
treef1df9638e6658cd81536548ec99158e76838c4ce /src/test
parent416137eb3186c05b7a601e94cde354e9b3ec0a78 (diff)
downloadrust-d0163d3311f0afe7b8dc3b70dba8aa32f318225c.tar.gz
rust-d0163d3311f0afe7b8dc3b70dba8aa32f318225c.zip
Pass the #[plugin(...)] meta item to the registrar
Diffstat (limited to 'src/test')
-rw-r--r--src/test/auxiliary/plugin_args.rs50
-rw-r--r--src/test/compile-fail/multi-plugin-attr.rs15
-rw-r--r--src/test/run-pass/plugin-args-1.rs22
-rw-r--r--src/test/run-pass/plugin-args-2.rs22
-rw-r--r--src/test/run-pass/plugin-args-3.rs22
-rw-r--r--src/test/run-pass/plugin-args-4.rs22
6 files changed, 153 insertions, 0 deletions
diff --git a/src/test/auxiliary/plugin_args.rs b/src/test/auxiliary/plugin_args.rs
new file mode 100644
index 00000000000..b90c3f1d727
--- /dev/null
+++ b/src/test/auxiliary/plugin_args.rs
@@ -0,0 +1,50 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// force-host
+
+#![feature(plugin_registrar)]
+
+extern crate syntax;
+extern crate rustc;
+
+use std::borrow::ToOwned;
+use syntax::ast;
+use syntax::codemap::Span;
+use syntax::ext::build::AstBuilder;
+use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacExpr, NormalTT};
+use syntax::parse::token;
+use syntax::print::pprust;
+use syntax::ptr::P;
+use rustc::plugin::Registry;
+
+struct Expander {
+    args: P<ast::MetaItem>,
+}
+
+impl TTMacroExpander for Expander {
+    fn expand<'cx>(&self,
+                   ecx: &'cx mut ExtCtxt,
+                   sp: Span,
+                   _: &[ast::TokenTree]) -> Box<MacResult+'cx> {
+
+        let attr = ecx.attribute(sp, self.args.clone());
+        let src = pprust::attribute_to_string(&attr);
+        let interned = token::intern_and_get_ident(src.as_slice());
+        MacExpr::new(ecx.expr_str(sp, interned))
+    }
+}
+
+#[plugin_registrar]
+pub fn plugin_registrar(reg: &mut Registry) {
+    let args = reg.args().clone();
+    reg.register_syntax_extension(token::intern("plugin_args"),
+        NormalTT(box Expander { args: args, }, None));
+}
diff --git a/src/test/compile-fail/multi-plugin-attr.rs b/src/test/compile-fail/multi-plugin-attr.rs
new file mode 100644
index 00000000000..1d98cd26a38
--- /dev/null
+++ b/src/test/compile-fail/multi-plugin-attr.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[plugin]
+#[plugin]  //~ ERROR #[plugin] specified multiple times
+extern crate std;
+
+fn main() {}
diff --git a/src/test/run-pass/plugin-args-1.rs b/src/test/run-pass/plugin-args-1.rs
new file mode 100644
index 00000000000..5a91f603f96
--- /dev/null
+++ b/src/test/run-pass/plugin-args-1.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:plugin_args.rs
+// ignore-stage1
+
+#![feature(plugin)]
+
+#[no_link]
+#[plugin]
+extern crate plugin_args;
+
+fn main() {
+    assert_eq!(plugin_args!(), "#[plugin]");
+}
diff --git a/src/test/run-pass/plugin-args-2.rs b/src/test/run-pass/plugin-args-2.rs
new file mode 100644
index 00000000000..d0ac22a5290
--- /dev/null
+++ b/src/test/run-pass/plugin-args-2.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:plugin_args.rs
+// ignore-stage1
+
+#![feature(plugin)]
+
+#[no_link]
+#[plugin()]
+extern crate plugin_args;
+
+fn main() {
+    assert_eq!(plugin_args!(), "#[plugin()]");
+}
diff --git a/src/test/run-pass/plugin-args-3.rs b/src/test/run-pass/plugin-args-3.rs
new file mode 100644
index 00000000000..7cac8ac57e5
--- /dev/null
+++ b/src/test/run-pass/plugin-args-3.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:plugin_args.rs
+// ignore-stage1
+
+#![feature(plugin)]
+
+#[no_link]
+#[plugin(hello(there), how(are="you"))]
+extern crate plugin_args;
+
+fn main() {
+    assert_eq!(plugin_args!(), "#[plugin(hello(there), how(are = \"you\"))]");
+}
diff --git a/src/test/run-pass/plugin-args-4.rs b/src/test/run-pass/plugin-args-4.rs
new file mode 100644
index 00000000000..8563c8c178f
--- /dev/null
+++ b/src/test/run-pass/plugin-args-4.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:plugin_args.rs
+// ignore-stage1
+
+#![feature(plugin)]
+
+#[no_link]
+#[plugin="foobar"]
+extern crate plugin_args;
+
+fn main() {
+    assert_eq!(plugin_args!(), "#[plugin = \"foobar\"]");
+}