tiny_tds 2.1.2 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.devcontainer/Dockerfile +21 -0
- data/.devcontainer/boot.sh +6 -0
- data/.devcontainer/compose.yaml +40 -0
- data/.devcontainer/devcontainer.json +30 -0
- data/.github/workflows/ci.yml +586 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +71 -1
- data/Gemfile +1 -8
- data/ISSUE_TEMPLATE.md +1 -1
- data/README.md +81 -97
- data/Rakefile +48 -29
- data/VERSION +1 -1
- data/astyle.conf +8 -0
- data/ext/tiny_tds/client.c +252 -112
- data/ext/tiny_tds/client.h +5 -3
- data/ext/tiny_tds/extconf.rb +173 -52
- data/ext/tiny_tds/extconsts.rb +4 -11
- data/ext/tiny_tds/result.c +223 -87
- data/ext/tiny_tds/result.h +2 -2
- data/ext/tiny_tds/tiny_tds_ext.c +6 -2
- data/lib/tiny_tds/bin.rb +14 -28
- data/lib/tiny_tds/client.rb +38 -42
- data/lib/tiny_tds/error.rb +0 -2
- data/lib/tiny_tds/gem.rb +7 -16
- data/lib/tiny_tds/result.rb +0 -2
- data/lib/tiny_tds/version.rb +1 -1
- data/lib/tiny_tds.rb +27 -47
- data/tasks/native_gem.rake +12 -10
- data/tasks/package.rake +1 -3
- data/tasks/ports.rake +14 -77
- data/tasks/test.rake +3 -5
- data/test/bin/install-freetds.sh +2 -4
- data/test/bin/restore-from-native-gem.ps1 +16 -0
- data/test/client_test.rb +152 -116
- data/test/gem_test.rb +40 -124
- data/test/result_test.rb +285 -350
- data/test/schema_test.rb +369 -395
- data/test/sql/db-create.sql +18 -0
- data/test/sql/db-login.sql +38 -0
- data/test/test_helper.rb +112 -85
- data/test/thread_test.rb +21 -38
- data/tiny_tds.gemspec +31 -26
- metadata +114 -63
- data/.travis.yml +0 -24
- data/BACKERS.md +0 -32
- data/appveyor.yml +0 -51
- data/tasks/ports/freetds.rb +0 -37
- data/tasks/ports/libiconv.rb +0 -43
- data/tasks/ports/openssl.rb +0 -78
- data/tasks/ports/recipe.rb +0 -52
- data/test/appveyor/dbsetup.ps1 +0 -27
- data/test/appveyor/dbsetup.sql +0 -9
- data/test/benchmark/query.rb +0 -77
- data/test/benchmark/query_odbc.rb +0 -106
- data/test/benchmark/query_tinytds.rb +0 -126
- data/test/bin/install-openssl.sh +0 -18
- data/test/bin/setup.sh +0 -19
- data/test/schema/sqlserver_2000.sql +0 -140
- data/test/schema/sqlserver_2005.sql +0 -140
- data/test/schema/sqlserver_2014.sql +0 -140
- data/test/schema/sqlserver_2016.sql +0 -140
- data/test/schema/sybase_ase.sql +0 -138
- /data/test/schema/{sqlserver_2008.sql → sqlserver_2017.sql} +0 -0
data/test/client_test.rb
CHANGED
|
@@ -1,126 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test_helper'
|
|
1
|
+
require "test_helper"
|
|
3
2
|
|
|
4
3
|
class ClientTest < TinyTds::TestCase
|
|
5
|
-
|
|
6
|
-
describe 'With valid credentials' do
|
|
7
|
-
|
|
4
|
+
describe "with valid credentials" do
|
|
8
5
|
before do
|
|
9
6
|
@client = new_connection
|
|
10
7
|
end
|
|
11
8
|
|
|
12
|
-
it
|
|
9
|
+
it "must not be closed" do
|
|
13
10
|
assert !@client.closed?
|
|
14
11
|
assert @client.active?
|
|
15
12
|
end
|
|
16
13
|
|
|
17
|
-
it
|
|
14
|
+
it "allows client connection to be closed" do
|
|
18
15
|
assert @client.close
|
|
19
16
|
assert @client.closed?
|
|
20
17
|
assert !@client.active?
|
|
21
|
-
|
|
18
|
+
assert @client.dead?
|
|
19
|
+
action = lambda { @client.execute("SELECT 1 as [one]").each }
|
|
22
20
|
assert_raise_tinytds_error(action) do |e|
|
|
23
|
-
assert_match %r{closed connection}i, e.message,
|
|
21
|
+
assert_match %r{closed connection}i, e.message, "ignore if non-english test run"
|
|
24
22
|
end
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
it
|
|
28
|
-
if
|
|
29
|
-
assert_equal 7, @client.tds_version
|
|
30
|
-
assert_equal 'DBTDS_5_0 - 5.0 SQL Server', @client.tds_version_info
|
|
31
|
-
elsif @client.tds_73?
|
|
25
|
+
it "has getters for the tds version information (brittle since conf takes precedence)" do
|
|
26
|
+
if @client.tds_73?
|
|
32
27
|
assert_equal 11, @client.tds_version
|
|
33
|
-
assert_equal
|
|
28
|
+
assert_equal "DBTDS_7_3 - Microsoft SQL Server 2008", @client.tds_version_info
|
|
34
29
|
else
|
|
35
30
|
assert_equal 9, @client.tds_version
|
|
36
|
-
assert_equal
|
|
31
|
+
assert_equal "DBTDS_7_1/DBTDS_8_0 - Microsoft SQL Server 2000", @client.tds_version_info
|
|
37
32
|
end
|
|
38
33
|
end
|
|
39
34
|
|
|
40
|
-
it
|
|
41
|
-
assert_equal
|
|
42
|
-
assert_equal Encoding.find(
|
|
35
|
+
it "uses UTF-8 client charset/encoding by default" do
|
|
36
|
+
assert_equal "UTF-8", @client.charset
|
|
37
|
+
assert_equal Encoding.find("UTF-8"), @client.encoding
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
it
|
|
40
|
+
it "has a #escape method used for quote strings" do
|
|
46
41
|
assert_equal "''hello''", @client.escape("'hello'")
|
|
47
42
|
end
|
|
48
43
|
|
|
49
|
-
[
|
|
44
|
+
["CP850", "CP1252", "ISO-8859-1"].each do |encoding|
|
|
50
45
|
it "allows valid iconv character set - #{encoding}" do
|
|
46
|
+
client = new_connection(encoding: encoding)
|
|
47
|
+
assert_equal encoding, client.charset
|
|
48
|
+
assert_equal Encoding.find(encoding), client.encoding
|
|
49
|
+
ensure
|
|
50
|
+
client&.close
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
unless sqlserver_azure?
|
|
55
|
+
it "must be able to use :host/:port connection" do
|
|
56
|
+
host = ENV["TINYTDS_UNIT_HOST_TEST"] || ENV["TINYTDS_UNIT_HOST"] || "localhost"
|
|
57
|
+
port = ENV["TINYTDS_UNIT_PORT_TEST"] || ENV["TINYTDS_UNIT_PORT"] || 1433
|
|
51
58
|
begin
|
|
52
|
-
client = new_connection
|
|
53
|
-
assert_equal encoding, client.charset
|
|
54
|
-
assert_equal Encoding.find(encoding), client.encoding
|
|
59
|
+
client = new_connection dataserver: nil, host: host, port: port
|
|
55
60
|
ensure
|
|
56
|
-
client
|
|
61
|
+
client&.close
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
end
|
|
60
|
-
|
|
61
|
-
it 'must be able to use :host/:port connection' do
|
|
62
|
-
host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
|
|
63
|
-
port = ENV['TINYTDS_UNIT_PORT_TEST'] || ENV['TINYTDS_UNIT_PORT'] || 1433
|
|
64
|
-
begin
|
|
65
|
-
client = new_connection dataserver: nil, host: host, port: port
|
|
66
|
-
ensure
|
|
67
|
-
client.close if client
|
|
68
|
-
end
|
|
69
|
-
end unless sqlserver_azure?
|
|
70
|
-
|
|
71
65
|
end
|
|
72
66
|
|
|
73
|
-
describe
|
|
67
|
+
describe "With in-valid options" do
|
|
68
|
+
before(:all) do
|
|
69
|
+
init_toxiproxy
|
|
70
|
+
end
|
|
74
71
|
|
|
75
|
-
it
|
|
76
|
-
assert_raises(ArgumentError) { new_connection :
|
|
72
|
+
it "raises an argument error when no :host given and :dataserver is blank" do
|
|
73
|
+
assert_raises(ArgumentError) { new_connection dataserver: nil, host: nil }
|
|
77
74
|
end
|
|
78
75
|
|
|
79
|
-
it
|
|
80
|
-
assert_raises(ArgumentError) { TinyTds::Client.new :
|
|
76
|
+
it "raises an argument error when no :username is supplied" do
|
|
77
|
+
assert_raises(ArgumentError) { TinyTds::Client.new username: nil }
|
|
81
78
|
end
|
|
82
79
|
|
|
83
|
-
it
|
|
84
|
-
options = connection_options :
|
|
80
|
+
it "raises TinyTds exception with undefined :dataserver" do
|
|
81
|
+
options = connection_options login_timeout: 1, dataserver: "DOESNOTEXIST"
|
|
85
82
|
action = lambda { new_connection(options) }
|
|
86
83
|
assert_raise_tinytds_error(action) do |e|
|
|
87
84
|
# Not sure why tese are different.
|
|
88
85
|
if ruby_darwin?
|
|
89
86
|
assert_equal 20009, e.db_error_number
|
|
90
87
|
assert_equal 9, e.severity
|
|
91
|
-
assert_match %r{is unavailable or does not exist}i, e.message,
|
|
88
|
+
assert_match %r{is unavailable or does not exist}i, e.message, "ignore if non-english test run"
|
|
92
89
|
else
|
|
93
90
|
assert_equal 20012, e.db_error_number
|
|
94
91
|
assert_equal 2, e.severity
|
|
95
|
-
assert_match %r{server name not found in configuration files}i, e.message,
|
|
92
|
+
assert_match %r{server name not found in configuration files}i, e.message, "ignore if non-english test run"
|
|
96
93
|
end
|
|
97
94
|
end
|
|
98
95
|
assert_new_connections_work
|
|
99
96
|
end
|
|
100
97
|
|
|
101
|
-
it
|
|
102
|
-
client = new_connection :
|
|
98
|
+
it "raises TinyTds exception with long query past :timeout option" do
|
|
99
|
+
client = new_connection timeout: 1
|
|
103
100
|
action = lambda { client.execute("WaitFor Delay '00:00:02'").do }
|
|
104
101
|
assert_raise_tinytds_error(action) do |e|
|
|
105
102
|
assert_equal 20003, e.db_error_number
|
|
106
103
|
assert_equal 6, e.severity
|
|
107
|
-
assert_match %r{timed out}i, e.message,
|
|
104
|
+
assert_match %r{timed out}i, e.message, "ignore if non-english test run"
|
|
108
105
|
end
|
|
109
106
|
assert_client_works(client)
|
|
110
107
|
close_client(client)
|
|
111
108
|
assert_new_connections_work
|
|
112
109
|
end
|
|
113
110
|
|
|
114
|
-
it
|
|
115
|
-
client = new_connection :
|
|
111
|
+
it "must not timeout per sql batch when not under transaction" do
|
|
112
|
+
client = new_connection timeout: 2
|
|
116
113
|
client.execute("WaitFor Delay '00:00:01'").do
|
|
117
114
|
client.execute("WaitFor Delay '00:00:01'").do
|
|
118
115
|
client.execute("WaitFor Delay '00:00:01'").do
|
|
119
116
|
close_client(client)
|
|
120
117
|
end
|
|
121
118
|
|
|
122
|
-
it
|
|
123
|
-
client = new_connection :
|
|
119
|
+
it "must not timeout per sql batch when under transaction" do
|
|
120
|
+
client = new_connection timeout: 2
|
|
124
121
|
begin
|
|
125
122
|
client.execute("BEGIN TRANSACTION").do
|
|
126
123
|
client.execute("WaitFor Delay '00:00:01'").do
|
|
@@ -132,99 +129,138 @@ class ClientTest < TinyTds::TestCase
|
|
|
132
129
|
end
|
|
133
130
|
end
|
|
134
131
|
|
|
135
|
-
it
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
it "raises TinyTds exception with tcp socket network failure" do
|
|
133
|
+
client = new_connection timeout: 2, port: 1234, host: ENV["TOXIPROXY_HOST"]
|
|
134
|
+
assert_client_works(client)
|
|
135
|
+
action = lambda { client.execute("waitfor delay '00:00:05'").do }
|
|
136
|
+
|
|
137
|
+
# Use toxiproxy to close the TCP socket after 1 second.
|
|
138
|
+
# We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
|
|
139
|
+
# the network connection needs to close after the sql batch is sent and before the timeout above is hit
|
|
140
|
+
Toxiproxy[:sqlserver_test].toxic(:slow_close, delay: 1000).apply do
|
|
144
141
|
assert_raise_tinytds_error(action) do |e|
|
|
145
142
|
assert_equal 20003, e.db_error_number
|
|
146
143
|
assert_equal 6, e.severity
|
|
147
|
-
assert_match %r{timed out}i, e.message,
|
|
144
|
+
assert_match %r{timed out}i, e.message, "ignore if non-english test run"
|
|
148
145
|
end
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
end
|
|
147
|
+
ensure
|
|
148
|
+
assert_new_connections_work
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "raises TinyTds exception with dead connection network failure" do
|
|
152
|
+
skip if ruby_windows?
|
|
153
|
+
|
|
154
|
+
begin
|
|
155
|
+
client = new_connection timeout: 2, port: 1234, host: ENV["TOXIPROXY_HOST"]
|
|
156
|
+
assert_client_works(client)
|
|
157
|
+
action = lambda { client.execute("waitfor delay '00:00:05'").do }
|
|
158
|
+
|
|
159
|
+
# Use toxiproxy to close the network connection after 1 second.
|
|
160
|
+
# We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
|
|
161
|
+
# the network connection needs to close after the sql batch is sent and before the timeout above is hit
|
|
162
|
+
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 1000).apply do
|
|
163
|
+
assert_raise_tinytds_error(action) do |e|
|
|
164
|
+
assert_equal 20047, e.db_error_number
|
|
165
|
+
assert_includes [1, 9], e.severity
|
|
166
|
+
assert_match %r{dead or not enabled}i, e.message, "ignore if non-english test run"
|
|
167
|
+
end
|
|
157
168
|
end
|
|
158
|
-
|
|
169
|
+
ensure
|
|
159
170
|
assert_new_connections_work
|
|
160
171
|
end
|
|
161
172
|
end
|
|
162
173
|
|
|
163
|
-
it
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
it "raises TinyTds exception with login timeout" do
|
|
175
|
+
action = lambda do
|
|
176
|
+
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
|
|
177
|
+
new_connection login_timeout: 1, port: 1234, host: ENV["TOXIPROXY_HOST"]
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
assert_raise_tinytds_error(action) do |e|
|
|
181
|
+
assert_equal 20003, e.db_error_number
|
|
182
|
+
assert_equal 6, e.severity
|
|
183
|
+
assert_match %r{timed out}i, e.message, "ignore if non-english test run"
|
|
184
|
+
end
|
|
185
|
+
ensure
|
|
186
|
+
assert_new_connections_work
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "raises TinyTds exception with wrong :username" do
|
|
190
|
+
skip if ENV["CI"] && sqlserver_azure? # Some issue with db_error_number.
|
|
191
|
+
options = connection_options username: "willnotwork"
|
|
166
192
|
action = lambda { new_connection(options) }
|
|
167
193
|
assert_raise_tinytds_error(action) do |e|
|
|
168
|
-
assert_equal
|
|
194
|
+
assert_equal 18456, e.db_error_number
|
|
169
195
|
assert_equal 14, e.severity
|
|
170
|
-
assert_match %r{login failed}i, e.message,
|
|
196
|
+
assert_match %r{login failed}i, e.message, "ignore if non-english test run"
|
|
171
197
|
end
|
|
172
198
|
assert_new_connections_work
|
|
173
199
|
end
|
|
174
|
-
|
|
175
200
|
end
|
|
176
201
|
|
|
177
|
-
describe
|
|
178
|
-
|
|
202
|
+
describe "#parse_username" do
|
|
179
203
|
let(:client) { @client = new_connection }
|
|
180
204
|
|
|
181
|
-
it
|
|
182
|
-
|
|
183
|
-
|
|
205
|
+
it "returns username if azure is not true" do
|
|
206
|
+
_(
|
|
207
|
+
client.send(:parse_username, username: "user@abc123.database.windows.net")
|
|
208
|
+
).must_equal "user@abc123.database.windows.net"
|
|
184
209
|
end
|
|
185
210
|
|
|
186
|
-
it
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
it "returns short username if azure is true" do
|
|
212
|
+
_(
|
|
213
|
+
client.send(
|
|
214
|
+
:parse_username,
|
|
215
|
+
username: "user@abc123.database.windows.net",
|
|
216
|
+
host: "abc123.database.windows.net",
|
|
217
|
+
azure: true
|
|
218
|
+
)
|
|
219
|
+
).must_equal "user@abc123"
|
|
192
220
|
end
|
|
193
221
|
|
|
194
|
-
it
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
222
|
+
it "returns full username if azure is false" do
|
|
223
|
+
_(
|
|
224
|
+
client.send(
|
|
225
|
+
:parse_username,
|
|
226
|
+
username: "user@abc123.database.windows.net",
|
|
227
|
+
host: "abc123.database.windows.net",
|
|
228
|
+
azure: false
|
|
229
|
+
)
|
|
230
|
+
).must_equal "user@abc123.database.windows.net"
|
|
200
231
|
end
|
|
201
232
|
|
|
202
|
-
it
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
233
|
+
it "returns short username if passed and azure is true" do
|
|
234
|
+
_(
|
|
235
|
+
client.send(
|
|
236
|
+
:parse_username,
|
|
237
|
+
username: "user@abc123",
|
|
238
|
+
host: "abc123.database.windows.net",
|
|
239
|
+
azure: true
|
|
240
|
+
)
|
|
241
|
+
).must_equal "user@abc123"
|
|
208
242
|
end
|
|
209
243
|
|
|
210
|
-
it
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
244
|
+
it "returns username with servername if passed and azure is true" do
|
|
245
|
+
_(
|
|
246
|
+
client.send(
|
|
247
|
+
:parse_username,
|
|
248
|
+
username: "user",
|
|
249
|
+
host: "abc123.database.windows.net",
|
|
250
|
+
azure: true
|
|
251
|
+
)
|
|
252
|
+
).must_equal "user@abc123"
|
|
216
253
|
end
|
|
217
254
|
|
|
218
|
-
it
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
255
|
+
it "returns username with servername if passed and azure is false" do
|
|
256
|
+
_(
|
|
257
|
+
client.send(
|
|
258
|
+
:parse_username,
|
|
259
|
+
username: "user",
|
|
260
|
+
host: "abc123.database.windows.net",
|
|
261
|
+
azure: false
|
|
262
|
+
)
|
|
263
|
+
).must_equal "user"
|
|
224
264
|
end
|
|
225
|
-
|
|
226
265
|
end
|
|
227
|
-
|
|
228
|
-
|
|
229
266
|
end
|
|
230
|
-
|
data/test/gem_test.rb
CHANGED
|
@@ -1,179 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
require
|
|
3
|
-
require 'tiny_tds/gem'
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "tiny_tds/gem"
|
|
4
3
|
|
|
5
|
-
class GemTest <
|
|
6
|
-
gem_root ||= File.expand_path
|
|
4
|
+
class GemTest < Minitest::Spec
|
|
5
|
+
gem_root ||= File.expand_path "../..", __FILE__
|
|
7
6
|
|
|
8
7
|
describe TinyTds::Gem do
|
|
9
|
-
|
|
10
8
|
# We're going to muck with some system globals so lets make sure
|
|
11
9
|
# they get set back later
|
|
12
|
-
original_host = RbConfig::CONFIG['host']
|
|
13
10
|
original_pwd = Dir.pwd
|
|
14
11
|
|
|
15
12
|
after do
|
|
16
|
-
RbConfig::CONFIG['host'] = original_host
|
|
17
13
|
Dir.chdir original_pwd
|
|
18
14
|
end
|
|
19
15
|
|
|
20
|
-
describe
|
|
16
|
+
describe "#root_path" do
|
|
21
17
|
let(:root_path) { TinyTds::Gem.root_path }
|
|
22
18
|
|
|
23
|
-
it
|
|
24
|
-
root_path.must_equal gem_root
|
|
19
|
+
it "should be the root path" do
|
|
20
|
+
_(root_path).must_equal gem_root
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
it
|
|
28
|
-
Dir.chdir
|
|
23
|
+
it "should be the root path no matter the cwd" do
|
|
24
|
+
Dir.chdir "/"
|
|
29
25
|
|
|
30
|
-
root_path.must_equal gem_root
|
|
26
|
+
_(root_path).must_equal gem_root
|
|
31
27
|
end
|
|
32
28
|
end
|
|
33
29
|
|
|
34
|
-
describe
|
|
30
|
+
describe "#ports_root_path" do
|
|
35
31
|
let(:ports_root_path) { TinyTds::Gem.ports_root_path }
|
|
36
32
|
|
|
37
|
-
it
|
|
38
|
-
ports_root_path.must_equal File.join(gem_root,
|
|
33
|
+
it "should be the ports path" do
|
|
34
|
+
_(ports_root_path).must_equal File.join(gem_root, "ports")
|
|
39
35
|
end
|
|
40
36
|
|
|
41
|
-
it
|
|
42
|
-
Dir.chdir
|
|
37
|
+
it "should be the ports path no matter the cwd" do
|
|
38
|
+
Dir.chdir "/"
|
|
43
39
|
|
|
44
|
-
ports_root_path.must_equal File.join(gem_root,
|
|
40
|
+
_(ports_root_path).must_equal File.join(gem_root, "ports")
|
|
45
41
|
end
|
|
46
42
|
end
|
|
47
43
|
|
|
48
|
-
describe
|
|
49
|
-
let(:
|
|
50
|
-
|
|
51
|
-
describe
|
|
52
|
-
let(:
|
|
53
|
-
ports_host_root = File.join(gem_root,
|
|
54
|
-
[
|
|
55
|
-
File.join('a','bin'),
|
|
56
|
-
File.join('a','inner','bin'),
|
|
57
|
-
File.join('b','bin')
|
|
58
|
-
].map do |p|
|
|
44
|
+
describe "#ports_bin_and_lib_paths" do
|
|
45
|
+
let(:ports_bin_and_lib_paths) { TinyTds::Gem.ports_bin_and_lib_paths }
|
|
46
|
+
|
|
47
|
+
describe "when the ports directories exist" do
|
|
48
|
+
let(:fake_bin_and_lib_path) do
|
|
49
|
+
ports_host_root = File.join(gem_root, "ports", "x86_64-unknown")
|
|
50
|
+
["bin", "lib"].map do |p|
|
|
59
51
|
File.join(ports_host_root, p)
|
|
60
52
|
end
|
|
61
53
|
end
|
|
62
54
|
|
|
63
55
|
before do
|
|
64
|
-
|
|
65
|
-
fake_bin_paths.each do |path|
|
|
56
|
+
fake_bin_and_lib_path.each do |path|
|
|
66
57
|
FileUtils.mkdir_p(path)
|
|
67
58
|
end
|
|
68
59
|
end
|
|
69
60
|
|
|
70
61
|
after do
|
|
71
62
|
FileUtils.remove_entry_secure(
|
|
72
|
-
File.join(gem_root,
|
|
63
|
+
File.join(gem_root, "ports", "x86_64-unknown"), true
|
|
73
64
|
)
|
|
74
65
|
end
|
|
75
66
|
|
|
76
|
-
it
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'should return all the bin directories regardless of cwd' do
|
|
81
|
-
Dir.chdir '/'
|
|
82
|
-
ports_bin_paths.sort.must_equal fake_bin_paths.sort
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe 'when the ports directories are missing' do
|
|
87
|
-
before do
|
|
88
|
-
RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'should return no directories' do
|
|
92
|
-
ports_bin_paths.must_be_empty
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it 'should return no directories regardless of cwd' do
|
|
96
|
-
Dir.chdir '/'
|
|
97
|
-
ports_bin_paths.must_be_empty
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
67
|
+
it "should return all the bin directories" do
|
|
68
|
+
fake_platform = Gem::Platform.new("x86_64-unknown")
|
|
101
69
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
describe 'when the ports directories exist' do
|
|
106
|
-
let(:fake_lib_paths) do
|
|
107
|
-
ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs')
|
|
108
|
-
[
|
|
109
|
-
File.join('a','lib'),
|
|
110
|
-
File.join('a','inner','lib'),
|
|
111
|
-
File.join('b','lib')
|
|
112
|
-
].map do |p|
|
|
113
|
-
File.join(ports_host_root, p)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
70
|
+
Gem::Platform.stub(:local, fake_platform) do
|
|
71
|
+
_(ports_bin_and_lib_paths.sort).must_equal fake_bin_and_lib_path.sort
|
|
116
72
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
FileUtils.mkdir_p(path)
|
|
73
|
+
# should return the same regardless of path
|
|
74
|
+
Dir.chdir "/"
|
|
75
|
+
_(ports_bin_and_lib_paths.sort).must_equal fake_bin_and_lib_path.sort
|
|
121
76
|
end
|
|
122
77
|
end
|
|
123
|
-
|
|
124
|
-
after do
|
|
125
|
-
FileUtils.remove_entry_secure(
|
|
126
|
-
File.join(gem_root, 'ports', 'fake-host-with-dirs'), true
|
|
127
|
-
)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it 'should return all the lib directories' do
|
|
131
|
-
ports_lib_paths.sort.must_equal fake_lib_paths.sort
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it 'should return all the lib directories regardless of cwd' do
|
|
135
|
-
Dir.chdir '/'
|
|
136
|
-
ports_lib_paths.sort.must_equal fake_lib_paths.sort
|
|
137
|
-
end
|
|
138
78
|
end
|
|
139
79
|
|
|
140
|
-
describe
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
it 'should return no directories' do
|
|
147
|
-
ports_lib_paths.must_be_empty
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it 'should return no directories regardless of cwd' do
|
|
151
|
-
Dir.chdir '/'
|
|
152
|
-
ports_lib_paths.must_be_empty
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
80
|
+
describe "when the ports directories are missing" do
|
|
81
|
+
it "should return no directories" do
|
|
82
|
+
fake_platform = Gem::Platform.new("x86_64-unknown")
|
|
156
83
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
'i686-pc-linux-gnu' => 'i686-pc-linux-gnu',
|
|
160
|
-
'x86_64-pc-linux-gnu' => 'x86_64-pc-linux-gnu',
|
|
161
|
-
'i686-w64-mingw32' => 'i686-w64-mingw32',
|
|
162
|
-
'x86_64-w64-mingw32' => 'x86_64-w64-mingw32',
|
|
163
|
-
# consolidate this host to our build w64-mingw32 arch
|
|
164
|
-
'i686-pc-mingw32' => 'i686-w64-mingw32'
|
|
165
|
-
}.each do |host,expected|
|
|
166
|
-
describe "on a #{host} architecture" do
|
|
167
|
-
before do
|
|
168
|
-
RbConfig::CONFIG['host'] = host
|
|
169
|
-
end
|
|
84
|
+
Gem::Platform.stub(:local, fake_platform) do
|
|
85
|
+
_(ports_bin_and_lib_paths).must_be_empty
|
|
170
86
|
|
|
171
|
-
|
|
172
|
-
|
|
87
|
+
# should be empty regardless of path
|
|
88
|
+
Dir.chdir "/"
|
|
89
|
+
_(ports_bin_and_lib_paths).must_be_empty
|
|
173
90
|
end
|
|
174
91
|
end
|
|
175
92
|
end
|
|
176
93
|
end
|
|
177
94
|
end
|
|
178
95
|
end
|
|
179
|
-
|