Add pretty=typed test support to compiletest and add a test for fixed size arrays.

This commit is contained in:
Luqman Aden 2014-07-22 16:39:10 -07:00 committed by Alex Crichton
parent 445340771d
commit c2ac7fde0b
4 changed files with 172 additions and 1 deletions

View File

@ -36,6 +36,10 @@ pub struct TestProps {
pub no_prefer_dynamic: bool,
// Don't run --pretty expanded when running pretty printing tests
pub no_pretty_expanded: bool,
// Which pretty mode are we testing with, default to 'normal'
pub pretty_mode: String,
// Only compare pretty output and don't try compiling
pub pretty_compare_only: bool,
}
// Load any test directives embedded in the file
@ -51,6 +55,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut check_stdout = false;
let mut no_prefer_dynamic = false;
let mut no_pretty_expanded = false;
let mut pretty_mode = None;
let mut pretty_compare_only = false;
iter_header(testfile, |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
@ -85,6 +91,14 @@ pub fn load_props(testfile: &Path) -> TestProps {
no_pretty_expanded = parse_no_pretty_expanded(ln);
}
if pretty_mode.is_none() {
pretty_mode = parse_pretty_mode(ln);
}
if !pretty_compare_only {
pretty_compare_only = parse_pretty_compare_only(ln);
}
match parse_aux_build(ln) {
Some(ab) => { aux_builds.push(ab); }
None => {}
@ -115,6 +129,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
check_stdout: check_stdout,
no_prefer_dynamic: no_prefer_dynamic,
no_pretty_expanded: no_pretty_expanded,
pretty_mode: pretty_mode.unwrap_or("normal".to_string()),
pretty_compare_only: pretty_compare_only
}
}
@ -205,6 +221,14 @@ fn parse_no_pretty_expanded(line: &str) -> bool {
parse_name_directive(line, "no-pretty-expanded")
}
fn parse_pretty_mode(line: &str) -> Option<String> {
parse_name_value_directive(line, "pretty-mode")
}
fn parse_pretty_compare_only(line: &str) -> bool {
parse_name_directive(line, "pretty-compare-only")
}
fn parse_exec_env(line: &str) -> Option<(String, String)> {
parse_name_value_directive(line, "exec-env").map(|nv| {
// nv is either FOO or FOO=BAR

View File

@ -168,7 +168,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
props,
testfile,
srcs[round].to_string(),
"normal");
props.pretty_mode.as_slice());
if !proc_res.status.success() {
fatal_proc_rec(format!("pretty-printing failed in round {}",
@ -200,6 +200,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
compare_source(expected.as_slice(), actual.as_slice());
// If we're only making sure that the output matches then just stop here
if props.pretty_compare_only { return; }
// Finally, let's make sure it actually appears to remain valid code
let proc_res = typecheck_source(config, props, testfile, actual);

View File

@ -0,0 +1,95 @@
#![feature(phase)]
#![no_std]
#![feature(globs)]
#[phase(plugin, link)]
extern crate std = "std";
extern crate native;
use std::prelude::*;
// Copyright 2014 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.
// pretty-compare-only
// pretty-mode:typed
// pp-exact:issue-4264.pp
// #4264 fixed-length vector types
pub fn foo(_: [int, ..(3 as uint)]) { }
pub fn bar() {
static FOO: uint = ((5u as uint) - (4u as uint) as uint);
let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), .. 1]);
let _: [(), ..(1u as uint)] = ([(() as ())] as [(), .. 1]);
let _ =
(((&((([(1i as int), (2 as int), (3 as int)] as [int, .. 3])) as
[int, .. 3]) as &[int, .. 3]) as *const _ as
*const [int, .. 3]) as *const [int, ..(3u as uint)] as
*const [int, .. 3]);
(match (() as ()) {
() => {
#[inline]
#[allow(dead_code)]
static __STATIC_FMTSTR:
[::std::fmt::rt::Piece<'static>, ..(1u as uint)] =
([((::std::fmt::rt::String as
fn(&'static str) -> core::fmt::rt::Piece<'static>)(("test"
as
&'static str))
as core::fmt::rt::Piece<'static>)] as
[core::fmt::rt::Piece<'static>, .. 1]);
let __args_vec =
(&([] as &'static [core::fmt::Argument<'static>]) as
&'static [core::fmt::Argument<'static>]);
let __args =
(unsafe {
((::std::fmt::Arguments::new as
unsafe fn(&'static [core::fmt::rt::Piece<'static>], &'a [core::fmt::Argument<'a>]) -> core::fmt::Arguments<'a>)((__STATIC_FMTSTR
as
[core::fmt::rt::Piece<'static>, .. 1]),
(__args_vec
as
&'static [core::fmt::Argument<'static>]))
as core::fmt::Arguments<'static>)
} as core::fmt::Arguments<'static>);
((::std::fmt::format as
fn(&core::fmt::Arguments<'_>) -> collections::string::String)((&(__args
as
core::fmt::Arguments<'static>)
as
&core::fmt::Arguments<'static>))
as collections::string::String)
}
} as collections::string::String);
}
pub type Foo = [int, ..(3u as uint)];
pub struct Bar {
pub x: [int, ..(3u as uint)],
}
pub struct TupleBar([int, ..(4u as uint)]);
pub enum Baz { BazVariant([int, ..(5u as uint)]), }
pub fn id<T>(x: T) -> T { (x as T) }
pub fn use_id() {
let _ =
((id::<[int, ..(3u as uint)]> as
fn([int, .. 3]) -> [int, .. 3])(([(1 as int), (2 as int),
(3 as int)] as [int, .. 3])) as
[int, .. 3]);
}
fn main() { }

View File

@ -0,0 +1,49 @@
// Copyright 2014 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.
// pretty-compare-only
// pretty-mode:typed
// pp-exact:issue-4264.pp
// #4264 fixed-length vector types
pub fn foo(_: [int, ..3]) {}
pub fn bar() {
static FOO: uint = 5u - 4u;
let _: [(), ..FOO] = [()];
let _ : [(), ..1u] = [()];
let _ = &([1i,2,3]) as *const _ as *const [int, ..3u];
format!("test");
}
pub type Foo = [int, ..3u];
pub struct Bar {
pub x: [int, ..3u]
}
pub struct TupleBar([int, ..4u]);
pub enum Baz {
BazVariant([int, ..5u])
}
pub fn id<T>(x: T) -> T { x }
pub fn use_id() {
let _ = id::<[int, ..3u]>([1,2,3]);
}
fn main() {}