Skip to content

Commit 310b9fc

Browse files
committed
libsyntax: Unconfigure tests during normal build
1 parent a332e22 commit 310b9fc

File tree

22 files changed

+1277
-1303
lines changed

22 files changed

+1277
-1303
lines changed

src/libsyntax/ast.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use std::fmt;
2727

2828
pub use rustc_target::abi::FloatTy;
2929

30+
#[cfg(test)]
31+
mod tests;
32+
3033
#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
3134
pub struct Label {
3235
pub ident: Ident,
@@ -2432,15 +2435,3 @@ impl ForeignItemKind {
24322435
}
24332436
}
24342437
}
2435-
2436-
#[cfg(test)]
2437-
mod tests {
2438-
use super::*;
2439-
2440-
// Are ASTs encodable?
2441-
#[test]
2442-
fn check_asts_encodable() {
2443-
fn assert_encodable<T: rustc_serialize::Encodable>() {}
2444-
assert_encodable::<Crate>();
2445-
}
2446-
}

src/libsyntax/ast/tests.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
// Are ASTs encodable?
4+
#[test]
5+
fn check_asts_encodable() {
6+
fn assert_encodable<T: rustc_serialize::Encodable>() {}
7+
assert_encodable::<Crate>();
8+
}

src/libsyntax/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub use rustc_data_structures::thin_vec::ThinVec;
3333
use ast::AttrId;
3434
use syntax_pos::edition::Edition;
3535

36+
#[cfg(test)]
37+
mod tests;
38+
3639
const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
3740

3841
// A variant of 'try!' that panics on an Err. This is used as a crutch on the
@@ -132,8 +135,6 @@ pub mod util {
132135
pub mod lev_distance;
133136
pub mod node_count;
134137
pub mod parser;
135-
#[cfg(test)]
136-
pub mod parser_testing;
137138
pub mod map_in_place;
138139
}
139140

@@ -183,7 +184,4 @@ pub mod ext {
183184

184185
pub mod early_buffered_lints;
185186

186-
#[cfg(test)]
187-
mod test_snippet;
188-
189187
__build_diagnostic_array! { libsyntax, DIAGNOSTICS }

src/libsyntax/mut_visit.rs

+3-74
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use rustc_data_structures::sync::Lrc;
2222
use std::ops::DerefMut;
2323
use std::{panic, process, ptr};
2424

25+
#[cfg(test)]
26+
mod tests;
27+
2528
pub trait ExpectOne<A: Array> {
2629
fn expect_one(self, err: &'static str) -> A::Item;
2730
}
@@ -1255,77 +1258,3 @@ pub fn noop_visit_vis<T: MutVisitor>(Spanned { node, span }: &mut Visibility, vi
12551258
}
12561259
vis.visit_span(span);
12571260
}
1258-
1259-
#[cfg(test)]
1260-
mod tests {
1261-
use crate::ast::{self, Ident};
1262-
use crate::util::parser_testing::{string_to_crate, matches_codepattern};
1263-
use crate::print::pprust;
1264-
use crate::mut_visit;
1265-
use crate::with_default_globals;
1266-
use super::*;
1267-
1268-
// this version doesn't care about getting comments or docstrings in.
1269-
fn fake_print_crate(s: &mut pprust::State<'_>,
1270-
krate: &ast::Crate) {
1271-
s.print_mod(&krate.module, &krate.attrs)
1272-
}
1273-
1274-
// change every identifier to "zz"
1275-
struct ToZzIdentMutVisitor;
1276-
1277-
impl MutVisitor for ToZzIdentMutVisitor {
1278-
fn visit_ident(&mut self, ident: &mut ast::Ident) {
1279-
*ident = Ident::from_str("zz");
1280-
}
1281-
fn visit_mac(&mut self, mac: &mut ast::Mac) {
1282-
mut_visit::noop_visit_mac(mac, self)
1283-
}
1284-
}
1285-
1286-
// maybe add to expand.rs...
1287-
macro_rules! assert_pred {
1288-
($pred:expr, $predname:expr, $a:expr , $b:expr) => (
1289-
{
1290-
let pred_val = $pred;
1291-
let a_val = $a;
1292-
let b_val = $b;
1293-
if !(pred_val(&a_val, &b_val)) {
1294-
panic!("expected args satisfying {}, got {} and {}",
1295-
$predname, a_val, b_val);
1296-
}
1297-
}
1298-
)
1299-
}
1300-
1301-
// make sure idents get transformed everywhere
1302-
#[test] fn ident_transformation () {
1303-
with_default_globals(|| {
1304-
let mut zz_visitor = ToZzIdentMutVisitor;
1305-
let mut krate = string_to_crate(
1306-
"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
1307-
zz_visitor.visit_crate(&mut krate);
1308-
assert_pred!(
1309-
matches_codepattern,
1310-
"matches_codepattern",
1311-
pprust::to_string(|s| fake_print_crate(s, &krate)),
1312-
"#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string());
1313-
})
1314-
}
1315-
1316-
// even inside macro defs....
1317-
#[test] fn ident_transformation_in_defs () {
1318-
with_default_globals(|| {
1319-
let mut zz_visitor = ToZzIdentMutVisitor;
1320-
let mut krate = string_to_crate(
1321-
"macro_rules! a {(b $c:expr $(d $e:token)f+ => \
1322-
(g $(d $d $e)+))} ".to_string());
1323-
zz_visitor.visit_crate(&mut krate);
1324-
assert_pred!(
1325-
matches_codepattern,
1326-
"matches_codepattern",
1327-
pprust::to_string(|s| fake_print_crate(s, &krate)),
1328-
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
1329-
})
1330-
}
1331-
}

src/libsyntax/mut_visit/tests.rs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use super::*;
2+
3+
use crate::ast::{self, Ident};
4+
use crate::tests::{string_to_crate, matches_codepattern};
5+
use crate::print::pprust;
6+
use crate::mut_visit;
7+
use crate::with_default_globals;
8+
9+
// this version doesn't care about getting comments or docstrings in.
10+
fn fake_print_crate(s: &mut pprust::State<'_>,
11+
krate: &ast::Crate) {
12+
s.print_mod(&krate.module, &krate.attrs)
13+
}
14+
15+
// change every identifier to "zz"
16+
struct ToZzIdentMutVisitor;
17+
18+
impl MutVisitor for ToZzIdentMutVisitor {
19+
fn visit_ident(&mut self, ident: &mut ast::Ident) {
20+
*ident = Ident::from_str("zz");
21+
}
22+
fn visit_mac(&mut self, mac: &mut ast::Mac) {
23+
mut_visit::noop_visit_mac(mac, self)
24+
}
25+
}
26+
27+
// maybe add to expand.rs...
28+
macro_rules! assert_pred {
29+
($pred:expr, $predname:expr, $a:expr , $b:expr) => (
30+
{
31+
let pred_val = $pred;
32+
let a_val = $a;
33+
let b_val = $b;
34+
if !(pred_val(&a_val, &b_val)) {
35+
panic!("expected args satisfying {}, got {} and {}",
36+
$predname, a_val, b_val);
37+
}
38+
}
39+
)
40+
}
41+
42+
// make sure idents get transformed everywhere
43+
#[test] fn ident_transformation () {
44+
with_default_globals(|| {
45+
let mut zz_visitor = ToZzIdentMutVisitor;
46+
let mut krate = string_to_crate(
47+
"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
48+
zz_visitor.visit_crate(&mut krate);
49+
assert_pred!(
50+
matches_codepattern,
51+
"matches_codepattern",
52+
pprust::to_string(|s| fake_print_crate(s, &krate)),
53+
"#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string());
54+
})
55+
}
56+
57+
// even inside macro defs....
58+
#[test] fn ident_transformation_in_defs () {
59+
with_default_globals(|| {
60+
let mut zz_visitor = ToZzIdentMutVisitor;
61+
let mut krate = string_to_crate(
62+
"macro_rules! a {(b $c:expr $(d $e:token)f+ => \
63+
(g $(d $d $e)+))} ".to_string());
64+
zz_visitor.visit_crate(&mut krate);
65+
assert_pred!(
66+
matches_codepattern,
67+
"matches_codepattern",
68+
pprust::to_string(|s| fake_print_crate(s, &krate)),
69+
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
70+
})
71+
}

src/libsyntax/parse/lexer/comments.rs

+3-51
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use syntax_pos::{BytePos, CharPos, Pos, FileName};
99

1010
use std::usize;
1111

12+
#[cfg(test)]
13+
mod tests;
14+
1215
#[derive(Clone, Copy, PartialEq, Debug)]
1316
pub enum CommentStyle {
1417
/// No code on either side of each line of the comment
@@ -249,54 +252,3 @@ pub fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec<Com
249252

250253
comments
251254
}
252-
253-
#[cfg(test)]
254-
mod tests {
255-
use super::*;
256-
257-
#[test]
258-
fn test_block_doc_comment_1() {
259-
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
260-
let stripped = strip_doc_comment_decoration(comment);
261-
assert_eq!(stripped, " Test \n* Test\n Test");
262-
}
263-
264-
#[test]
265-
fn test_block_doc_comment_2() {
266-
let comment = "/**\n * Test\n * Test\n*/";
267-
let stripped = strip_doc_comment_decoration(comment);
268-
assert_eq!(stripped, " Test\n Test");
269-
}
270-
271-
#[test]
272-
fn test_block_doc_comment_3() {
273-
let comment = "/**\n let a: *i32;\n *a = 5;\n*/";
274-
let stripped = strip_doc_comment_decoration(comment);
275-
assert_eq!(stripped, " let a: *i32;\n *a = 5;");
276-
}
277-
278-
#[test]
279-
fn test_block_doc_comment_4() {
280-
let comment = "/*******************\n test\n *********************/";
281-
let stripped = strip_doc_comment_decoration(comment);
282-
assert_eq!(stripped, " test");
283-
}
284-
285-
#[test]
286-
fn test_line_doc_comment() {
287-
let stripped = strip_doc_comment_decoration("/// test");
288-
assert_eq!(stripped, " test");
289-
let stripped = strip_doc_comment_decoration("///! test");
290-
assert_eq!(stripped, " test");
291-
let stripped = strip_doc_comment_decoration("// test");
292-
assert_eq!(stripped, " test");
293-
let stripped = strip_doc_comment_decoration("// test");
294-
assert_eq!(stripped, " test");
295-
let stripped = strip_doc_comment_decoration("///test");
296-
assert_eq!(stripped, "test");
297-
let stripped = strip_doc_comment_decoration("///!test");
298-
assert_eq!(stripped, "test");
299-
let stripped = strip_doc_comment_decoration("//test");
300-
assert_eq!(stripped, "test");
301-
}
302-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_block_doc_comment_1() {
5+
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
6+
let stripped = strip_doc_comment_decoration(comment);
7+
assert_eq!(stripped, " Test \n* Test\n Test");
8+
}
9+
10+
#[test]
11+
fn test_block_doc_comment_2() {
12+
let comment = "/**\n * Test\n * Test\n*/";
13+
let stripped = strip_doc_comment_decoration(comment);
14+
assert_eq!(stripped, " Test\n Test");
15+
}
16+
17+
#[test]
18+
fn test_block_doc_comment_3() {
19+
let comment = "/**\n let a: *i32;\n *a = 5;\n*/";
20+
let stripped = strip_doc_comment_decoration(comment);
21+
assert_eq!(stripped, " let a: *i32;\n *a = 5;");
22+
}
23+
24+
#[test]
25+
fn test_block_doc_comment_4() {
26+
let comment = "/*******************\n test\n *********************/";
27+
let stripped = strip_doc_comment_decoration(comment);
28+
assert_eq!(stripped, " test");
29+
}
30+
31+
#[test]
32+
fn test_line_doc_comment() {
33+
let stripped = strip_doc_comment_decoration("/// test");
34+
assert_eq!(stripped, " test");
35+
let stripped = strip_doc_comment_decoration("///! test");
36+
assert_eq!(stripped, " test");
37+
let stripped = strip_doc_comment_decoration("// test");
38+
assert_eq!(stripped, " test");
39+
let stripped = strip_doc_comment_decoration("// test");
40+
assert_eq!(stripped, " test");
41+
let stripped = strip_doc_comment_decoration("///test");
42+
assert_eq!(stripped, "test");
43+
let stripped = strip_doc_comment_decoration("///!test");
44+
assert_eq!(stripped, "test");
45+
let stripped = strip_doc_comment_decoration("//test");
46+
assert_eq!(stripped, "test");
47+
}

0 commit comments

Comments
 (0)