@@ -6,9 +6,11 @@ class TestActivate < TestCase
6
6
def setup
7
7
super
8
8
9
- @save_env = %w[ PATH CPATH LIBRARY_PATH ] . inject ( { } ) do |env , var |
9
+ @save_env = %w[ PATH CPATH LIBRARY_PATH LDFLAGS ] . inject ( { } ) do |env , var |
10
10
env . update ( var => ENV [ var ] )
11
11
end
12
+ $LDFLAGS = nil
13
+ $CPPFLAGS = nil
12
14
13
15
FileUtils . rm_rf ( [ "tmp" , "ports" ] ) # remove any previous test files
14
16
@@ -20,6 +22,8 @@ def setup
20
22
def teardown
21
23
FileUtils . rm_rf ( [ "tmp" , "ports" ] ) # remove any previous test files
22
24
25
+ $LDFLAGS = nil
26
+ $CPPFLAGS = nil
23
27
@save_env . each do |var , val |
24
28
ENV [ var ] = val
25
29
end
@@ -28,79 +32,131 @@ def teardown
28
32
end
29
33
30
34
def test_PATH_env_var_when_bin_does_not_exist
35
+ ENV [ "PATH" ] = "foo"
31
36
refute ( Dir . exist? ( bin_path ) )
32
- refute ( path_elements ( 'PATH' ) . include? ( bin_path ) )
37
+ refute_includes ( path_elements ( 'PATH' ) , bin_path )
33
38
34
39
recipe . activate
35
40
36
- refute ( path_elements ( 'PATH' ) . include? ( bin_path ) )
41
+ refute_includes ( path_elements ( 'PATH' ) , bin_path )
37
42
end
38
43
39
44
def test_PATH_env_var_when_bin_exists
45
+ ENV [ "PATH" ] = "foo"
40
46
FileUtils . mkdir_p ( bin_path )
41
- refute ( path_elements ( 'PATH' ) . include? ( bin_path ) )
47
+ refute_includes ( path_elements ( 'PATH' ) , bin_path )
42
48
43
49
recipe . activate
44
50
45
- assert ( path_elements ( 'PATH' ) . include? ( bin_path ) )
51
+ assert_includes ( path_elements ( 'PATH' ) , bin_path )
52
+ assert_equal ( path_elements ( 'PATH' ) . first , bin_path )
46
53
end
47
54
48
55
def test_CPATH_env_var_when_include_does_not_exist
56
+ ENV [ "CPATH" ] = "foo"
49
57
refute ( Dir . exist? ( include_path ) )
50
- refute ( path_elements ( 'CPATH' ) . include? ( include_path ) )
58
+ refute_includes ( path_elements ( 'CPATH' ) , include_path )
51
59
52
60
recipe . activate
53
61
54
- refute ( path_elements ( 'CPATH' ) . include? ( include_path ) )
62
+ refute_includes ( path_elements ( 'CPATH' ) , include_path )
55
63
end
56
64
57
65
def test_CPATH_env_var_when_include_exists
66
+ ENV [ "CPATH" ] = "foo"
58
67
FileUtils . mkdir_p ( include_path )
59
- refute ( path_elements ( 'CPATH' ) . include? ( include_path ) )
68
+ refute_includes ( path_elements ( 'CPATH' ) , include_path )
60
69
61
70
recipe . activate
62
71
63
- assert ( path_elements ( 'CPATH' ) . include? ( include_path ) )
72
+ assert_includes ( path_elements ( 'CPATH' ) , include_path )
73
+ assert_equal ( path_elements ( 'CPATH' ) . first , include_path )
64
74
end
65
75
66
76
def test_LIBRARY_PATH_env_var_when_lib_does_not_exist
77
+ ENV [ "LIBRARY_PATH" ] = "foo"
67
78
refute ( Dir . exist? ( lib_path ) )
68
- refute ( path_elements ( 'LIBRARY_PATH' ) . include? ( lib_path ) )
79
+ refute_includes ( path_elements ( 'LIBRARY_PATH' ) , lib_path )
69
80
70
81
recipe . activate
71
82
72
- refute ( path_elements ( 'LIBRARY_PATH' ) . include? ( lib_path ) )
83
+ refute_includes ( path_elements ( 'LIBRARY_PATH' ) , lib_path )
73
84
end
74
85
75
86
def test_LIBRARY_PATH_env_var_when_lib_exists
87
+ ENV [ "LIBRARY_PATH" ] = "foo"
76
88
FileUtils . mkdir_p ( lib_path )
77
- refute ( path_elements ( 'LIBRARY_PATH' ) . include? ( lib_path ) )
89
+ refute_includes ( path_elements ( 'LIBRARY_PATH' ) , lib_path )
78
90
79
91
recipe . activate
80
92
81
- assert ( path_elements ( 'LIBRARY_PATH' ) . include? ( lib_path ) )
93
+ assert_includes ( path_elements ( 'LIBRARY_PATH' ) , lib_path )
94
+ assert_equal ( path_elements ( 'LIBRARY_PATH' ) . first , lib_path )
82
95
end
83
96
84
97
def test_LDFLAGS_env_var_when_not_cross_compiling
98
+ ENV [ "LDFLAGS" ] = "-lfoo"
85
99
FileUtils . mkdir_p ( lib_path )
86
100
assert_equal ( recipe . host , recipe . original_host ) # assert on setup)
87
101
88
- refute ( flag_elements ( 'LDFLAGS' ) . include? ( "-L#{ lib_path } " ) )
102
+ refute_includes ( flag_elements ( 'LDFLAGS' ) , "-L#{ lib_path } " )
89
103
90
104
recipe . activate
91
105
92
- refute ( flag_elements ( 'LDFLAGS' ) . include? ( "-L#{ lib_path } " ) )
106
+ refute_includes ( flag_elements ( 'LDFLAGS' ) , "-L#{ lib_path } " )
93
107
end
94
108
95
109
def test_LDFLAGS_env_var_when_cross_compiling
110
+ ENV [ "LDFLAGS" ] = "-lfoo"
96
111
recipe . host = recipe . original_host + "-x" # make them not-equal
97
112
FileUtils . mkdir_p ( lib_path )
98
113
99
- refute ( flag_elements ( 'LDFLAGS' ) . include? ( "-L#{ lib_path } " ) )
114
+ refute_includes ( flag_elements ( 'LDFLAGS' ) , "-L#{ lib_path } " )
100
115
101
116
recipe . activate
102
117
103
- assert ( flag_elements ( 'LDFLAGS' ) . include? ( "-L#{ lib_path } " ) )
118
+ assert_includes ( flag_elements ( 'LDFLAGS' ) , "-L#{ lib_path } " )
119
+ assert_equal ( flag_elements ( 'LDFLAGS' ) . first , "-L#{ lib_path } " )
120
+ end
121
+
122
+ def test_LDFLAGS_global_not_set_when_mkmf_is_false
123
+ $LDFLAGS = "-lm"
124
+ FileUtils . mkdir_p ( lib_path )
125
+
126
+ recipe . activate ( mkmf : false )
127
+
128
+ refute_includes ( $LDFLAGS. split , "-l#{ recipe . name } " )
129
+ refute_includes ( $LDFLAGS. split , "-L#{ lib_path } " )
130
+ end
131
+
132
+ def test_LDFLAGS_global_set_in_mkmf
133
+ $LDFLAGS = '-lm'
134
+ FileUtils . mkdir_p ( lib_path )
135
+
136
+ recipe . activate ( mkmf : true )
137
+
138
+ assert_includes ( $LDFLAGS. split , "-l#{ recipe . name } " )
139
+ assert_includes ( $LDFLAGS. split , "-L#{ lib_path } " )
140
+ assert_equal ( $LDFLAGS. split . first , "-L#{ lib_path } " )
141
+ end
142
+
143
+ def test_CPPFLAGS_global_not_set_when_mkmf_is_false
144
+ $CPPFLAGS = "-Ifoo"
145
+ FileUtils . mkdir_p ( include_path )
146
+
147
+ recipe . activate ( mkmf : false )
148
+
149
+ refute_includes ( $CPPFLAGS. split , "-I#{ include_path } " )
150
+ end
151
+
152
+ def test_CPPFLAGS_global_set_in_mkmf
153
+ $CPPFLAGS = '-Ifoo'
154
+ FileUtils . mkdir_p ( include_path )
155
+
156
+ recipe . activate ( mkmf : true )
157
+
158
+ assert_includes ( $CPPFLAGS. split , "-I#{ include_path } " )
159
+ assert_equal ( $CPPFLAGS. split . first , "-I#{ include_path } " )
104
160
end
105
161
106
162
private
@@ -114,14 +170,14 @@ def flag_elements(varname)
114
170
end
115
171
116
172
def bin_path
117
- File . join ( recipe . path , "bin" )
173
+ MiniPortile . native_path ( File . join ( recipe . path , "bin" ) )
118
174
end
119
175
120
176
def include_path
121
- File . join ( recipe . path , "include" )
177
+ MiniPortile . native_path ( File . join ( recipe . path , "include" ) )
122
178
end
123
179
124
180
def lib_path
125
- File . join ( recipe . path , "lib" )
181
+ MiniPortile . native_path ( File . join ( recipe . path , "lib" ) )
126
182
end
127
183
end
0 commit comments