]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
New upstream version 1.12.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 _: &ast::CrateConfig,
51 _: &Input,
52 _: &Option<PathBuf>,
53 _: &Option<PathBuf>)
54 -> Compilation {
55 self.count *= 3;
56 Compilation::Stop
57 }
58
59 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
60 -> (Input, Option<PathBuf>) {
61 self.count *= 5;
62 (input, input_path)
63 }
64
65 fn no_input(&mut self,
66 _: &getopts::Matches,
67 _: &config::Options,
68 _: &ast::CrateConfig,
69 _: &Option<PathBuf>,
70 _: &Option<PathBuf>,
71 _: &errors::registry::Registry)
72 -> Option<(Input, Option<PathBuf>)> {
73 panic!("This shouldn't happen");
74 }
75
76 fn build_controller(&mut self,
77 _: &Session,
78 _: &getopts::Matches)
79 -> driver::CompileController<'a> {
80 panic!("This shouldn't be called");
81 }
82 }
83
84
85 fn main() {
86 let mut tc = TestCalls { count: 1 };
87 // we should never get use this filename, but lets make sure they are valid args.
88 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
89 rustc_driver::run_compiler(&args, &mut tc);
90 assert_eq!(tc.count, 30);
91 }