]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/common.rs
Remove the parse-fail test suite
[rust.git] / src / tools / compiletest / src / common.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 pub use self::Mode::*;
11
12 use std::fmt;
13 use std::path::{Path, PathBuf};
14 use std::str::FromStr;
15
16 use test::ColorConfig;
17 use util::PathBufExt;
18
19 #[derive(Clone, Copy, PartialEq, Debug)]
20 pub enum Mode {
21     CompileFail,
22     RunFail,
23     /// This now behaves like a `ui` test that has an implict `// run-pass`.
24     RunPass,
25     RunPassValgrind,
26     Pretty,
27     DebugInfoBoth,
28     DebugInfoGdb,
29     DebugInfoLldb,
30     Codegen,
31     Rustdoc,
32     CodegenUnits,
33     Incremental,
34     RunMake,
35     Ui,
36     MirOpt,
37 }
38
39 impl Mode {
40     pub fn disambiguator(self) -> &'static str {
41         // Run-pass and pretty run-pass tests could run concurrently, and if they do,
42         // they need to keep their output segregated. Same is true for debuginfo tests that
43         // can be run both on gdb and lldb.
44         match self {
45             Pretty => ".pretty",
46             DebugInfoGdb => ".gdb",
47             DebugInfoLldb => ".lldb",
48             _ => "",
49         }
50     }
51 }
52
53 impl FromStr for Mode {
54     type Err = ();
55     fn from_str(s: &str) -> Result<Mode, ()> {
56         match s {
57             "compile-fail" => Ok(CompileFail),
58             "run-fail" => Ok(RunFail),
59             "run-pass" => Ok(RunPass),
60             "run-pass-valgrind" => Ok(RunPassValgrind),
61             "pretty" => Ok(Pretty),
62             "debuginfo-both" => Ok(DebugInfoBoth),
63             "debuginfo-lldb" => Ok(DebugInfoLldb),
64             "debuginfo-gdb" => Ok(DebugInfoGdb),
65             "codegen" => Ok(Codegen),
66             "rustdoc" => Ok(Rustdoc),
67             "codegen-units" => Ok(CodegenUnits),
68             "incremental" => Ok(Incremental),
69             "run-make" => Ok(RunMake),
70             "ui" => Ok(Ui),
71             "mir-opt" => Ok(MirOpt),
72             _ => Err(()),
73         }
74     }
75 }
76
77 impl fmt::Display for Mode {
78     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79         let s = match *self {
80             CompileFail => "compile-fail",
81             RunFail => "run-fail",
82             RunPass => "run-pass",
83             RunPassValgrind => "run-pass-valgrind",
84             Pretty => "pretty",
85             DebugInfoBoth => "debuginfo-both",
86             DebugInfoGdb => "debuginfo-gdb",
87             DebugInfoLldb => "debuginfo-lldb",
88             Codegen => "codegen",
89             Rustdoc => "rustdoc",
90             CodegenUnits => "codegen-units",
91             Incremental => "incremental",
92             RunMake => "run-make",
93             Ui => "ui",
94             MirOpt => "mir-opt",
95         };
96         fmt::Display::fmt(s, f)
97     }
98 }
99
100 #[derive(Clone, Debug, PartialEq)]
101 pub enum CompareMode {
102     Nll,
103     Polonius,
104 }
105
106 impl CompareMode {
107     pub(crate) fn to_str(&self) -> &'static str {
108         match *self {
109             CompareMode::Nll => "nll",
110             CompareMode::Polonius => "polonius",
111         }
112     }
113
114     pub fn parse(s: String) -> CompareMode {
115         match s.as_str() {
116             "nll" => CompareMode::Nll,
117             "polonius" => CompareMode::Polonius,
118             x => panic!("unknown --compare-mode option: {}", x),
119         }
120     }
121 }
122
123 #[derive(Clone)]
124 pub struct Config {
125     /// Whether to overwrite stderr/stdout files instead of complaining about changes in output
126     pub bless: bool,
127
128     /// The library paths required for running the compiler
129     pub compile_lib_path: PathBuf,
130
131     /// The library paths required for running compiled programs
132     pub run_lib_path: PathBuf,
133
134     /// The rustc executable
135     pub rustc_path: PathBuf,
136
137     /// The rustdoc executable
138     pub rustdoc_path: Option<PathBuf>,
139
140     /// The python executable to use for LLDB
141     pub lldb_python: String,
142
143     /// The python executable to use for htmldocck
144     pub docck_python: String,
145
146     /// The llvm FileCheck binary path
147     pub llvm_filecheck: Option<PathBuf>,
148
149     /// The valgrind path
150     pub valgrind_path: Option<String>,
151
152     /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
153     /// (or, alternatively, to silently run them like regular run-pass tests).
154     pub force_valgrind: bool,
155
156     /// The directory containing the tests to run
157     pub src_base: PathBuf,
158
159     /// The directory where programs should be built
160     pub build_base: PathBuf,
161
162     /// The name of the stage being built (stage1, etc)
163     pub stage_id: String,
164
165     /// The test mode, compile-fail, run-fail, run-pass
166     pub mode: Mode,
167
168     /// Run ignored tests
169     pub run_ignored: bool,
170
171     /// Only run tests that match this filter
172     pub filter: Option<String>,
173
174     /// Exactly match the filter, rather than a substring
175     pub filter_exact: bool,
176
177     /// Write out a parseable log of tests that were run
178     pub logfile: Option<PathBuf>,
179
180     /// A command line to prefix program execution with,
181     /// for running under valgrind
182     pub runtool: Option<String>,
183
184     /// Flags to pass to the compiler when building for the host
185     pub host_rustcflags: Option<String>,
186
187     /// Flags to pass to the compiler when building for the target
188     pub target_rustcflags: Option<String>,
189
190     /// Target system to be tested
191     pub target: String,
192
193     /// Host triple for the compiler being invoked
194     pub host: String,
195
196     /// Path to / name of the GDB executable
197     pub gdb: Option<String>,
198
199     /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
200     pub gdb_version: Option<u32>,
201
202     /// Whether GDB has native rust support
203     pub gdb_native_rust: bool,
204
205     /// Version of LLDB
206     pub lldb_version: Option<String>,
207
208     /// Whether LLDB has native rust support
209     pub lldb_native_rust: bool,
210
211     /// Version of LLVM
212     pub llvm_version: Option<String>,
213
214     /// Is LLVM a system LLVM
215     pub system_llvm: bool,
216
217     /// Path to the android tools
218     pub android_cross_path: PathBuf,
219
220     /// Extra parameter to run adb on arm-linux-androideabi
221     pub adb_path: String,
222
223     /// Extra parameter to run test suite on arm-linux-androideabi
224     pub adb_test_dir: String,
225
226     /// status whether android device available or not
227     pub adb_device_status: bool,
228
229     /// the path containing LLDB's Python module
230     pub lldb_python_dir: Option<String>,
231
232     /// Explain what's going on
233     pub verbose: bool,
234
235     /// Print one character per test instead of one line
236     pub quiet: bool,
237
238     /// Whether to use colors in test.
239     pub color: ColorConfig,
240
241     /// where to find the remote test client process, if we're using it
242     pub remote_test_client: Option<PathBuf>,
243
244     /// mode describing what file the actual ui output will be compared to
245     pub compare_mode: Option<CompareMode>,
246
247     // Configuration for various run-make tests frobbing things like C compilers
248     // or querying about various LLVM component information.
249     pub cc: String,
250     pub cxx: String,
251     pub cflags: String,
252     pub ar: String,
253     pub linker: Option<String>,
254     pub llvm_components: String,
255     pub llvm_cxxflags: String,
256     pub nodejs: Option<String>,
257 }
258
259 #[derive(Debug, Clone)]
260 pub struct TestPaths {
261     pub file: PathBuf,         // e.g., compile-test/foo/bar/baz.rs
262     pub relative_dir: PathBuf, // e.g., foo/bar
263 }
264
265 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
266 pub fn expected_output_path(
267     testpaths: &TestPaths,
268     revision: Option<&str>,
269     compare_mode: &Option<CompareMode>,
270     kind: &str,
271 ) -> PathBuf {
272     assert!(UI_EXTENSIONS.contains(&kind));
273     let mut parts = Vec::new();
274
275     if let Some(x) = revision {
276         parts.push(x);
277     }
278     if let Some(ref x) = *compare_mode {
279         parts.push(x.to_str());
280     }
281     parts.push(kind);
282
283     let extension = parts.join(".");
284     testpaths.file.with_extension(extension)
285 }
286
287 pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED];
288 pub const UI_STDERR: &str = "stderr";
289 pub const UI_STDOUT: &str = "stdout";
290 pub const UI_FIXED: &str = "fixed";
291
292 /// Absolute path to the directory where all output for all tests in the given
293 /// `relative_dir` group should reside. Example:
294 ///   /path/to/build/host-triple/test/ui/relative/
295 /// This is created early when tests are collected to avoid race conditions.
296 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
297     config.build_base.join(relative_dir)
298 }
299
300 /// Generates a unique name for the test, such as `testname.revision.mode`.
301 pub fn output_testname_unique(
302     config: &Config,
303     testpaths: &TestPaths,
304     revision: Option<&str>,
305 ) -> PathBuf {
306     let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
307     PathBuf::from(&testpaths.file.file_stem().unwrap())
308         .with_extra_extension(revision.unwrap_or(""))
309         .with_extra_extension(mode)
310 }
311
312 /// Absolute path to the directory where all output for the given
313 /// test/revision should reside.  Example:
314 ///   /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
315 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
316     output_relative_path(config, &testpaths.relative_dir)
317         .join(output_testname_unique(config, testpaths, revision))
318 }
319
320 /// Absolute path to the base filename used as output for the given
321 /// test/revision.  Example:
322 ///   /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
323 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
324     output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
325 }