From 5c1338a18e50555d240f29d6c52873ff97f584bb Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 27 Feb 2012 21:23:49 -0800 Subject: [PATCH] add ability to run multi-crate tests, run tests with --inline --- mk/tests.mk | 3 ++- src/comp/metadata/astencode.rs | 5 +++-- src/compiletest/common.rs | 40 +++++++++++++++++++++++----------- src/compiletest/compiletest.rs | 4 +++- src/compiletest/header.rs | 16 ++++++++++++-- src/compiletest/runtest.rs | 25 +++++++++++++++++---- src/libstd/serialization.rs | 2 +- src/test/aux/cci_iter_lib.rs | 9 ++++++++ 8 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 src/test/aux/cci_iter_lib.rs diff --git a/mk/tests.mk b/mk/tests.mk index 858561e97e5..057d264920b 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -253,8 +253,9 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --compile-lib-path $$(HLIB$(1)_H_$(3)) \ --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \ --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X) \ + --aux-base $$(S)src/test/aux/ \ --stage-id stage$(1)-$(2) \ - --rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2)" \ + --rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2) --inline" \ $$(CTEST_TESTARGS) CFAIL_ARGS$(1)-T-$(2)-H-$(3) := \ diff --git a/src/comp/metadata/astencode.rs b/src/comp/metadata/astencode.rs index eeb65cb2ef0..e1b75e3addf 100644 --- a/src/comp/metadata/astencode.rs +++ b/src/comp/metadata/astencode.rs @@ -134,7 +134,7 @@ fn visit_ids(item: @ast::item, vfn: fn@(ast::node_id)) { }, visit_item: fn@(i: @ast::item) { - vfn(i.id) + vfn(i.id); }, visit_local: fn@(l: @ast::local) { @@ -772,7 +772,8 @@ fn decode_side_tables(xcx: extended_decode_ctxt, let id0 = entry_doc[c::tag_table_id].as_int(); let id = xcx.tr_id(id0); - #debug[">> Side table document with tag 0x%x found for id %d (orig %d)", + #debug[">> Side table document with tag 0x%x \ + found for id %d (orig %d)", tag, id, id0]; if tag == (c::tag_table_mutbl as uint) { diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index 7f2c46bef48..b4dcd36b45b 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -2,29 +2,43 @@ import option; enum mode { mode_compile_fail, mode_run_fail, mode_run_pass, mode_pretty, } -type config = +type config = { // The library paths required for running the compiler + compile_lib_path: str, + // The library paths required for running compiled programs + run_lib_path: str, + // The rustc executable + rustc_path: str, + // The directory containing the tests to run + src_base: str, + // The directory where programs should be built + build_base: str, + + // Directory for auxiliary libraries + aux_base: str, + // The name of the stage being built (stage1, etc) + stage_id: str, + // The test mode, compile-fail, run-fail, run-pass + mode: mode, + // Run ignored tests + run_ignored: bool, + // Only run tests that match this filter + filter: option, + // A command line to prefix program execution with, // for running under valgrind + runtool: option, + // Flags to pass to the compiler + rustcflags: option, + // Explain what's going on - {compile_lib_path: str, - run_lib_path: str, - rustc_path: str, - src_base: str, - build_base: str, - stage_id: str, - mode: mode, - run_ignored: bool, - filter: option, - runtool: option, - rustcflags: option, - verbose: bool}; + verbose: bool}; diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 4fc510e9c62..e0780bf473c 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -35,7 +35,8 @@ fn parse_config(args: [str]) -> config { let opts = [getopts::reqopt("compile-lib-path"), getopts::reqopt("run-lib-path"), getopts::reqopt("rustc-path"), getopts::reqopt("src-base"), - getopts::reqopt("build-base"), getopts::reqopt("stage-id"), + getopts::reqopt("build-base"), getopts::reqopt("aux-base"), + getopts::reqopt("stage-id"), getopts::reqopt("mode"), getopts::optflag("ignored"), getopts::optopt("runtool"), getopts::optopt("rustcflags"), getopts::optflag("verbose")]; @@ -53,6 +54,7 @@ fn parse_config(args: [str]) -> config { rustc_path: getopts::opt_str(match, "rustc-path"), src_base: getopts::opt_str(match, "src-base"), build_base: getopts::opt_str(match, "build-base"), + aux_base: getopts::opt_str(match, "aux-base"), stage_id: getopts::opt_str(match, "stage-id"), mode: str_mode(getopts::opt_str(match, "mode")), run_ignored: getopts::opt_present(match, "ignored"), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 636cf0746a6..e0a37cd9414 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -17,12 +17,15 @@ type test_props = { compile_flags: option, // If present, the name of a file that this test should match when // pretty-printed - pp_exact: option + pp_exact: option, + // Modules from aux directory that should be compiled + aux_builds: [str] }; // Load any test directives embedded in the file fn load_props(testfile: str) -> test_props { let error_patterns = []; + let aux_builds = []; let compile_flags = option::none; let pp_exact = option::none; iter_header(testfile) {|ln| @@ -38,11 +41,16 @@ fn load_props(testfile: str) -> test_props { if option::is_none(pp_exact) { pp_exact = parse_pp_exact(ln, testfile); } + + option::may(parse_aux_build(ln)) {|ab| + aux_builds += [ab]; + } }; ret { error_patterns: error_patterns, compile_flags: compile_flags, - pp_exact: pp_exact + pp_exact: pp_exact, + aux_builds: aux_builds }; } @@ -82,6 +90,10 @@ fn parse_error_pattern(line: str) -> option { parse_name_value_directive(line, "error-pattern") } +fn parse_aux_build(line: str) -> option { + parse_name_value_directive(line, "aux-build") +} + fn parse_compile_flags(line: str) -> option { parse_name_value_directive(line, "compile-flags") } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 74fcbf841f4..8bf5124d3f2 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -179,7 +179,7 @@ actual:\n\ fn make_typecheck_args(config: config, _testfile: str) -> procargs { let prog = config.rustc_path; - let args = ["-", "--no-trans", "--lib"]; + let args = ["-", "--no-trans", "--lib", "-L", config.build_base]; args += split_maybe_args(config.rustcflags); ret {prog: prog, args: args}; } @@ -287,7 +287,16 @@ type procres = {status: int, stdout: str, stderr: str, cmdline: str}; fn compile_test(config: config, props: test_props, testfile: str) -> procres { - compose_and_run(config, testfile, bind make_compile_args(_, props, _), + vec::iter(props.aux_builds) {|rel_ab| + let abs_ab = fs::connect(config.aux_base, rel_ab); + compose_and_run(config, abs_ab, + make_compile_args(_, props, ["--lib"], + make_lib_name, _), + config.compile_lib_path, option::none); + } + + compose_and_run(config, testfile, + make_compile_args(_, props, [], make_exe_name, _), config.compile_lib_path, option::none) } @@ -305,15 +314,23 @@ fn compose_and_run(config: config, testfile: str, procargs.prog, procargs.args, input); } -fn make_compile_args(config: config, props: test_props, testfile: str) -> +fn make_compile_args(config: config, props: test_props, extras: [str], + xform: fn(config, str) -> str, testfile: str) -> procargs { let prog = config.rustc_path; - let args = [testfile, "-o", make_exe_name(config, testfile)]; + let args = [testfile, "-o", xform(config, testfile), + "-L", config.build_base] + extras; args += split_maybe_args(config.rustcflags); args += split_maybe_args(props.compile_flags); ret {prog: prog, args: args}; } +fn make_lib_name(config: config, testfile: str) -> str { + // what we return here is not particularly important, as it + // happens; rustc ignores everything except for the directory. + output_base_name(config, testfile) +} + fn make_exe_name(config: config, testfile: str) -> str { output_base_name(config, testfile) + os::exec_suffix() } diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index 8130492cff9..ce402165fdd 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -387,7 +387,7 @@ fn test_option_int() { } fn deserialize_0(s: S) -> option { - s.read_enum("option") {|| + s.read_enum("core::option::t") {|| s.read_enum_variant {|i| alt check i { 0u { none } diff --git a/src/test/aux/cci_iter_lib.rs b/src/test/aux/cci_iter_lib.rs new file mode 100644 index 00000000000..9c7c1d09b2b --- /dev/null +++ b/src/test/aux/cci_iter_lib.rs @@ -0,0 +1,9 @@ +#[inline] +fn iter(v: [T], f: fn(T)) { + let i = 0u; + let n = vec::len(v); + while i < n { + f(v[i]); + i += 1u; + } +}