Skip to content

Commit ac9fc30

Browse files
committed
Add pretty=typed test support to compiletest and add a test for fixed size arrays.
1 parent fb22420 commit ac9fc30

File tree

4 files changed

+172
-1
lines changed

4 files changed

+172
-1
lines changed

src/compiletest/header.rs

+24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub struct TestProps {
3636
pub no_prefer_dynamic: bool,
3737
// Don't run --pretty expanded when running pretty printing tests
3838
pub no_pretty_expanded: bool,
39+
// Which pretty mode are we testing with, default to 'normal'
40+
pub pretty_mode: String,
41+
// Only compare pretty output and don't try compiling
42+
pub pretty_compare_only: bool,
3943
}
4044

4145
// Load any test directives embedded in the file
@@ -51,6 +55,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
5155
let mut check_stdout = false;
5256
let mut no_prefer_dynamic = false;
5357
let mut no_pretty_expanded = false;
58+
let mut pretty_mode = None;
59+
let mut pretty_compare_only = false;
5460
iter_header(testfile, |ln| {
5561
match parse_error_pattern(ln) {
5662
Some(ep) => error_patterns.push(ep),
@@ -85,6 +91,14 @@ pub fn load_props(testfile: &Path) -> TestProps {
8591
no_pretty_expanded = parse_no_pretty_expanded(ln);
8692
}
8793

94+
if pretty_mode.is_none() {
95+
pretty_mode = parse_pretty_mode(ln);
96+
}
97+
98+
if !pretty_compare_only {
99+
pretty_compare_only = parse_pretty_compare_only(ln);
100+
}
101+
88102
match parse_aux_build(ln) {
89103
Some(ab) => { aux_builds.push(ab); }
90104
None => {}
@@ -115,6 +129,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
115129
check_stdout: check_stdout,
116130
no_prefer_dynamic: no_prefer_dynamic,
117131
no_pretty_expanded: no_pretty_expanded,
132+
pretty_mode: pretty_mode.unwrap_or("normal".to_string()),
133+
pretty_compare_only: pretty_compare_only
118134
}
119135
}
120136

@@ -205,6 +221,14 @@ fn parse_no_pretty_expanded(line: &str) -> bool {
205221
parse_name_directive(line, "no-pretty-expanded")
206222
}
207223

224+
fn parse_pretty_mode(line: &str) -> Option<String> {
225+
parse_name_value_directive(line, "pretty-mode")
226+
}
227+
228+
fn parse_pretty_compare_only(line: &str) -> bool {
229+
parse_name_directive(line, "pretty-compare-only")
230+
}
231+
208232
fn parse_exec_env(line: &str) -> Option<(String, String)> {
209233
parse_name_value_directive(line, "exec-env").map(|nv| {
210234
// nv is either FOO or FOO=BAR

src/compiletest/runtest.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
168168
props,
169169
testfile,
170170
srcs[round].to_string(),
171-
"normal");
171+
props.pretty_mode.as_slice());
172172

173173
if !proc_res.status.success() {
174174
fatal_proc_rec(format!("pretty-printing failed in round {}",
@@ -200,6 +200,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
200200

201201
compare_source(expected.as_slice(), actual.as_slice());
202202

203+
// If we're only making sure that the output matches then just stop here
204+
if props.pretty_compare_only { return; }
205+
203206
// Finally, let's make sure it actually appears to remain valid code
204207
let proc_res = typecheck_source(config, props, testfile, actual);
205208

src/test/pretty/issue-4264.pp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#![feature(phase)]
2+
#![no_std]
3+
#![feature(globs)]
4+
#[phase(plugin, link)]
5+
extern crate std = "std";
6+
extern crate native;
7+
use std::prelude::*;
8+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
9+
// file at the top-level directory of this distribution and at
10+
// http://rust-lang.org/COPYRIGHT.
11+
//
12+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
13+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
14+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
15+
// option. This file may not be copied, modified, or distributed
16+
// except according to those terms.
17+
18+
// pretty-compare-only
19+
// pretty-mode:typed
20+
// pp-exact:issue-4264.pp
21+
22+
// #4264 fixed-length vector types
23+
24+
pub fn foo(_: [int, ..(3 as uint)]) { }
25+
26+
pub fn bar() {
27+
static FOO: uint = ((5u as uint) - (4u as uint) as uint);
28+
let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), .. 1]);
29+
30+
let _: [(), ..(1u as uint)] = ([(() as ())] as [(), .. 1]);
31+
32+
let _ =
33+
(((&((([(1i as int), (2 as int), (3 as int)] as [int, .. 3])) as
34+
[int, .. 3]) as &[int, .. 3]) as *const _ as
35+
*const [int, .. 3]) as *const [int, ..(3u as uint)] as
36+
*const [int, .. 3]);
37+
(match (() as ()) {
38+
() => {
39+
#[inline]
40+
#[allow(dead_code)]
41+
static __STATIC_FMTSTR:
42+
[::std::fmt::rt::Piece<'static>, ..(1u as uint)] =
43+
([((::std::fmt::rt::String as
44+
fn(&'static str) -> core::fmt::rt::Piece<'static>)(("test"
45+
as
46+
&'static str))
47+
as core::fmt::rt::Piece<'static>)] as
48+
[core::fmt::rt::Piece<'static>, .. 1]);
49+
let __args_vec =
50+
(&([] as &'static [core::fmt::Argument<'static>]) as
51+
&'static [core::fmt::Argument<'static>]);
52+
let __args =
53+
(unsafe {
54+
((::std::fmt::Arguments::new as
55+
unsafe fn(&'static [core::fmt::rt::Piece<'static>], &'a [core::fmt::Argument<'a>]) -> core::fmt::Arguments<'a>)((__STATIC_FMTSTR
56+
as
57+
[core::fmt::rt::Piece<'static>, .. 1]),
58+
(__args_vec
59+
as
60+
&'static [core::fmt::Argument<'static>]))
61+
as core::fmt::Arguments<'static>)
62+
} as core::fmt::Arguments<'static>);
63+
64+
65+
66+
67+
68+
69+
70+
71+
((::std::fmt::format as
72+
fn(&core::fmt::Arguments<'_>) -> collections::string::String)((&(__args
73+
as
74+
core::fmt::Arguments<'static>)
75+
as
76+
&core::fmt::Arguments<'static>))
77+
as collections::string::String)
78+
}
79+
} as collections::string::String);
80+
}
81+
pub type Foo = [int, ..(3u as uint)];
82+
pub struct Bar {
83+
pub x: [int, ..(3u as uint)],
84+
}
85+
pub struct TupleBar([int, ..(4u as uint)]);
86+
pub enum Baz { BazVariant([int, ..(5u as uint)]), }
87+
pub fn id<T>(x: T) -> T { (x as T) }
88+
pub fn use_id() {
89+
let _ =
90+
((id::<[int, ..(3u as uint)]> as
91+
fn([int, .. 3]) -> [int, .. 3])(([(1 as int), (2 as int),
92+
(3 as int)] as [int, .. 3])) as
93+
[int, .. 3]);
94+
}
95+
fn main() { }

src/test/pretty/issue-4264.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014 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+
// pretty-compare-only
12+
// pretty-mode:typed
13+
// pp-exact:issue-4264.pp
14+
15+
// #4264 fixed-length vector types
16+
17+
pub fn foo(_: [int, ..3]) {}
18+
19+
pub fn bar() {
20+
static FOO: uint = 5u - 4u;
21+
let _: [(), ..FOO] = [()];
22+
23+
let _ : [(), ..1u] = [()];
24+
25+
let _ = &([1i,2,3]) as *const _ as *const [int, ..3u];
26+
27+
format!("test");
28+
}
29+
30+
pub type Foo = [int, ..3u];
31+
32+
pub struct Bar {
33+
pub x: [int, ..3u]
34+
}
35+
36+
pub struct TupleBar([int, ..4u]);
37+
38+
pub enum Baz {
39+
BazVariant([int, ..5u])
40+
}
41+
42+
pub fn id<T>(x: T) -> T { x }
43+
44+
pub fn use_id() {
45+
let _ = id::<[int, ..3u]>([1,2,3]);
46+
}
47+
48+
49+
fn main() {}

0 commit comments

Comments
 (0)