]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
Use `assert_eq!` instead of `assert!` in tests
[rust.git] / src / test / run-pass-fulldeps / compiler-calls.rs
1 // Copyright 2015 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 // Test that the CompilerCalls interface to the compiler works.
12
13 // ignore-cross-compile
14
15 #![feature(rustc_private, path)]
16 #![feature(core)]
17
18 extern crate getopts;
19 extern crate rustc;
20 extern crate rustc_driver;
21 extern crate syntax;
22
23 use rustc::session::Session;
24 use rustc::session::config::{self, Input};
25 use rustc_driver::{driver, CompilerCalls, Compilation};
26 use syntax::diagnostics;
27
28 use std::path::PathBuf;
29
30 struct TestCalls {
31     count: u32
32 }
33
34 impl<'a> CompilerCalls<'a> for TestCalls {
35     fn early_callback(&mut self,
36                       _: &getopts::Matches,
37                       _: &diagnostics::registry::Registry)
38                       -> Compilation {
39         self.count *= 2;
40         Compilation::Continue
41     }
42
43     fn late_callback(&mut self,
44                      _: &getopts::Matches,
45                      _: &Session,
46                      _: &Input,
47                      _: &Option<PathBuf>,
48                      _: &Option<PathBuf>)
49                      -> Compilation {
50         self.count *= 3;
51         Compilation::Stop
52     }
53
54     fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
55                   -> (Input, Option<PathBuf>) {
56         self.count *= 5;
57         (input, input_path)
58     }
59
60     fn no_input(&mut self,
61                 _: &getopts::Matches,
62                 _: &config::Options,
63                 _: &Option<PathBuf>,
64                 _: &Option<PathBuf>,
65                 _: &diagnostics::registry::Registry)
66                 -> Option<(Input, Option<PathBuf>)> {
67         panic!("This shouldn't happen");
68     }
69
70     fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
71         panic!("This shouldn't be called");
72     }
73 }
74
75
76 fn main() {
77     let mut tc = TestCalls { count: 1 };
78     // we should never get use this filename, but lets make sure they are valid args.
79     let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
80     rustc_driver::run_compiler(&args, &mut tc);
81     assert_eq!(tc.count, 30);
82 }