Skip to content

Commit 152aa0b

Browse files
committed
---
yaml --- r: 4343 b: refs/heads/master c: 0fbb678 h: refs/heads/master i: 4341: e628e9d 4339: 5910f04 4335: 85e75ae v: v3
1 parent 18c5ee9 commit 152aa0b

File tree

8 files changed

+87
-13
lines changed

8 files changed

+87
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: eea888af253083d658319382352181df7f255c03
2+
refs/heads/master: 0fbb6782bbdbe8d3bd703ca46110c989aec3e2ff

trunk/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ for i in \
182182
rustllvm \
183183
dl stage0 stage1 stage2 stage3 \
184184
stage0/lib stage1/lib stage2/lib stage3/lib \
185-
test/run-pass test/run-fail test/compile-fail test/bench
185+
test/run-pass test/run-fail test/compile-fail test/bench test/pretty
186186
do
187187
make_dir $i
188188
done

trunk/mk/tests.mk

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ ALL_TEST_INPUTS = $(wildcard $(S)src/test/*/*.rs \
66
$(S)src/test/*/*/*.rs \
77
$(S)src/test/*/*.rc)
88

9-
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
109
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
1110
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
1211
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
1312
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
1413
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
1514
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
15+
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
16+
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
1617

1718
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
1819
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
1920
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
2021
BENCH_TESTS := $(BENCH_RS)
22+
PRETTY_TESTS := $(PRETTY_RS)
2123

2224
FT := run_pass_stage2
2325
FT_LIB := $(call CFG_LIB_NAME,$(FT))
@@ -157,12 +159,16 @@ check-stage$(2)-rpass: test/run-pass.stage$(2).out \
157159

158160
check-stage$(2)-bench: test/bench.stage$(2).out \
159161

160-
check-stage$(2)-pretty: test/pretty.stage$(2).out \
161-
162162
check-stage$(2)-pretty-rpass: test/pretty-rpass.stage$(2).out \
163163

164164
check-stage$(2)-pretty-rfail: test/pretty-rfail.stage$(2).out \
165165

166+
check-stage$(2)-pretty-pretty: test/pretty-pretty.stage$(2).out \
167+
168+
check-stage$(2)-pretty: check-stage$(2)-pretty-rpass \
169+
check-stage$(2)-pretty-rfail \
170+
check-stage$(2)-pretty-pretty \
171+
166172
CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2) \
167173
--run-lib-path stage$(2)/lib \
168174
--rustc-path stage$(2)/rustc$$(X) \
@@ -203,6 +209,11 @@ PRETTY_RFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
203209
--build-base test/run-fail/ \
204210
--mode pretty \
205211

212+
PRETTY_PRETTY_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
213+
--src-base $$(S)src/test/pretty/ \
214+
--build-base test/pretty/ \
215+
--mode pretty \
216+
206217
test/compiletest.stage$(2)$$(X): $$(COMPILETEST_CRATE) \
207218
$$(COMPILETEST_INPUTS) \
208219
$$(SREQ$(2))
@@ -245,8 +256,10 @@ test/pretty-rfail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
245256
$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_RFAIL_ARGS$(2))
246257
$$(Q)touch $$@
247258

248-
test/pretty.stage$(2).out.tmp: test/pretty-rpass.stage$(2).out.tmp \
249-
test/pretty-rfail.stage$(2).out.tmp
259+
test/pretty-pretty.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
260+
$$(PRETTY_TESTS)
261+
@$$(call E, run: $$<)
262+
$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_PRETTY_ARGS$(2))
250263
$$(Q)touch $$@
251264

252265
endef

trunk/src/test/compiletest/header.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
import std::option;
22
import std::str;
33
import std::io;
4+
import std::fs;
45

56
import common::config;
67

78
export test_props;
89
export load_props;
910
export is_test_ignored;
1011

11-
type test_props = {error_patterns: str[], compile_flags: option::t[str]};
12+
type test_props = {
13+
// Lines that should be expected, in order, on standard out
14+
error_patterns: str[],
15+
// Extra flags to pass to the compiler
16+
compile_flags: option::t[str],
17+
// If present, the name of a file that this test should match when
18+
// pretty-printed
19+
pp_exact: option::t[str]
20+
};
1221

1322
// Load any test directives embedded in the file
1423
fn load_props(testfile: &str) -> test_props {
1524
let error_patterns = ~[];
1625
let compile_flags = option::none;
26+
let pp_exact = option::none;
1727
for each ln: str in iter_header(testfile) {
1828
alt parse_error_pattern(ln) {
1929
option::some(ep) { error_patterns += ~[ep]; }
2030
option::none. { }
2131
}
2232

23-
2433
if option::is_none(compile_flags) {
2534
compile_flags = parse_compile_flags(ln);
2635
}
36+
37+
if option::is_none(pp_exact) {
38+
pp_exact = parse_pp_exact(ln, testfile);
39+
}
2740
}
28-
ret {error_patterns: error_patterns, compile_flags: compile_flags};
41+
ret {
42+
error_patterns: error_patterns,
43+
compile_flags: compile_flags,
44+
pp_exact: pp_exact
45+
};
2946
}
3047

3148
fn is_test_ignored(config: &config, testfile: &str) -> bool {
@@ -64,6 +81,19 @@ fn parse_compile_flags(line: &str) -> option::t[str] {
6481
parse_name_value_directive(line, "compile-flags")
6582
}
6683

84+
fn parse_pp_exact(line: &str, testfile: &str) -> option::t[str] {
85+
alt parse_name_value_directive(line, "pp-exact") {
86+
option::some(s) { option::some(s) }
87+
option::none. {
88+
if parse_name_directive(line, "pp-exact") {
89+
option::some(fs::basename(testfile))
90+
} else {
91+
option::none
92+
}
93+
}
94+
}
95+
}
96+
6797
fn parse_name_directive(line: &str, directive: &str) -> bool {
6898
str::find(line, directive) >= 0
6999
}

trunk/src/test/compiletest/runtest.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ fn run_rpass_test(cx: &cx, props: &test_props, testfile: &str) {
7575
}
7676

7777
fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
78-
const rounds: int = 2;
78+
if option::is_some(props.pp_exact) {
79+
logv(cx.config, "testing for exact pretty-printing");
80+
} else {
81+
logv(cx.config, "testing for converging pretty-printing");
82+
}
83+
84+
let rounds = alt props.pp_exact {
85+
option::some(_) { 1 }
86+
option::none. { 2 }
87+
};
7988

8089
let srcs = ~[str::unsafe_from_bytes(
8190
io::file_reader(testfile).read_whole_stream())];
@@ -94,7 +103,16 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
94103
round += 1;
95104
}
96105

97-
let expected = srcs.(ivec::len(srcs) - 2u);
106+
let expected = alt props.pp_exact {
107+
option::some(file) {
108+
let filepath = fs::connect(fs::dirname(testfile), file);
109+
str::unsafe_from_bytes(
110+
io::file_reader(filepath).read_whole_stream())
111+
}
112+
option::none. {
113+
srcs.(ivec::len(srcs) - 2u)
114+
}
115+
};
98116
let actual = srcs.(ivec::len(srcs) - 1u);
99117

100118
compare_source(expected, actual);
@@ -122,7 +140,7 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
122140

123141
fn compare_source(expected: &str, actual: &str) {
124142
if expected != actual {
125-
error("pretty-printed source does not converge");
143+
error("pretty-printed source does match expected source");
126144
let msg = #fmt("\n\
127145
expected:\n\
128146
------------------------------------------\n\

trunk/src/test/pretty/example1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// pp-exact
2+
3+
fn main() { }

trunk/src/test/pretty/example2.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// pp-exact:example2.pp
2+
3+
fn main() { }

trunk/src/test/pretty/example2.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// pp-exact:example2.pp
2+
3+
fn
4+
main
5+
()
6+
{
7+
}

0 commit comments

Comments
 (0)