]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/header.rs
edab2a5ec034c15511349c0c86635c4a535c8805
[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             } else {
396                 self.failure_status = match config.mode {
397                     Mode::RunFail => 101,
398                     _ => 1,
399                 };
400             }
401
402             if !self.run_rustfix {
403                 self.run_rustfix = config.parse_run_rustfix(ln);
404             }
405         });
406
407         for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
408             if let Ok(val) = env::var(key) {
409                 if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
410                     self.exec_env.push(((*key).to_owned(), val))
411                 }
412             }
413         }
414     }
415 }
416
417 fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
418     if testfile.is_dir() {
419         return;
420     }
421
422     let comment = if testfile.to_string_lossy().ends_with(".rs") {
423         "//"
424     } else {
425         "#"
426     };
427
428     let comment_with_brace = comment.to_string() + "[";
429
430     let rdr = BufReader::new(File::open(testfile).unwrap());
431     for ln in rdr.lines() {
432         // Assume that any directives will be found before the first
433         // module or function. This doesn't seem to be an optimization
434         // with a warm page cache. Maybe with a cold one.
435         let ln = ln.unwrap();
436         let ln = ln.trim();
437         if ln.starts_with("fn") || ln.starts_with("mod") {
438             return;
439         } else if ln.starts_with(&comment_with_brace) {
440             // A comment like `//[foo]` is specific to revision `foo`
441             if let Some(close_brace) = ln.find(']') {
442                 let open_brace = ln.find('[').unwrap();
443                 let lncfg = &ln[open_brace + 1 .. close_brace];
444                 let matches = match cfg {
445                     Some(s) => s == &lncfg[..],
446                     None => false,
447                 };
448                 if matches {
449                     it(ln[(close_brace + 1)..].trim_left());
450                 }
451             } else {
452                 panic!("malformed condition directive: expected `{}foo]`, found `{}`",
453                         comment_with_brace, ln)
454             }
455         } else if ln.starts_with(comment) {
456             it(ln[comment.len() ..].trim_left());
457         }
458     }
459     return;
460 }
461
462 impl Config {
463     fn parse_error_pattern(&self, line: &str) -> Option<String> {
464         self.parse_name_value_directive(line, "error-pattern")
465     }
466
467     fn parse_forbid_output(&self, line: &str) -> Option<String> {
468         self.parse_name_value_directive(line, "forbid-output")
469     }
470
471     fn parse_aux_build(&self, line: &str) -> Option<String> {
472         self.parse_name_value_directive(line, "aux-build")
473     }
474
475     fn parse_compile_flags(&self, line: &str) -> Option<String> {
476         self.parse_name_value_directive(line, "compile-flags")
477     }
478
479     fn parse_revisions(&self, line: &str) -> Option<Vec<String>> {
480         self.parse_name_value_directive(line, "revisions")
481             .map(|r| r.split_whitespace().map(|t| t.to_string()).collect())
482     }
483
484     fn parse_run_flags(&self, line: &str) -> Option<String> {
485         self.parse_name_value_directive(line, "run-flags")
486     }
487
488     fn parse_check_line(&self, line: &str) -> Option<String> {
489         self.parse_name_value_directive(line, "check")
490     }
491
492     fn parse_force_host(&self, line: &str) -> bool {
493         self.parse_name_directive(line, "force-host")
494     }
495
496     fn parse_build_aux_docs(&self, line: &str) -> bool {
497         self.parse_name_directive(line, "build-aux-docs")
498     }
499
500     fn parse_check_stdout(&self, line: &str) -> bool {
501         self.parse_name_directive(line, "check-stdout")
502     }
503
504     fn parse_no_prefer_dynamic(&self, line: &str) -> bool {
505         self.parse_name_directive(line, "no-prefer-dynamic")
506     }
507
508     fn parse_pretty_expanded(&self, line: &str) -> bool {
509         self.parse_name_directive(line, "pretty-expanded")
510     }
511
512     fn parse_pretty_mode(&self, line: &str) -> Option<String> {
513         self.parse_name_value_directive(line, "pretty-mode")
514     }
515
516     fn parse_pretty_compare_only(&self, line: &str) -> bool {
517         self.parse_name_directive(line, "pretty-compare-only")
518     }
519
520     fn parse_failure_status(&self, line: &str) -> Option<i32> {
521         match self.parse_name_value_directive(line, "failure-status") {
522             Some(code) => code.trim().parse::<i32>().ok(),
523             _ => None,
524         }
525     }
526
527     fn parse_compile_pass(&self, line: &str) -> bool {
528         self.parse_name_directive(line, "compile-pass")
529     }
530
531     fn parse_disable_ui_testing_normalization(&self, line: &str) -> bool {
532         self.parse_name_directive(line, "disable-ui-testing-normalization")
533     }
534
535     fn parse_check_test_line_numbers_match(&self, line: &str) -> bool {
536         self.parse_name_directive(line, "check-test-line-numbers-match")
537     }
538
539     fn parse_run_pass(&self, line: &str) -> bool {
540         self.parse_name_directive(line, "run-pass")
541     }
542
543     fn parse_skip_codegen(&self, line: &str) -> bool {
544         self.parse_name_directive(line, "skip-codegen")
545     }
546
547     fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
548         self.parse_name_value_directive(line, name).map(|nv| {
549             // nv is either FOO or FOO=BAR
550             let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
551
552             match strs.len() {
553                 1 => (strs.pop().unwrap(), "".to_owned()),
554                 2 => {
555                     let end = strs.pop().unwrap();
556                     (strs.pop().unwrap(), end)
557                 }
558                 n => panic!("Expected 1 or 2 strings, not {}", n),
559             }
560         })
561     }
562
563     fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
564         if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
565             Some(PathBuf::from(&s))
566         } else if self.parse_name_directive(line, "pp-exact") {
567             testfile.file_name().map(PathBuf::from)
568         } else {
569             None
570         }
571     }
572
573     fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
574         if self.parse_cfg_name_directive(line, prefix) {
575             let from = match parse_normalization_string(&mut line) {
576                 Some(s) => s,
577                 None => return None,
578             };
579             let to = match parse_normalization_string(&mut line) {
580                 Some(s) => s,
581                 None => return None,
582             };
583             Some((from, to))
584         } else {
585             None
586         }
587     }
588
589     /// Parses a name-value directive which contains config-specific information, e.g. `ignore-x86`
590     /// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
591     fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> bool {
592         if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
593             let name = line[prefix.len() + 1..]
594                 .split(&[':', ' '][..])
595                 .next()
596                 .unwrap();
597
598             name == "test" ||
599                 util::matches_os(&self.target, name) ||             // target
600                 name == util::get_arch(&self.target) ||             // architecture
601                 name == util::get_pointer_width(&self.target) ||    // pointer width
602                 name == self.stage_id.split('-').next().unwrap() || // stage
603                 Some(name) == util::get_env(&self.target) ||        // env
604                 match self.mode {
605                     common::DebugInfoGdb => name == "gdb",
606                     common::DebugInfoLldb => name == "lldb",
607                     common::Pretty => name == "pretty",
608                     _ => false,
609                 } || (self.target != self.host && name == "cross-compile")
610         } else {
611             false
612         }
613     }
614
615     fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
616         // returns whether this line contains this prefix or not. For prefix
617         // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
618         // "ignore-android" etc.
619         line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-')
620     }
621
622     fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
623         // Ensure the directive is a whole word. Do not match "ignore-x86" when
624         // the line says "ignore-x86_64".
625         line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
626             None | Some(&b' ') | Some(&b':') => true,
627             _ => false,
628         }
629     }
630
631     pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
632         let colon = directive.len();
633         if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
634             let value = line[(colon + 1)..].to_owned();
635             debug!("{}: {}", directive, value);
636             Some(expand_variables(value, self))
637         } else {
638             None
639         }
640     }
641
642     pub fn find_rust_src_root(&self) -> Option<PathBuf> {
643         let mut path = self.src_base.clone();
644         let path_postfix = Path::new("src/etc/lldb_batchmode.py");
645
646         while path.pop() {
647             if path.join(&path_postfix).is_file() {
648                 return Some(path);
649             }
650         }
651
652         None
653     }
654
655     fn parse_run_rustfix(&self, line: &str) -> bool {
656         self.parse_name_directive(line, "run-rustfix")
657     }
658
659     fn parse_edition(&self, line: &str) -> Option<String> {
660         self.parse_name_value_directive(line, "edition")
661     }
662 }
663
664 pub fn lldb_version_to_int(version_string: &str) -> isize {
665     let error_string = format!(
666         "Encountered LLDB version string with unexpected format: {}",
667         version_string
668     );
669     version_string.parse().expect(&error_string)
670 }
671
672 fn expand_variables(mut value: String, config: &Config) -> String {
673     const CWD: &'static str = "{{cwd}}";
674     const SRC_BASE: &'static str = "{{src-base}}";
675     const BUILD_BASE: &'static str = "{{build-base}}";
676
677     if value.contains(CWD) {
678         let cwd = env::current_dir().unwrap();
679         value = value.replace(CWD, &cwd.to_string_lossy());
680     }
681
682     if value.contains(SRC_BASE) {
683         value = value.replace(SRC_BASE, &config.src_base.to_string_lossy());
684     }
685
686     if value.contains(BUILD_BASE) {
687         value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
688     }
689
690     value
691 }
692
693 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
694 /// variable after the end of the quoted string.
695 ///
696 /// # Examples
697 ///
698 /// ```
699 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
700 /// let first = parse_normalization_string(&mut s);
701 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
702 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
703 /// ```
704 fn parse_normalization_string(line: &mut &str) -> Option<String> {
705     // FIXME support escapes in strings.
706     let begin = match line.find('"') {
707         Some(i) => i + 1,
708         None => return None,
709     };
710     let end = match line[begin..].find('"') {
711         Some(i) => i + begin,
712         None => return None,
713     };
714     let result = line[begin..end].to_owned();
715     *line = &line[end + 1..];
716     Some(result)
717 }