From daef3b9b53559b4c176b0a02db0f2c4fb8232c20 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 2 Mar 2015 13:21:40 -0800 Subject: [PATCH] Add regression tests for #15778 Fixes #15778. --- src/test/auxiliary/lint_for_crate.rs | 43 +++++++++++++++++++ .../compile-fail-fulldeps/issue-15778-fail.rs | 18 ++++++++ .../run-pass-fulldeps/issue-15778-pass.rs | 19 ++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/test/auxiliary/lint_for_crate.rs create mode 100644 src/test/compile-fail-fulldeps/issue-15778-fail.rs create mode 100644 src/test/run-pass-fulldeps/issue-15778-pass.rs diff --git a/src/test/auxiliary/lint_for_crate.rs b/src/test/auxiliary/lint_for_crate.rs new file mode 100644 index 0000000000000..1be37ce1780b3 --- /dev/null +++ b/src/test/auxiliary/lint_for_crate.rs @@ -0,0 +1,43 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host + +#![feature(plugin_registrar)] +#![feature(box_syntax)] + +extern crate syntax; +#[macro_use] extern crate rustc; + +use syntax::{ast, attr}; +use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; +use rustc::plugin::Registry; + +declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]"); + +struct Pass; + +impl LintPass for Pass { + fn get_lints(&self) -> LintArray { + lint_array!(CRATE_NOT_OKAY) + } + + fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) { + if !attr::contains_name(&krate.attrs, "crate_okay") { + cx.span_lint(CRATE_NOT_OKAY, krate.span, + "crate is not marked with #![crate_okay]"); + } + } +} + +#[plugin_registrar] +pub fn plugin_registrar(reg: &mut Registry) { + reg.register_lint_pass(box Pass as LintPassObject); +} diff --git a/src/test/compile-fail-fulldeps/issue-15778-fail.rs b/src/test/compile-fail-fulldeps/issue-15778-fail.rs new file mode 100644 index 0000000000000..8c6889f715fc0 --- /dev/null +++ b/src/test/compile-fail-fulldeps/issue-15778-fail.rs @@ -0,0 +1,18 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lint_for_crate.rs +// ignore-stage1 +// compile-flags: -D crate-not-okay + +#![feature(plugin, custom_attribute)] //~ ERROR crate is not marked with #![crate_okay] +#![plugin(lint_for_crate)] + +pub fn main() { } diff --git a/src/test/run-pass-fulldeps/issue-15778-pass.rs b/src/test/run-pass-fulldeps/issue-15778-pass.rs new file mode 100644 index 0000000000000..a767779687a3d --- /dev/null +++ b/src/test/run-pass-fulldeps/issue-15778-pass.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lint_for_crate.rs +// ignore-stage1 +// compile-flags: -D crate-not-okay + +#![feature(plugin, custom_attribute)] +#![plugin(lint_for_crate)] +#![crate_okay] + +pub fn main() { }