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