1 extern crate cc;
2 extern crate tempdir;
3 
4 use std::env;
5 use std::path::Path;
6 use std::ffi::OsString;
7 
8 mod support;
9 use support::Test;
10 
11 #[test]
main()12 fn main() {
13     ccache();
14     distcc();
15     ccache_spaces();
16     ccache_env_flags();
17     leading_spaces();
18     extra_flags();
19     path_to_ccache();
20     more_spaces();
21 }
22 
ccache()23 fn ccache() {
24     let test = Test::gnu();
25 
26     env::set_var("CC", "ccache cc");
27     let compiler = test.gcc().file("foo.c").get_compiler();
28 
29     assert_eq!(compiler.path(), Path::new("cc"));
30 }
31 
ccache_spaces()32 fn ccache_spaces() {
33     let test = Test::gnu();
34     test.shim("ccache");
35 
36     env::set_var("CC", "ccache        cc");
37     let compiler = test.gcc().file("foo.c").get_compiler();
38     assert_eq!(compiler.path(), Path::new("cc"));
39 }
40 
distcc()41 fn distcc() {
42     let test = Test::gnu();
43     test.shim("distcc");
44 
45     env::set_var("CC", "distcc cc");
46     let compiler = test.gcc().file("foo.c").get_compiler();
47     assert_eq!(compiler.path(), Path::new("cc"));
48 }
49 
ccache_env_flags()50 fn ccache_env_flags() {
51     let test = Test::gnu();
52     test.shim("ccache");
53 
54     env::set_var("CC", "ccache lol-this-is-not-a-compiler");
55     let compiler = test.gcc().file("foo.c").get_compiler();
56     assert_eq!(compiler.path(), Path::new("lol-this-is-not-a-compiler"));
57     assert_eq!(
58         compiler.cc_env(),
59         OsString::from("ccache lol-this-is-not-a-compiler")
60     );
61     assert!(
62         compiler
63             .cflags_env()
64             .into_string()
65             .unwrap()
66             .contains("ccache") == false
67     );
68     assert!(
69         compiler
70             .cflags_env()
71             .into_string()
72             .unwrap()
73             .contains(" lol-this-is-not-a-compiler") == false
74     );
75 
76     env::set_var("CC", "");
77 }
78 
leading_spaces()79 fn leading_spaces() {
80     let test = Test::gnu();
81     test.shim("ccache");
82 
83     env::set_var("CC", " test ");
84     let compiler = test.gcc().file("foo.c").get_compiler();
85     assert_eq!(compiler.path(), Path::new("test"));
86 
87     env::set_var("CC", "");
88 }
89 
extra_flags()90 fn extra_flags() {
91     let test = Test::gnu();
92     test.shim("ccache");
93 
94     env::set_var("CC", "ccache cc -m32");
95     let compiler = test.gcc().file("foo.c").get_compiler();
96     assert_eq!(compiler.path(), Path::new("cc"));
97 }
98 
path_to_ccache()99 fn path_to_ccache() {
100     let test = Test::gnu();
101     test.shim("ccache");
102 
103     env::set_var("CC", "/path/to/ccache.exe cc -m32");
104     let compiler = test.gcc().file("foo.c").get_compiler();
105     assert_eq!(compiler.path(), Path::new("cc"));
106     assert_eq!(
107         compiler.cc_env(),
108         OsString::from("/path/to/ccache.exe cc -m32"),
109     );
110 }
111 
more_spaces()112 fn more_spaces() {
113     let test = Test::gnu();
114     test.shim("ccache");
115 
116     env::set_var("CC", "cc -m32");
117     let compiler = test.gcc().file("foo.c").get_compiler();
118     assert_eq!(compiler.path(), Path::new("cc"));
119 }
120