Skip to content

Commit baedc3b

Browse files
committed
Tests
1 parent 534556a commit baedc3b

File tree

9 files changed

+153
-2
lines changed

9 files changed

+153
-2
lines changed

src/librustc_driver/driver.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
11851185
Some(ref n) if *n == "rlib" => {
11861186
Some(config::CrateTypeRlib)
11871187
}
1188+
Some(ref n) if *n == "metadata" => {
1189+
Some(config::CrateTypeMetadata)
1190+
}
11881191
Some(ref n) if *n == "dylib" => {
11891192
Some(config::CrateTypeDylib)
11901193
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// no-prefer-dynamic
12+
13+
#![crate_type="metadata"]
14+
15+
pub struct Foo {
16+
pub field: i32,
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="rlib"]
12+
13+
pub struct Foo {
14+
pub field: i32,
15+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rmeta_rlib.rs
12+
// no-prefer-dynamic
13+
// must-compile-successfully
14+
15+
// Check that building a metadata crate works with a dependent, rlib crate.
16+
// This is a cfail test since there is no executable to run.
17+
18+
#![crate_type="metadata"]
19+
20+
extern crate rmeta_rlib;
21+
use rmeta_rlib::Foo;
22+
23+
pub fn main() {
24+
let _ = Foo { field: 42 };
25+
}

src/test/compile-fail/rmeta-pass.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rmeta_meta.rs
12+
// no-prefer-dynamic
13+
// must-compile-successfully
14+
15+
// Check that building a metadata crate works with a dependent, metadata-only
16+
// crate.
17+
// This is a cfail test since there is no executable to run.
18+
19+
#![crate_type="metadata"]
20+
21+
extern crate rmeta_meta;
22+
use rmeta_meta::Foo;
23+
24+
pub fn main() {
25+
let _ = Foo { field: 42 };
26+
}

src/test/compile-fail/rmeta.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// no-prefer-dynamic
12+
13+
// Check that building a metadata crate finds an error.
14+
15+
#![crate_type="metadata"]
16+
17+
fn main() {
18+
let _ = Foo; //~ ERROR unresolved name `Foo`
19+
}

src/test/compile-fail/rmeta_lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rmeta_meta.rs
12+
// no-prefer-dynamic
13+
// error-pattern: crate `rmeta_meta` required to be available in rlib, but it was not available
14+
15+
// Check that building a non-metadata crate fails if a dependent crate is
16+
// metadata-only.
17+
18+
extern crate rmeta_meta;
19+
use rmeta_meta::Foo;
20+
21+
fn main() {
22+
let _ = Foo { field: 42 };
23+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rmeta_meta.rs
12+
// no-prefer-dynamic
13+
14+
// Check that building a metadata crate finds an error with a dependent,
15+
// metadata-only crate.
16+
17+
#![crate_type="metadata"]
18+
19+
extern crate rmeta_meta;
20+
use rmeta_meta::Foo;
21+
22+
fn main() {
23+
let _ = Foo { field2: 42 }; //~ ERROR struct `rmeta_meta::Foo` has no field named `field2`
24+
}

src/tools/compiletest/src/runtest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ actual:\n\
396396

397397
// FIXME (#9639): This needs to handle non-utf8 paths
398398
let mut args = vec!["-".to_owned(),
399-
"--emit".to_owned(),
400-
"metadata".to_owned(),
399+
"-Zno-trans".to_owned(),
401400
"--out-dir".to_owned(),
402401
out_dir.to_str().unwrap().to_owned(),
403402
format!("--target={}", target),

0 commit comments

Comments
 (0)