]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
Imported Upstream version 1.8.0+dfsg1
[rustc.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, errors};
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 _: &config::Options,
38 _: &diagnostics::registry::Registry,
39 _: config::ErrorOutputType)
40 -> Compilation {
41 self.count *= 2;
42 Compilation::Continue
43 }
44
45 fn late_callback(&mut self,
46 _: &getopts::Matches,
47 _: &Session,
48 _: &Input,
49 _: &Option<PathBuf>,
50 _: &Option<PathBuf>)
51 -> Compilation {
52 self.count *= 3;
53 Compilation::Stop
54 }
55
56 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
57 -> (Input, Option<PathBuf>) {
58 self.count *= 5;
59 (input, input_path)
60 }
61
62 fn no_input(&mut self,
63 _: &getopts::Matches,
64 _: &config::Options,
65 _: &Option<PathBuf>,
66 _: &Option<PathBuf>,
67 _: &diagnostics::registry::Registry)
68 -> Option<(Input, Option<PathBuf>)> {
69 panic!("This shouldn't happen");
70 }
71
72 fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
73 panic!("This shouldn't be called");
74 }
75 }
76
77
78 fn main() {
79 let mut tc = TestCalls { count: 1 };
80 // we should never get use this filename, but lets make sure they are valid args.
81 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
82 rustc_driver::run_compiler(&args, &mut tc);
83 assert_eq!(tc.count, 30);
84 }