]> git.lizzy.rs Git - rust.git/commitdiff
Add dedicated pretty-printer tests with new pp-exact directive
authorBrian Anderson <banderson@mozilla.com>
Mon, 1 Aug 2011 21:10:59 +0000 (14:10 -0700)
committerBrian Anderson <banderson@mozilla.com>
Tue, 2 Aug 2011 17:39:13 +0000 (10:39 -0700)
Add a new src/test/pretty directory to hold just source files for testing the
pretty-printer.

Add a new pp-exact directive. When this directive is followed by a file name
it specifies a file containing the output that the pretty-printer should
generate. When pp-exact is not followed by a filename it says that the file
should pretty-print as written.

configure
mk/tests.mk
src/test/compiletest/header.rs
src/test/compiletest/runtest.rs
src/test/pretty/example1.rs [new file with mode: 0644]
src/test/pretty/example2.pp [new file with mode: 0644]
src/test/pretty/example2.rs [new file with mode: 0644]

index 60b33f3bf5de6eec160719ace130a91f60a6e633..f6d862c125262ce90cee364667f763cacecfe463 100755 (executable)
--- a/configure
+++ b/configure
@@ -182,7 +182,7 @@ for i in \
     rustllvm \
     dl stage0 stage1 stage2 stage3 \
     stage0/lib stage1/lib stage2/lib stage3/lib \
-    test/run-pass test/run-fail test/compile-fail test/bench
+    test/run-pass test/run-fail test/compile-fail test/bench test/pretty
 do
     make_dir $i
 done
index ee87a17ea126ddc10ffb06770e660aaf47381256..f755905c1c2d7173935f81b25a968b0e95a4387f 100644 (file)
@@ -6,18 +6,20 @@ ALL_TEST_INPUTS = $(wildcard $(S)src/test/*/*.rs   \
                               $(S)src/test/*/*/*.rs \
                               $(S)src/test/*/*.rc)
 
-BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
 RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
 RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
 CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
+BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
+PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
 
 RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
 RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
 CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
 BENCH_TESTS := $(BENCH_RS)
+PRETTY_TESTS := $(PRETTY_RS)
 
 FT := run_pass_stage2
 FT_LIB := $(call CFG_LIB_NAME,$(FT))
@@ -157,12 +159,16 @@ check-stage$(2)-rpass: test/run-pass.stage$(2).out \
 
 check-stage$(2)-bench: test/bench.stage$(2).out \
 
-check-stage$(2)-pretty: test/pretty.stage$(2).out \
-
 check-stage$(2)-pretty-rpass: test/pretty-rpass.stage$(2).out \
 
 check-stage$(2)-pretty-rfail: test/pretty-rfail.stage$(2).out \
 
+check-stage$(2)-pretty-pretty: test/pretty-pretty.stage$(2).out \
+
+check-stage$(2)-pretty: check-stage$(2)-pretty-rpass \
+                        check-stage$(2)-pretty-rfail \
+                        check-stage$(2)-pretty-pretty \
+
 CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2) \
                          --run-lib-path stage$(2)/lib \
                          --rustc-path stage$(2)/rustc$$(X) \
@@ -203,6 +209,11 @@ PRETTY_RFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                          --build-base test/run-fail/ \
                          --mode pretty \
 
+PRETTY_PRETTY_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
+                          --src-base $$(S)src/test/pretty/ \
+                          --build-base test/pretty/ \
+                          --mode pretty \
+
 test/compiletest.stage$(2)$$(X): $$(COMPILETEST_CRATE) \
                                  $$(COMPILETEST_INPUTS) \
                                  $$(SREQ$(2))
@@ -245,8 +256,10 @@ test/pretty-rfail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
        $$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_RFAIL_ARGS$(2))
        $$(Q)touch $$@
 
-test/pretty.stage$(2).out.tmp: test/pretty-rpass.stage$(2).out.tmp \
-                               test/pretty-rfail.stage$(2).out.tmp
+test/pretty-pretty.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
+                                     $$(PRETTY_TESTS)
+       @$$(call E, run: $$<)
+       $$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_PRETTY_ARGS$(2))
        $$(Q)touch $$@
 
 endef
index 7df2d7ee3103eceaf156befd409fb88080531fad..41619ad9de5c6153db7b1188b4bd1a5619c866f8 100644 (file)
@@ -1,6 +1,7 @@
 import std::option;
 import std::str;
 import std::io;
+import std::fs;
 
 import common::config;
 
@@ -8,24 +9,40 @@
 export load_props;
 export is_test_ignored;
 
-type test_props = {error_patterns: str[], compile_flags: option::t[str]};
+type test_props = {
+    // Lines that should be expected, in order, on standard out
+    error_patterns: str[],
+    // Extra flags to pass to the compiler
+    compile_flags: option::t[str],
+    // If present, the name of a file that this test should match when
+    // pretty-printed
+    pp_exact: option::t[str]
+};
 
 // Load any test directives embedded in the file
 fn load_props(testfile: &str) -> test_props {
     let error_patterns = ~[];
     let compile_flags = option::none;
+    let pp_exact = option::none;
     for each ln: str  in iter_header(testfile) {
         alt parse_error_pattern(ln) {
           option::some(ep) { error_patterns += ~[ep]; }
           option::none. { }
         }
 
-
         if option::is_none(compile_flags) {
             compile_flags = parse_compile_flags(ln);
         }
+
+        if option::is_none(pp_exact) {
+            pp_exact = parse_pp_exact(ln, testfile);
+        }
     }
-    ret {error_patterns: error_patterns, compile_flags: compile_flags};
+    ret {
+        error_patterns: error_patterns,
+        compile_flags: compile_flags,
+        pp_exact: pp_exact
+    };
 }
 
 fn is_test_ignored(config: &config, testfile: &str) -> bool {
@@ -64,6 +81,19 @@ fn parse_compile_flags(line: &str) -> option::t[str] {
     parse_name_value_directive(line, "compile-flags")
 }
 
+fn parse_pp_exact(line: &str, testfile: &str) -> option::t[str] {
+    alt parse_name_value_directive(line, "pp-exact") {
+      option::some(s) { option::some(s) }
+      option::none. {
+        if parse_name_directive(line, "pp-exact") {
+            option::some(fs::basename(testfile))
+        } else {
+            option::none
+        }
+      }
+    }
+}
+
 fn parse_name_directive(line: &str, directive: &str) -> bool {
     str::find(line, directive) >= 0
 }
index 50f61575a916981319681ed64ae482ce0538117f..53bedaa2a18af43464e7613c8c723585e0cc0a21 100644 (file)
@@ -75,7 +75,16 @@ fn run_rpass_test(cx: &cx, props: &test_props, testfile: &str) {
 }
 
 fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
-    const rounds: int = 2;
+    if option::is_some(props.pp_exact) {
+        logv(cx.config, "testing for exact pretty-printing");
+    } else {
+        logv(cx.config, "testing for converging pretty-printing");
+    }
+
+    let rounds = alt props.pp_exact {
+      option::some(_) { 1 }
+      option::none. { 2 }
+    };
 
     let srcs = ~[str::unsafe_from_bytes(
         io::file_reader(testfile).read_whole_stream())];
@@ -94,7 +103,16 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
         round += 1;
     }
 
-    let expected = srcs.(ivec::len(srcs) - 2u);
+    let expected = alt props.pp_exact {
+      option::some(file) {
+        let filepath = fs::connect(fs::dirname(testfile), file);
+        str::unsafe_from_bytes(
+            io::file_reader(filepath).read_whole_stream())
+      }
+      option::none. {
+        srcs.(ivec::len(srcs) - 2u)
+      }
+    };
     let actual = srcs.(ivec::len(srcs) - 1u);
 
     compare_source(expected, actual);
@@ -122,7 +140,7 @@ fn make_pp_args(config: &config, testfile: &str) -> procargs {
 
     fn compare_source(expected: &str, actual: &str) {
         if expected != actual {
-            error("pretty-printed source does not converge");
+            error("pretty-printed source does match expected source");
             let msg = #fmt("\n\
 expected:\n\
 ------------------------------------------\n\
diff --git a/src/test/pretty/example1.rs b/src/test/pretty/example1.rs
new file mode 100644 (file)
index 0000000..1e4ac5e
--- /dev/null
@@ -0,0 +1,3 @@
+// pp-exact
+
+fn main() { }
\ No newline at end of file
diff --git a/src/test/pretty/example2.pp b/src/test/pretty/example2.pp
new file mode 100644 (file)
index 0000000..67ab4bf
--- /dev/null
@@ -0,0 +1,3 @@
+// pp-exact:example2.pp
+
+fn main() { }
\ No newline at end of file
diff --git a/src/test/pretty/example2.rs b/src/test/pretty/example2.rs
new file mode 100644 (file)
index 0000000..3f3e99a
--- /dev/null
@@ -0,0 +1,7 @@
+// pp-exact:example2.pp
+
+fn
+main
+()
+{
+}
\ No newline at end of file