]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
New upstream version 1.14.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 extern crate rustc_errors as errors;
23
24 use rustc::session::Session;
25 use rustc::session::config::{self, Input};
26 use rustc_driver::{driver, CompilerCalls, Compilation};
27 use syntax::ast;
28
29 use std::path::PathBuf;
30
31 struct TestCalls {
32 count: u32
33 }
34
35 impl<'a> CompilerCalls<'a> for TestCalls {
36 fn early_callback(&mut self,
37 _: &getopts::Matches,
38 _: &config::Options,
39 _: &ast::CrateConfig,
40 _: &errors::registry::Registry,
41 _: config::ErrorOutputType)
42 -> Compilation {
43 self.count *= 2;
44 Compilation::Continue
45 }
46
47 fn late_callback(&mut self,
48 _: &getopts::Matches,
49 _: &Session,
50 _: &Input,
51 _: &Option<PathBuf>,
52 _: &Option<PathBuf>)
53 -> Compilation {
54 self.count *= 3;
55 Compilation::Stop
56 }
57
58 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
59 -> (Input, Option<PathBuf>) {
60 self.count *= 5;
61 (input, input_path)
62 }
63
64 fn no_input(&mut self,
65 _: &getopts::Matches,
66 _: &config::Options,
67 _: &ast::CrateConfig,
68 _: &Option<PathBuf>,
69 _: &Option<PathBuf>,
70 _: &errors::registry::Registry)
71 -> Option<(Input, Option<PathBuf>)> {
72 panic!("This shouldn't happen");
73 }
74
75 fn build_controller(&mut self,
76 _: &Session,
77 _: &getopts::Matches)
78 -> driver::CompileController<'a> {
79 panic!("This shouldn't be called");
80 }
81 }
82
83
84 fn main() {
85 let mut tc = TestCalls { count: 1 };
86 // we should never get use this filename, but lets make sure they are valid args.
87 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
88 rustc_driver::run_compiler(&args, &mut tc, None, None);
89 assert_eq!(tc.count, 30);
90 }