]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
85aaf69f
SL
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
d9579d0f 13// ignore-cross-compile
85aaf69f 14
c34b1796 15#![feature(rustc_private, path)]
85aaf69f
SL
16#![feature(core)]
17
18extern crate getopts;
19extern crate rustc;
20extern crate rustc_driver;
21extern crate syntax;
3157f602 22extern crate rustc_errors as errors;
85aaf69f
SL
23
24use rustc::session::Session;
25use rustc::session::config::{self, Input};
26use rustc_driver::{driver, CompilerCalls, Compilation};
5bcae85e 27use syntax::ast;
85aaf69f 28
c34b1796 29use std::path::PathBuf;
85aaf69f
SL
30
31struct TestCalls {
32 count: u32
33}
34
35impl<'a> CompilerCalls<'a> for TestCalls {
36 fn early_callback(&mut self,
37 _: &getopts::Matches,
7453a54e 38 _: &config::Options,
5bcae85e 39 _: &ast::CrateConfig,
3157f602 40 _: &errors::registry::Registry,
9cc50fc6 41 _: config::ErrorOutputType)
85aaf69f
SL
42 -> Compilation {
43 self.count *= 2;
44 Compilation::Continue
45 }
46
47 fn late_callback(&mut self,
48 _: &getopts::Matches,
49 _: &Session,
50 _: &Input,
c34b1796
AL
51 _: &Option<PathBuf>,
52 _: &Option<PathBuf>)
85aaf69f
SL
53 -> Compilation {
54 self.count *= 3;
55 Compilation::Stop
56 }
57
c34b1796
AL
58 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
59 -> (Input, Option<PathBuf>) {
85aaf69f
SL
60 self.count *= 5;
61 (input, input_path)
62 }
63
64 fn no_input(&mut self,
65 _: &getopts::Matches,
66 _: &config::Options,
5bcae85e 67 _: &ast::CrateConfig,
c34b1796
AL
68 _: &Option<PathBuf>,
69 _: &Option<PathBuf>,
3157f602 70 _: &errors::registry::Registry)
c34b1796 71 -> Option<(Input, Option<PathBuf>)> {
85aaf69f
SL
72 panic!("This shouldn't happen");
73 }
74
a7813a04
XL
75 fn build_controller(&mut self,
76 _: &Session,
77 _: &getopts::Matches)
78 -> driver::CompileController<'a> {
85aaf69f
SL
79 panic!("This shouldn't be called");
80 }
81}
82
83
84fn 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()];
c30ab7b3 88 rustc_driver::run_compiler(&args, &mut tc, None, None);
62682a34 89 assert_eq!(tc.count, 30);
85aaf69f 90}