1 extern crate cc;
2 extern crate tempdir;
3
4 use std::env;
5 use std::ffi::OsString;
6 use std::path::Path;
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")
67 == false
68 );
69 assert!(
70 compiler
71 .cflags_env()
72 .into_string()
73 .unwrap()
74 .contains(" lol-this-is-not-a-compiler")
75 == false
76 );
77
78 env::set_var("CC", "");
79 }
80
leading_spaces()81 fn leading_spaces() {
82 let test = Test::gnu();
83 test.shim("ccache");
84
85 env::set_var("CC", " test ");
86 let compiler = test.gcc().file("foo.c").get_compiler();
87 assert_eq!(compiler.path(), Path::new("test"));
88
89 env::set_var("CC", "");
90 }
91
extra_flags()92 fn extra_flags() {
93 let test = Test::gnu();
94 test.shim("ccache");
95
96 env::set_var("CC", "ccache cc -m32");
97 let compiler = test.gcc().file("foo.c").get_compiler();
98 assert_eq!(compiler.path(), Path::new("cc"));
99 }
100
path_to_ccache()101 fn path_to_ccache() {
102 let test = Test::gnu();
103 test.shim("ccache");
104
105 env::set_var("CC", "/path/to/ccache.exe cc -m32");
106 let compiler = test.gcc().file("foo.c").get_compiler();
107 assert_eq!(compiler.path(), Path::new("cc"));
108 assert_eq!(
109 compiler.cc_env(),
110 OsString::from("/path/to/ccache.exe cc -m32"),
111 );
112 }
113
more_spaces()114 fn more_spaces() {
115 let test = Test::gnu();
116 test.shim("ccache");
117
118 env::set_var("CC", "cc -m32");
119 let compiler = test.gcc().file("foo.c").get_compiler();
120 assert_eq!(compiler.path(), Path::new("cc"));
121 }
122