diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-08-24 15:28:43 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-08-24 15:51:16 -0700 |
| commit | c284b8b1dc348ab8b9c82350dd1b4e53fac1225c (patch) | |
| tree | 99de39b149969275f6f9ddebd7a9f555d91c5bff /src/compiletest | |
| parent | a8f1bee4574b8427a052e2fad93a90839288584b (diff) | |
| download | rust-c284b8b1dc348ab8b9c82350dd1b4e53fac1225c.tar.gz rust-c284b8b1dc348ab8b9c82350dd1b4e53fac1225c.zip | |
Start using core::path2::Path in a lot of places.
Diffstat (limited to 'src/compiletest')
| -rw-r--r-- | src/compiletest/common.rs | 10 | ||||
| -rw-r--r-- | src/compiletest/compiletest.rs | 48 | ||||
| -rw-r--r-- | src/compiletest/errors.rs | 2 | ||||
| -rw-r--r-- | src/compiletest/header.rs | 14 | ||||
| -rw-r--r-- | src/compiletest/runtest.rs | 132 |
5 files changed, 110 insertions, 96 deletions
diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index a7bcc8d67cc..021b138ffc1 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -10,16 +10,16 @@ type config = { run_lib_path: ~str, // The rustc executable - rustc_path: ~str, + rustc_path: Path, // The directory containing the tests to run - src_base: ~str, + src_base: Path, // The directory where programs should be built - build_base: ~str, + build_base: Path, // Directory for auxiliary libraries - aux_base: ~str, + aux_base: Path, // The name of the stage being built (stage1, etc) stage_id: ~str, @@ -34,7 +34,7 @@ type config = { filter: option<~str>, // Write out a parseable log of tests that were run - logfile: option<~str>, + logfile: option<Path>, // A command line to prefix program execution with, // for running under valgrind diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 73c824285ab..6a08c148461 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -42,12 +42,16 @@ fn parse_config(args: ~[~str]) -> config { err(f) => fail getopts::fail_str(f) }; + fn opt_path(m: getopts::matches, nm: ~str) -> Path { + Path(getopts::opt_str(m, nm)) + } + return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"), run_lib_path: getopts::opt_str(matches, ~"run-lib-path"), - rustc_path: getopts::opt_str(matches, ~"rustc-path"), - src_base: getopts::opt_str(matches, ~"src-base"), - build_base: getopts::opt_str(matches, ~"build-base"), - aux_base: getopts::opt_str(matches, ~"aux-base"), + rustc_path: opt_path(matches, ~"rustc-path"), + src_base: opt_path(matches, ~"src-base"), + build_base: opt_path(matches, ~"build-base"), + aux_base: opt_path(matches, ~"aux-base"), stage_id: getopts::opt_str(matches, ~"stage-id"), mode: str_mode(getopts::opt_str(matches, ~"mode")), run_ignored: getopts::opt_present(matches, ~"ignored"), @@ -55,7 +59,9 @@ fn parse_config(args: ~[~str]) -> config { if vec::len(matches.free) > 0u { option::some(matches.free[0]) } else { option::none }, - logfile: getopts::opt_maybe_str(matches, ~"logfile"), + logfile: option::map(getopts::opt_maybe_str(matches, + ~"logfile"), + |s| Path(s)), runtool: getopts::opt_maybe_str(matches, ~"runtool"), rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"), verbose: getopts::opt_present(matches, ~"verbose")}; @@ -66,9 +72,9 @@ fn log_config(config: config) { logv(c, fmt!("configuration:")); logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path)); logv(c, fmt!("run_lib_path: %s", config.run_lib_path)); - logv(c, fmt!("rustc_path: %s", config.rustc_path)); - logv(c, fmt!("src_base: %s", config.src_base)); - logv(c, fmt!("build_base: %s", config.build_base)); + logv(c, fmt!("rustc_path: %s", config.rustc_path.to_str())); + logv(c, fmt!("src_base: %s", config.src_base.to_str())); + logv(c, fmt!("build_base: %s", config.build_base.to_str())); logv(c, fmt!("stage_id: %s", config.stage_id)); logv(c, fmt!("mode: %s", mode_str(config.mode))); logv(c, fmt!("run_ignored: %b", config.run_ignored)); @@ -122,18 +128,19 @@ fn test_opts(config: config) -> test::test_opts { run_ignored: config.run_ignored, logfile: match config.logfile { - option::some(s) => option::some(s), + option::some(s) => option::some(s.to_str()), option::none => option::none } } } fn make_tests(config: config) -> ~[test::test_desc] { - debug!("making tests from %s", config.src_base); + debug!("making tests from %s", + config.src_base.to_str()); let mut tests = ~[]; - for os::list_dir_path(config.src_base).each |file| { - let file = file; - debug!("inspecting file %s", file); + for os::list_dir_path(&config.src_base).each |file| { + let file = copy file; + debug!("inspecting file %s", file.to_str()); if is_test(config, file) { vec::push(tests, make_test(config, file)) } @@ -141,7 +148,7 @@ fn make_tests(config: config) -> ~[test::test_desc] { return tests; } -fn is_test(config: config, testfile: ~str) -> bool { +fn is_test(config: config, testfile: &Path) -> bool { // Pretty-printer does not work with .rc files yet let valid_extensions = match config.mode { @@ -149,7 +156,7 @@ fn is_test(config: config, testfile: ~str) -> bool { _ => ~[~".rc", ~".rs"] }; let invalid_prefixes = ~[~".", ~"#", ~"~"]; - let name = path::basename(testfile); + let name = option::get(testfile.filename()); let mut valid = false; @@ -164,7 +171,7 @@ fn is_test(config: config, testfile: ~str) -> bool { return valid; } -fn make_test(config: config, testfile: ~str) -> +fn make_test(config: config, testfile: &Path) -> test::test_desc { { name: make_test_name(config, testfile), @@ -174,12 +181,13 @@ fn make_test(config: config, testfile: ~str) -> } } -fn make_test_name(config: config, testfile: ~str) -> ~str { - fmt!("[%s] %s", mode_str(config.mode), testfile) +fn make_test_name(config: config, testfile: &Path) -> ~str { + fmt!("[%s] %s", mode_str(config.mode), testfile.to_str()) } -fn make_test_closure(config: config, testfile: ~str) -> test::test_fn { - fn~() { runtest::run(config, copy testfile) } +fn make_test_closure(config: config, testfile: &Path) -> test::test_fn { + let testfile = testfile.to_str(); + fn~() { runtest::run(config, testfile) } } // Local Variables: diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 030e1d01ab0..9dde2f86f96 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -6,7 +6,7 @@ export expected_error; type expected_error = { line: uint, kind: ~str, msg: ~str }; // Load any test directives embedded in the file -fn load_errors(testfile: ~str) -> ~[expected_error] { +fn load_errors(testfile: &Path) -> ~[expected_error] { let mut error_patterns = ~[]; let rdr = result::get(io::file_reader(testfile)); let mut line_num = 1u; diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index efaa822d015..2905537d6a1 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -14,7 +14,7 @@ type test_props = { compile_flags: option<~str>, // If present, the name of a file that this test should match when // pretty-printed - pp_exact: option<~str>, + pp_exact: option<Path>, // Modules from aux directory that should be compiled aux_builds: ~[~str], // Environment settings to use during execution @@ -22,7 +22,7 @@ type test_props = { }; // Load any test directives embedded in the file -fn load_props(testfile: ~str) -> test_props { +fn load_props(testfile: &Path) -> test_props { let mut error_patterns = ~[]; let mut aux_builds = ~[]; let mut exec_env = ~[]; @@ -59,7 +59,7 @@ fn load_props(testfile: ~str) -> test_props { }; } -fn is_test_ignored(config: config, testfile: ~str) -> bool { +fn is_test_ignored(config: config, testfile: &Path) -> bool { let mut found = false; for iter_header(testfile) |ln| { if parse_name_directive(ln, ~"xfail-test") { return true; } @@ -74,7 +74,7 @@ fn is_test_ignored(config: config, testfile: ~str) -> bool { } } -fn iter_header(testfile: ~str, it: fn(~str) -> bool) -> bool { +fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool { let rdr = result::get(io::file_reader(testfile)); while !rdr.eof() { let ln = rdr.read_line(); @@ -114,12 +114,12 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> { } } -fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> { +fn parse_pp_exact(line: ~str, testfile: &Path) -> option<Path> { match parse_name_value_directive(line, ~"pp-exact") { - option::some(s) => option::some(s), + option::some(s) => option::some(Path(s)), option::none => { if parse_name_directive(line, ~"pp-exact") { - option::some(path::basename(testfile)) + option::some(testfile.file_path()) } else { option::none } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 6498a7d8952..fa003646699 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -16,17 +16,18 @@ fn run(config: config, testfile: ~str) { // We're going to be dumping a lot of info. Start on a new line. io::stdout().write_str(~"\n\n"); } - debug!("running %s", testfile); - let props = load_props(testfile); + let testfile = Path(testfile); + debug!("running %s", testfile.to_str()); + let props = load_props(&testfile); match config.mode { - mode_compile_fail => run_cfail_test(config, props, testfile), - mode_run_fail => run_rfail_test(config, props, testfile), - mode_run_pass => run_rpass_test(config, props, testfile), - mode_pretty => run_pretty_test(config, props, testfile) + mode_compile_fail => run_cfail_test(config, props, &testfile), + mode_run_fail => run_rfail_test(config, props, &testfile), + mode_run_pass => run_rpass_test(config, props, &testfile), + mode_pretty => run_pretty_test(config, props, &testfile) } } -fn run_cfail_test(config: config, props: test_props, testfile: ~str) { +fn run_cfail_test(config: config, props: test_props, testfile: &Path) { let procres = compile_test(config, props, testfile); if procres.status == 0 { @@ -46,7 +47,7 @@ fn run_cfail_test(config: config, props: test_props, testfile: ~str) { } } -fn run_rfail_test(config: config, props: test_props, testfile: ~str) { +fn run_rfail_test(config: config, props: test_props, testfile: &Path) { let mut procres = compile_test(config, props, testfile); if procres.status != 0 { fatal_procres(~"compilation failed!", procres); } @@ -74,7 +75,7 @@ fn check_correct_failure_status(procres: procres) { } } -fn run_rpass_test(config: config, props: test_props, testfile: ~str) { +fn run_rpass_test(config: config, props: test_props, testfile: &Path) { let mut procres = compile_test(config, props, testfile); if procres.status != 0 { fatal_procres(~"compilation failed!", procres); } @@ -84,7 +85,7 @@ fn run_rpass_test(config: config, props: test_props, testfile: ~str) { if procres.status != 0 { fatal_procres(~"test run failed!", procres); } } -fn run_pretty_test(config: config, props: test_props, testfile: ~str) { +fn run_pretty_test(config: config, props: test_props, testfile: &Path) { if option::is_some(props.pp_exact) { logv(config, ~"testing for exact pretty-printing"); } else { logv(config, ~"testing for converging pretty-printing"); } @@ -111,8 +112,8 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) { let mut expected = match props.pp_exact { option::some(file) => { - let filepath = path::connect(path::dirname(testfile), file); - result::get(io::read_whole_file_str(filepath)) + let filepath = testfile.dir_path().push_rel(&file); + result::get(io::read_whole_file_str(&filepath)) } option::none => { srcs[vec::len(srcs) - 2u] } }; @@ -136,15 +137,15 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) { return; - fn print_source(config: config, testfile: ~str, src: ~str) -> procres { + fn print_source(config: config, testfile: &Path, src: ~str) -> procres { compose_and_run(config, testfile, make_pp_args(config, testfile), ~[], config.compile_lib_path, option::some(src)) } - fn make_pp_args(config: config, _testfile: ~str) -> procargs { + fn make_pp_args(config: config, _testfile: &Path) -> procargs { let prog = config.rustc_path; let args = ~[~"-", ~"--pretty", ~"normal"]; - return {prog: prog, args: args}; + return {prog: prog.to_str(), args: args}; } fn compare_source(expected: ~str, actual: ~str) { @@ -168,28 +169,30 @@ actual:\n\ } fn typecheck_source(config: config, props: test_props, - testfile: ~str, src: ~str) -> procres { + testfile: &Path, src: ~str) -> procres { compose_and_run_compiler( config, props, testfile, make_typecheck_args(config, testfile), option::some(src)) } - fn make_typecheck_args(config: config, testfile: ~str) -> procargs { + fn make_typecheck_args(config: config, testfile: &Path) -> procargs { let prog = config.rustc_path; let mut args = ~[~"-", - ~"--no-trans", ~"--lib", ~"-L", config.build_base, - ~"-L", aux_output_dir_name(config, testfile)]; + ~"--no-trans", ~"--lib", + ~"-L", config.build_base.to_str(), + ~"-L", + aux_output_dir_name(config, testfile).to_str()]; args += split_maybe_args(config.rustcflags); - return {prog: prog, args: args}; + return {prog: prog.to_str(), args: args}; } } fn check_error_patterns(props: test_props, - testfile: ~str, + testfile: &Path, procres: procres) { if vec::is_empty(props.error_patterns) { - fatal(~"no error pattern specified in " + testfile); + fatal(~"no error pattern specified in " + testfile.to_str()); } if procres.status == 0 { @@ -228,7 +231,7 @@ fn check_error_patterns(props: test_props, } fn check_expected_errors(expected_errors: ~[errors::expected_error], - testfile: ~str, + testfile: &Path, procres: procres) { // true if we found the error in question @@ -240,7 +243,7 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error], } let prefixes = vec::map(expected_errors, |ee| { - fmt!("%s:%u:", testfile, ee.line) + fmt!("%s:%u:", testfile.to_str(), ee.line) }); // Scan and extract our error/warning messages, @@ -291,8 +294,8 @@ type procargs = {prog: ~str, args: ~[~str]}; type procres = {status: int, stdout: ~str, stderr: ~str, cmdline: ~str}; fn compile_test(config: config, props: test_props, - testfile: ~str) -> procres { - let link_args = ~[~"-L", aux_output_dir_name(config, testfile)]; + testfile: &Path) -> procres { + let link_args = ~[~"-L", aux_output_dir_name(config, testfile).to_str()]; compose_and_run_compiler( config, props, testfile, make_compile_args(config, props, link_args, @@ -301,7 +304,7 @@ fn compile_test(config: config, props: test_props, } fn exec_compiled_test(config: config, props: test_props, - testfile: ~str) -> procres { + testfile: &Path) -> procres { compose_and_run(config, testfile, make_run_args(config, props, testfile), props.exec_env, @@ -311,26 +314,28 @@ fn exec_compiled_test(config: config, props: test_props, fn compose_and_run_compiler( config: config, props: test_props, - testfile: ~str, + testfile: &Path, args: procargs, input: option<~str>) -> procres { if props.aux_builds.is_not_empty() { - ensure_dir(aux_output_dir_name(config, testfile)); + ensure_dir(&aux_output_dir_name(config, testfile)); } - let extra_link_args = ~[~"-L", aux_output_dir_name(config, testfile)]; + let extra_link_args = ~[~"-L", + aux_output_dir_name(config, testfile).to_str()]; do vec::iter(props.aux_builds) |rel_ab| { - let abs_ab = path::connect(config.aux_base, rel_ab); + let abs_ab = config.aux_base.push_rel(&Path(rel_ab)); let aux_args = make_compile_args(config, props, ~[~"--lib"] + extra_link_args, - |a,b| make_lib_name(a, b, testfile), abs_ab); - let auxres = compose_and_run(config, abs_ab, aux_args, ~[], + |a,b| make_lib_name(a, b, testfile), &abs_ab); + let auxres = compose_and_run(config, &abs_ab, aux_args, ~[], config.compile_lib_path, option::none); if auxres.status != 0 { fatal_procres( - fmt!("auxiliary build of %s failed to compile: ", abs_ab), + fmt!("auxiliary build of %s failed to compile: ", + abs_ab.to_str()), auxres); } } @@ -339,14 +344,14 @@ fn compose_and_run_compiler( config.compile_lib_path, input) } -fn ensure_dir(path: Path) { +fn ensure_dir(path: &Path) { if os::path_is_dir(path) { return; } if !os::make_dir(path, 0x1c0i32) { - fail fmt!("can't make dir %s", path); + fail fmt!("can't make dir %s", path.to_str()); } } -fn compose_and_run(config: config, testfile: ~str, +fn compose_and_run(config: config, testfile: &Path, procargs: procargs, procenv: ~[(~str, ~str)], lib_path: ~str, @@ -356,28 +361,30 @@ fn compose_and_run(config: config, testfile: ~str, } fn make_compile_args(config: config, props: test_props, extras: ~[~str], - xform: fn(config, ~str) -> ~str, testfile: ~str) -> - procargs { + xform: fn(config, (&Path)) -> Path, + testfile: &Path) -> procargs { let prog = config.rustc_path; - let mut args = ~[testfile, ~"-o", xform(config, testfile), - ~"-L", config.build_base] + extras; + let mut args = ~[testfile.to_str(), + ~"-o", xform(config, testfile).to_str(), + ~"-L", config.build_base.to_str()] + + extras; args += split_maybe_args(config.rustcflags); args += split_maybe_args(props.compile_flags); - return {prog: prog, args: args}; + return {prog: prog.to_str(), args: args}; } -fn make_lib_name(config: config, auxfile: ~str, testfile: ~str) -> ~str { +fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path { // what we return here is not particularly important, as it // happens; rustc ignores everything except for the directory. let auxname = output_testname(auxfile); - path::connect(aux_output_dir_name(config, testfile), auxname) + aux_output_dir_name(config, testfile).push_rel(&auxname) } -fn make_exe_name(config: config, testfile: ~str) -> ~str { - output_base_name(config, testfile) + os::exe_suffix() +fn make_exe_name(config: config, testfile: &Path) -> Path { + Path(output_base_name(config, testfile).to_str() + os::exe_suffix()) } -fn make_run_args(config: config, _props: test_props, testfile: ~str) -> +fn make_run_args(config: config, _props: test_props, testfile: &Path) -> procargs { let toolargs = { // If we've got another tool to run under (valgrind), @@ -390,7 +397,7 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) -> split_maybe_args(runtool) }; - let args = toolargs + ~[make_exe_name(config, testfile)]; + let args = toolargs + ~[make_exe_name(config, testfile).to_str()]; return {prog: args[0], args: vec::slice(args, 1u, vec::len(args))}; } @@ -408,7 +415,7 @@ fn split_maybe_args(argstr: option<~str>) -> ~[~str] { } } -fn program_output(config: config, testfile: ~str, lib_path: ~str, prog: ~str, +fn program_output(config: config, testfile: &Path, lib_path: ~str, prog: ~str, args: ~[~str], env: ~[(~str, ~str)], input: option<~str>) -> procres { let cmdline = @@ -445,37 +452,36 @@ fn lib_path_cmd_prefix(path: ~str) -> ~str { fmt!("%s=\"%s\"", util::lib_path_env_var(), util::make_new_path(path)) } -fn dump_output(config: config, testfile: ~str, out: ~str, err: ~str) { +fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) { dump_output_file(config, testfile, out, ~"out"); dump_output_file(config, testfile, err, ~"err"); maybe_dump_to_stdout(config, out, err); } -fn dump_output_file(config: config, testfile: ~str, +fn dump_output_file(config: config, testfile: &Path, out: ~str, extension: ~str) { let outfile = make_out_name(config, testfile, extension); let writer = result::get( - io::file_writer(outfile, ~[io::Create, io::Truncate])); + io::file_writer(&outfile, ~[io::Create, io::Truncate])); writer.write_str(out); } -fn make_out_name(config: config, testfile: ~str, extension: ~str) -> ~str { - output_base_name(config, testfile) + ~"." + extension +fn make_out_name(config: config, testfile: &Path, extension: ~str) -> Path { + output_base_name(config, testfile).with_filetype(extension) } -fn aux_output_dir_name(config: config, testfile: ~str) -> ~str { - output_base_name(config, testfile) + ~".libaux" +fn aux_output_dir_name(config: config, testfile: &Path) -> Path { + output_base_name(config, testfile).with_filetype("libaux") } -fn output_testname(testfile: ~str) -> ~str { - let parts = str::split_char(path::basename(testfile), '.'); - str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ~".") +fn output_testname(testfile: &Path) -> Path { + Path(option::get(testfile.filestem())) } -fn output_base_name(config: config, testfile: ~str) -> ~str { - let base = config.build_base; - let filename = output_testname(testfile); - fmt!("%s%s.%s", base, filename, config.stage_id) +fn output_base_name(config: config, testfile: &Path) -> Path { + config.build_base + .push_rel(&output_testname(testfile)) + .with_filetype(config.stage_id) } fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) { |
