]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/header.rs
Incorporate a stray test
[rust.git] / src / tools / compiletest / src / header.rs
1 // Copyright 2012-2013 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
11 use std::env;
12 use std::fs::File;
13 use std::io::prelude::*;
14 use std::io::BufReader;
15 use std::path::{Path, PathBuf};
16
17 use common::{self, Config, Mode};
18 use util;
19
20 use extract_gdb_version;
21
22 /// Properties which must be known very early, before actually running
23 /// the test.
24 pub struct EarlyProps {
25     pub ignore: bool,
26     pub should_fail: bool,
27     pub aux: Vec<String>,
28     pub revisions: Vec<String>,
29 }
30
31 impl EarlyProps {
32     pub fn from_file(config: &Config, testfile: &Path) -> Self {
33         let mut props = EarlyProps {
34             ignore: false,
35             should_fail: false,
36             aux: Vec::new(),
37             revisions: vec![],
38         };
39
40         iter_header(testfile, None, &mut |ln| {
41             // we should check if any only-<platform> exists and if it exists
42             // and does not matches the current platform, skip the test
43             props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore")
44                 || (config.has_cfg_prefix(ln, "only")
45                     && !config.parse_cfg_name_directive(ln, "only"))
46                 || ignore_gdb(config, ln) || ignore_lldb(config, ln)
47                 || ignore_llvm(config, ln);
48
49             if let Some(s) = config.parse_aux_build(ln) {
50                 props.aux.push(s);
51             }
52
53             if let Some(r) = config.parse_revisions(ln) {
54                 props.revisions.extend(r);
55             }
56
57             props.should_fail = props.should_fail || config.parse_name_directive(ln, "should-fail");
58         });
59
60         return props;
61
62         fn ignore_gdb(config: &Config, line: &str) -> bool {
63             if config.mode != common::DebugInfoGdb {
64                 return false;
65             }
66
67             if let Some(actual_version) = config.gdb_version {
68                 if line.starts_with("min-gdb-version") {
69                     let (start_ver, end_ver) = extract_gdb_version_range(line);
70
71                     if start_ver != end_ver {
72                         panic!("Expected single GDB version")
73                     }
74                     // Ignore if actual version is smaller the minimum required
75                     // version
76                     actual_version < start_ver
77                 } else if line.starts_with("ignore-gdb-version") {
78                     let (min_version, max_version) = extract_gdb_version_range(line);
79
80                     if max_version < min_version {
81                         panic!("Malformed GDB version range: max < min")
82                     }
83
84                     actual_version >= min_version && actual_version <= max_version
85                 } else {
86                     false
87                 }
88             } else {
89                 false
90             }
91         }
92
93         // Takes a directive of the form "ignore-gdb-version <version1> [- <version2>]",
94         // returns the numeric representation of <version1> and <version2> as
95         // tuple: (<version1> as u32, <version2> as u32)
96         // If the <version2> part is omitted, the second component of the tuple
97         // is the same as <version1>.
98         fn extract_gdb_version_range(line: &str) -> (u32, u32) {
99             const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
100
101             let range_components = line.split(&[' ', '-'][..])
102                                        .filter(|word| !word.is_empty())
103                                        .map(extract_gdb_version)
104                                        .skip_while(Option::is_none)
105                                        .take(3) // 3 or more = invalid, so take at most 3.
106                                        .collect::<Vec<Option<u32>>>();
107
108             match range_components.len() {
109                 1 => {
110                     let v = range_components[0].unwrap();
111                     (v, v)
112                 }
113                 2 => {
114                     let v_min = range_components[0].unwrap();
115                     let v_max = range_components[1].expect(ERROR_MESSAGE);
116                     (v_min, v_max)
117                 }
118                 _ => panic!(ERROR_MESSAGE),
119             }
120         }
121
122         fn ignore_lldb(config: &Config, line: &str) -> bool {
123             if config.mode != common::DebugInfoLldb {
124                 return false;
125             }
126
127             if let Some(ref actual_version) = config.lldb_version {
128                 if line.starts_with("min-lldb-version") {
129                     let min_version = line.trim_right()
130                         .rsplit(' ')
131                         .next()
132                         .expect("Malformed lldb version directive");
133                     // Ignore if actual version is smaller the minimum required
134                     // version
135                     lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
136                 } else {
137                     false
138                 }
139             } else {
140                 false
141             }
142         }
143
144         fn ignore_llvm(config: &Config, line: &str) -> bool {
145             if config.system_llvm && line.starts_with("no-system-llvm") {
146                 return true;
147             }
148             if let Some(ref actual_version) = config.llvm_version {
149                 if line.starts_with("min-llvm-version") {
150                     let min_version = line.trim_right()
151                         .rsplit(' ')
152                         .next()
153                         .expect("Malformed llvm version directive");
154                     // Ignore if actual version is smaller the minimum required
155                     // version
156                     &actual_version[..] < min_version
157                 } else if line.starts_with("min-system-llvm-version") {
158                     let min_version = line.trim_right()
159                         .rsplit(' ')
160                         .next()
161                         .expect("Malformed llvm version directive");
162                     // Ignore if using system LLVM and actual version
163                     // is smaller the minimum required version
164                     config.system_llvm && &actual_version[..] < min_version
165                 } else {
166                     false
167                 }
168             } else {
169                 false
170             }
171         }
172     }
173 }
174
175 #[derive(Clone, Debug)]
176 pub struct TestProps {
177     // Lines that should be expected, in order, on standard out
178     pub error_patterns: Vec<String>,
179     // Extra flags to pass to the compiler
180     pub compile_flags: Vec<String>,
181     // Extra flags to pass when the compiled code is run (such as --bench)
182     pub run_flags: Option<String>,
183     // If present, the name of a file that this test should match when
184     // pretty-printed
185     pub pp_exact: Option<PathBuf>,
186     // Other crates that should be compiled (typically from the same
187     // directory as the test, but for backwards compatibility reasons
188     // we also check the auxiliary directory)
189     pub aux_builds: Vec<String>,
190     // Environment settings to use for compiling
191     pub rustc_env: Vec<(String, String)>,
192     // Environment settings to use during execution
193     pub exec_env: Vec<(String, String)>,
194     // Lines to check if they appear in the expected debugger output
195     pub check_lines: Vec<String>,
196     // Build documentation for all specified aux-builds as well
197     pub build_aux_docs: bool,
198     // Flag to force a crate to be built with the host architecture
199     pub force_host: bool,
200     // Check stdout for error-pattern output as well as stderr
201     pub check_stdout: bool,
202     // Don't force a --crate-type=dylib flag on the command line
203     pub no_prefer_dynamic: bool,
204     // Run --pretty expanded when running pretty printing tests
205     pub pretty_expanded: bool,
206     // Which pretty mode are we testing with, default to 'normal'
207     pub pretty_mode: String,
208     // Only compare pretty output and don't try compiling
209     pub pretty_compare_only: bool,
210     // Patterns which must not appear in the output of a cfail test.
211     pub forbid_output: Vec<String>,
212     // Revisions to test for incremental compilation.
213     pub revisions: Vec<String>,
214     // Directory (if any) to use for incremental compilation.  This is
215     // not set by end-users; rather it is set by the incremental
216     // testing harness and used when generating compilation
217     // arguments. (In particular, it propagates to the aux-builds.)
218     pub incremental_dir: Option<PathBuf>,
219     // Specifies that a test must actually compile without errors.
220     pub compile_pass: bool,
221     // rustdoc will test the output of the `--test` option
222     pub check_test_line_numbers_match: bool,
223     // The test must be compiled and run successfully. Only used in UI tests for now.
224     pub run_pass: bool,
225     // Skip any codegen step and running the executable. Only for run-pass.
226     pub skip_codegen: bool,
227     // Do not pass `-Z ui-testing` to UI tests
228     pub disable_ui_testing_normalization: bool,
229     // customized normalization rules
230     pub normalize_stdout: Vec<(String, String)>,
231     pub normalize_stderr: Vec<(String, String)>,
232     pub failure_status: i32,
233     pub run_rustfix: bool,
234 }
235
236 impl TestProps {
237     pub fn new() -> Self {
238         TestProps {
239             error_patterns: vec![],
240             compile_flags: vec![],
241             run_flags: None,
242             pp_exact: None,
243             aux_builds: vec![],
244             revisions: vec![],
245             rustc_env: vec![],
246             exec_env: vec![],
247             check_lines: vec![],
248             build_aux_docs: false,
249             force_host: false,
250             check_stdout: false,
251             no_prefer_dynamic: false,
252             pretty_expanded: false,
253             pretty_mode: "normal".to_string(),
254             pretty_compare_only: false,
255             forbid_output: vec![],
256             incremental_dir: None,
257             compile_pass: false,
258             check_test_line_numbers_match: false,
259             run_pass: false,
260             skip_codegen: false,
261             disable_ui_testing_normalization: false,
262             normalize_stdout: vec![],
263             normalize_stderr: vec![],
264             failure_status: -1,
265             run_rustfix: false,
266         }
267     }
268
269     pub fn from_aux_file(&self, testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
270         let mut props = TestProps::new();
271
272         // copy over select properties to the aux build:
273         props.incremental_dir = self.incremental_dir.clone();
274         props.load_from(testfile, cfg, config);
275
276         props
277     }
278
279     pub fn from_file(testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
280         let mut props = TestProps::new();
281         props.load_from(testfile, cfg, config);
282         props
283     }
284
285     /// Load properties from `testfile` into `props`. If a property is
286     /// tied to a particular revision `foo` (indicated by writing
287     /// `//[foo]`), then the property is ignored unless `cfg` is
288     /// `Some("foo")`.
289     fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
290         iter_header(testfile, cfg, &mut |ln| {
291             if let Some(ep) = config.parse_error_pattern(ln) {
292                 self.error_patterns.push(ep);
293             }
294
295             if let Some(flags) = config.parse_compile_flags(ln) {
296                 self.compile_flags
297                     .extend(flags.split_whitespace().map(|s| s.to_owned()));
298             }
299
300             if let Some(edition) = config.parse_edition(ln) {
301                 self.compile_flags.push(format!("--edition={}", edition));
302             }
303
304             if let Some(r) = config.parse_revisions(ln) {
305                 self.revisions.extend(r);
306             }
307
308             if self.run_flags.is_none() {
309                 self.run_flags = config.parse_run_flags(ln);
310             }
311
312             if self.pp_exact.is_none() {
313                 self.pp_exact = config.parse_pp_exact(ln, testfile);
314             }
315
316             if !self.build_aux_docs {
317                 self.build_aux_docs = config.parse_build_aux_docs(ln);
318             }
319
320             if !self.force_host {
321                 self.force_host = config.parse_force_host(ln);
322             }
323
324             if !self.check_stdout {
325                 self.check_stdout = config.parse_check_stdout(ln);
326             }
327
328             if !self.no_prefer_dynamic {
329                 self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
330             }
331
332             if !self.pretty_expanded {
333                 self.pretty_expanded = config.parse_pretty_expanded(ln);
334             }
335
336             if let Some(m) = config.parse_pretty_mode(ln) {
337                 self.pretty_mode = m;
338             }
339
340             if !self.pretty_compare_only {
341                 self.pretty_compare_only = config.parse_pretty_compare_only(ln);
342             }
343
344             if let Some(ab) = config.parse_aux_build(ln) {
345                 self.aux_builds.push(ab);
346             }
347
348             if let Some(ee) = config.parse_env(ln, "exec-env") {
349                 self.exec_env.push(ee);
350             }
351
352             if let Some(ee) = config.parse_env(ln, "rustc-env") {
353                 self.rustc_env.push(ee);
354             }
355
356             if let Some(cl) = config.parse_check_line(ln) {
357                 self.check_lines.push(cl);
358             }
359
360             if let Some(of) = config.parse_forbid_output(ln) {
361                 self.forbid_output.push(of);
362             }
363
364             if !self.check_test_line_numbers_match {
365                 self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
366             }
367
368             if !self.run_pass {
369                 self.run_pass = config.parse_run_pass(ln);
370             }
371
372             if !self.compile_pass {
373                 // run-pass implies must_compile_sucessfully
374                 self.compile_pass = config.parse_compile_pass(ln) || self.run_pass;
375             }
376
377             if !self.skip_codegen {
378                 self.skip_codegen = config.parse_skip_codegen(ln);
379             }
380
381             if !self.disable_ui_testing_normalization {
382                 self.disable_ui_testing_normalization =
383                     config.parse_disable_ui_testing_normalization(ln);
384             }
385
386             if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
387                 self.normalize_stdout.push(rule);
388             }
389             if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
390                 self.normalize_stderr.push(rule);
391             }
392
393             if let Some(code) = config.parse_failure_status(ln) {
394                 self.failure_status = code;
395             }
396
397             if !self.run_rustfix {
398                 self.run_rustfix = config.parse_run_rustfix(ln);
399             }
400         });
401
402         if self.failure_status == -1 {
403             self.failure_status = match config.mode {
404                 Mode::RunFail => 101,
405                 _ => 1,
406             };
407         }
408
409         for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
410             if let Ok(val) = env::var(key) {
411                 if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
412                     self.exec_env.push(((*key).to_owned(), val))
413                 }
414             }
415         }
416     }
417 }
418
419 fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
420     if testfile.is_dir() {
421         return;
422     }
423
424     let comment = if testfile.to_string_lossy().ends_with(".rs") {
425         "//"
426     } else {
427         "#"
428     };
429
430     let comment_with_brace = comment.to_string() + "[";
431
432     let rdr = BufReader::new(File::open(testfile).unwrap());
433     for ln in rdr.lines() {
434         // Assume that any directives will be found before the first
435         // module or function. This doesn't seem to be an optimization
436         // with a warm page cache. Maybe with a cold one.
437         let ln = ln.unwrap();
438         let ln = ln.trim();
439         if ln.starts_with("fn") || ln.starts_with("mod") {
440             return;
441         } else if ln.starts_with(&comment_with_brace) {
442             // A comment like `//[foo]` is specific to revision `foo`
443             if let Some(close_brace) = ln.find(']') {
444                 let open_brace = ln.find('[').unwrap();
445                 let lncfg = &ln[open_brace + 1 .. close_brace];
446                 let matches = match cfg {
447                     Some(s) => s == &lncfg[..],
448                     None => false,
449                 };
450                 if matches {
451                     it(ln[(close_brace + 1)..].trim_left());
452                 }
453             } else {
454                 panic!("malformed condition directive: expected `{}foo]`, found `{}`",
455                         comment_with_brace, ln)
456             }
457         } else if ln.starts_with(comment) {
458             it(ln[comment.len() ..].trim_left());
459         }
460     }
461     return;
462 }
463
464 impl Config {
465     fn parse_error_pattern(&self, line: &str) -> Option<String> {
466         self.parse_name_value_directive(line, "error-pattern")
467     }
468
469     fn parse_forbid_output(&self, line: &str) -> Option<String> {
470         self.parse_name_value_directive(line, "forbid-output")
471     }
472
473     fn parse_aux_build(&self, line: &str) -> Option<String> {
474         self.parse_name_value_directive(line, "aux-build")
475     }
476
477     fn parse_compile_flags(&self, line: &str) -> Option<String> {
478         self.parse_name_value_directive(line, "compile-flags")
479     }
480
481     fn parse_revisions(&self, line: &str) -> Option<Vec<String>> {
482         self.parse_name_value_directive(line, "revisions")
483             .map(|r| r.split_whitespace().map(|t| t.to_string()).collect())
484     }
485
486     fn parse_run_flags(&self, line: &str) -> Option<String> {
487         self.parse_name_value_directive(line, "run-flags")
488     }
489
490     fn parse_check_line(&self, line: &str) -> Option<String> {
491         self.parse_name_value_directive(line, "check")
492     }
493
494     fn parse_force_host(&self, line: &str) -> bool {
495         self.parse_name_directive(line, "force-host")
496     }
497
498     fn parse_build_aux_docs(&self, line: &str) -> bool {
499         self.parse_name_directive(line, "build-aux-docs")
500     }
501
502     fn parse_check_stdout(&self, line: &str) -> bool {
503         self.parse_name_directive(line, "check-stdout")
504     }
505
506     fn parse_no_prefer_dynamic(&self, line: &str) -> bool {
507         self.parse_name_directive(line, "no-prefer-dynamic")
508     }
509
510     fn parse_pretty_expanded(&self, line: &str) -> bool {
511         self.parse_name_directive(line, "pretty-expanded")
512     }
513
514     fn parse_pretty_mode(&self, line: &str) -> Option<String> {
515         self.parse_name_value_directive(line, "pretty-mode")
516     }
517
518     fn parse_pretty_compare_only(&self, line: &str) -> bool {
519         self.parse_name_directive(line, "pretty-compare-only")
520     }
521
522     fn parse_failure_status(&self, line: &str) -> Option<i32> {
523         match self.parse_name_value_directive(line, "failure-status") {
524             Some(code) => code.trim().parse::<i32>().ok(),
525             _ => None,
526         }
527     }
528
529     fn parse_compile_pass(&self, line: &str) -> bool {
530         self.parse_name_directive(line, "compile-pass")
531     }
532
533     fn parse_disable_ui_testing_normalization(&self, line: &str) -> bool {
534         self.parse_name_directive(line, "disable-ui-testing-normalization")
535     }
536
537     fn parse_check_test_line_numbers_match(&self, line: &str) -> bool {
538         self.parse_name_directive(line, "check-test-line-numbers-match")
539     }
540
541     fn parse_run_pass(&self, line: &str) -> bool {
542         self.parse_name_directive(line, "run-pass")
543     }
544
545     fn parse_skip_codegen(&self, line: &str) -> bool {
546         self.parse_name_directive(line, "skip-codegen")
547     }
548
549     fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
550         self.parse_name_value_directive(line, name).map(|nv| {
551             // nv is either FOO or FOO=BAR
552             let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
553
554             match strs.len() {
555                 1 => (strs.pop().unwrap(), "".to_owned()),
556                 2 => {
557                     let end = strs.pop().unwrap();
558                     (strs.pop().unwrap(), end)
559                 }
560                 n => panic!("Expected 1 or 2 strings, not {}", n),
561             }
562         })
563     }
564
565     fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
566         if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
567             Some(PathBuf::from(&s))
568         } else if self.parse_name_directive(line, "pp-exact") {
569             testfile.file_name().map(PathBuf::from)
570         } else {
571             None
572         }
573     }
574
575     fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
576         if self.parse_cfg_name_directive(line, prefix) {
577             let from = match parse_normalization_string(&mut line) {
578                 Some(s) => s,
579                 None => return None,
580             };
581             let to = match parse_normalization_string(&mut line) {
582                 Some(s) => s,
583                 None => return None,
584             };
585             Some((from, to))
586         } else {
587             None
588         }
589     }
590
591     /// Parses a name-value directive which contains config-specific information, e.g. `ignore-x86`
592     /// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
593     fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> bool {
594         if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
595             let name = line[prefix.len() + 1..]
596                 .split(&[':', ' '][..])
597                 .next()
598                 .unwrap();
599
600             name == "test" ||
601                 util::matches_os(&self.target, name) ||             // target
602                 name == util::get_arch(&self.target) ||             // architecture
603                 name == util::get_pointer_width(&self.target) ||    // pointer width
604                 name == self.stage_id.split('-').next().unwrap() || // stage
605                 Some(name) == util::get_env(&self.target) ||        // env
606                 match self.mode {
607                     common::DebugInfoGdb => name == "gdb",
608                     common::DebugInfoLldb => name == "lldb",
609                     common::Pretty => name == "pretty",
610                     _ => false,
611                 } || (self.target != self.host && name == "cross-compile")
612         } else {
613             false
614         }
615     }
616
617     fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
618         // returns whether this line contains this prefix or not. For prefix
619         // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
620         // "ignore-android" etc.
621         line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-')
622     }
623
624     fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
625         // Ensure the directive is a whole word. Do not match "ignore-x86" when
626         // the line says "ignore-x86_64".
627         line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
628             None | Some(&b' ') | Some(&b':') => true,
629             _ => false,
630         }
631     }
632
633     pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
634         let colon = directive.len();
635         if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
636             let value = line[(colon + 1)..].to_owned();
637             debug!("{}: {}", directive, value);
638             Some(expand_variables(value, self))
639         } else {
640             None
641         }
642     }
643
644     pub fn find_rust_src_root(&self) -> Option<PathBuf> {
645         let mut path = self.src_base.clone();
646         let path_postfix = Path::new("src/etc/lldb_batchmode.py");
647
648         while path.pop() {
649             if path.join(&path_postfix).is_file() {
650                 return Some(path);
651             }
652         }
653
654         None
655     }
656
657     fn parse_run_rustfix(&self, line: &str) -> bool {
658         self.parse_name_directive(line, "run-rustfix")
659     }
660
661     fn parse_edition(&self, line: &str) -> Option<String> {
662         self.parse_name_value_directive(line, "edition")
663     }
664 }
665
666 pub fn lldb_version_to_int(version_string: &str) -> isize {
667     let error_string = format!(
668         "Encountered LLDB version string with unexpected format: {}",
669         version_string
670     );
671     version_string.parse().expect(&error_string)
672 }
673
674 fn expand_variables(mut value: String, config: &Config) -> String {
675     const CWD: &'static str = "{{cwd}}";
676     const SRC_BASE: &'static str = "{{src-base}}";
677     const BUILD_BASE: &'static str = "{{build-base}}";
678
679     if value.contains(CWD) {
680         let cwd = env::current_dir().unwrap();
681         value = value.replace(CWD, &cwd.to_string_lossy());
682     }
683
684     if value.contains(SRC_BASE) {
685         value = value.replace(SRC_BASE, &config.src_base.to_string_lossy());
686     }
687
688     if value.contains(BUILD_BASE) {
689         value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
690     }
691
692     value
693 }
694
695 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
696 /// variable after the end of the quoted string.
697 ///
698 /// # Examples
699 ///
700 /// ```
701 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
702 /// let first = parse_normalization_string(&mut s);
703 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
704 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
705 /// ```
706 fn parse_normalization_string(line: &mut &str) -> Option<String> {
707     // FIXME support escapes in strings.
708     let begin = match line.find('"') {
709         Some(i) => i + 1,
710         None => return None,
711     };
712     let end = match line[begin..].find('"') {
713         Some(i) => i + begin,
714         None => return None,
715     };
716     let result = line[begin..end].to_owned();
717     *line = &line[end + 1..];
718     Some(result)
719 }