tiny_tds 2.1.5 → 3.2.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 +4 -4
- data/.github/workflows/ci.yml +590 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +32 -1
- data/Gemfile +1 -8
- data/ISSUE_TEMPLATE.md +1 -1
- data/README.md +75 -88
- data/Rakefile +44 -30
- data/VERSION +1 -1
- data/docker-compose.yml +20 -8
- data/ext/tiny_tds/client.c +10 -15
- data/ext/tiny_tds/extconf.rb +183 -66
- data/ext/tiny_tds/extconsts.rb +4 -11
- data/ext/tiny_tds/result.c +28 -35
- data/ext/tiny_tds/tiny_tds_ext.c +4 -1
- data/lib/tiny_tds/bin.rb +12 -26
- data/lib/tiny_tds/client.rb +38 -42
- data/lib/tiny_tds/error.rb +0 -2
- data/lib/tiny_tds/gem.rb +5 -14
- data/lib/tiny_tds/result.rb +0 -2
- data/lib/tiny_tds/version.rb +1 -1
- data/lib/tiny_tds.rb +28 -47
- data/setup_cimgruby_dev.sh +25 -0
- data/start_dev.sh +21 -0
- data/tasks/native_gem.rake +12 -10
- data/tasks/package.rake +1 -3
- data/tasks/ports.rake +14 -75
- data/tasks/test.rake +3 -5
- data/test/bin/install-freetds.sh +2 -4
- data/test/bin/install-mssql.ps1 +42 -0
- data/test/bin/install-mssqltools.sh +9 -0
- data/test/bin/restore-from-native-gem.ps1 +10 -0
- data/test/bin/setup_tinytds_db.sh +7 -0
- data/test/bin/setup_volume_permissions.sh +10 -0
- data/test/client_test.rb +111 -120
- data/test/gem_test.rb +32 -111
- data/test/result_test.rb +259 -365
- 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 +75 -102
- data/test/thread_test.rb +22 -31
- data/tiny_tds.gemspec +28 -27
- metadata +70 -57
- data/.travis.yml +0 -25
- data/appveyor.yml +0 -72
- data/tasks/ports/freetds.rb +0 -37
- data/tasks/ports/libiconv.rb +0 -43
- data/tasks/ports/openssl.rb +0 -62
- 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/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
|
-
describe
|
4
|
+
describe "with valid credentials" do
|
6
5
|
before do
|
7
6
|
@client = new_connection
|
8
7
|
end
|
9
8
|
|
10
|
-
it
|
9
|
+
it "must not be closed" do
|
11
10
|
assert !@client.closed?
|
12
11
|
assert @client.active?
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
14
|
+
it "allows client connection to be closed" do
|
16
15
|
assert @client.close
|
17
16
|
assert @client.closed?
|
18
17
|
assert !@client.active?
|
19
|
-
|
18
|
+
assert @client.dead?
|
19
|
+
action = lambda { @client.execute("SELECT 1 as [one]").each }
|
20
20
|
assert_raise_tinytds_error(action) do |e|
|
21
|
-
assert_match %r{closed connection}i, e.message,
|
21
|
+
assert_match %r{closed connection}i, e.message, "ignore if non-english test run"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
if
|
27
|
-
assert_equal 7, @client.tds_version
|
28
|
-
assert_equal 'DBTDS_5_0 - 5.0 SQL Server', @client.tds_version_info
|
29
|
-
elsif @client.tds_73?
|
25
|
+
it "has getters for the tds version information (brittle since conf takes precedence)" do
|
26
|
+
if @client.tds_73?
|
30
27
|
assert_equal 11, @client.tds_version
|
31
|
-
assert_equal
|
28
|
+
assert_equal "DBTDS_7_3 - Microsoft SQL Server 2008", @client.tds_version_info
|
32
29
|
else
|
33
30
|
assert_equal 9, @client.tds_version
|
34
|
-
assert_equal
|
31
|
+
assert_equal "DBTDS_7_1/DBTDS_8_0 - Microsoft SQL Server 2000", @client.tds_version_info
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
it
|
39
|
-
assert_equal
|
40
|
-
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
|
41
38
|
end
|
42
39
|
|
43
|
-
it
|
40
|
+
it "has a #escape method used for quote strings" do
|
44
41
|
assert_equal "''hello''", @client.escape("'hello'")
|
45
42
|
end
|
46
43
|
|
47
|
-
[
|
44
|
+
["CP850", "CP1252", "ISO-8859-1"].each do |encoding|
|
48
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
|
49
58
|
begin
|
50
|
-
client = new_connection
|
51
|
-
assert_equal encoding, client.charset
|
52
|
-
assert_equal Encoding.find(encoding), client.encoding
|
59
|
+
client = new_connection dataserver: nil, host: host, port: port
|
53
60
|
ensure
|
54
|
-
client
|
61
|
+
client&.close
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
58
|
-
|
59
|
-
it 'must be able to use :host/:port connection' do
|
60
|
-
host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
|
61
|
-
port = ENV['TINYTDS_UNIT_PORT_TEST'] || ENV['TINYTDS_UNIT_PORT'] || 1433
|
62
|
-
begin
|
63
|
-
client = new_connection dataserver: nil, host: host, port: port
|
64
|
-
ensure
|
65
|
-
client.close if client
|
66
|
-
end
|
67
|
-
end unless sqlserver_azure?
|
68
65
|
end
|
69
66
|
|
70
|
-
describe
|
67
|
+
describe "With in-valid options" do
|
71
68
|
before(:all) do
|
72
69
|
init_toxiproxy
|
73
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,32 +129,30 @@ class ClientTest < TinyTds::TestCase
|
|
132
129
|
end
|
133
130
|
end
|
134
131
|
|
135
|
-
it
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
assert_client_works(client)
|
140
|
-
action = lambda { client.execute("waitfor delay '00:00:05'").do }
|
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 }
|
141
136
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
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
|
141
|
+
assert_raise_tinytds_error(action) do |e|
|
142
|
+
assert_equal 20003, e.db_error_number
|
143
|
+
assert_equal 6, e.severity
|
144
|
+
assert_match %r{timed out}i, e.message, "ignore if non-english test run"
|
151
145
|
end
|
152
|
-
ensure
|
153
|
-
assert_new_connections_work
|
154
146
|
end
|
147
|
+
ensure
|
148
|
+
assert_new_connections_work
|
155
149
|
end
|
156
150
|
|
157
|
-
it
|
158
|
-
skip if
|
151
|
+
it "raises TinyTds exception with dead connection network failure" do
|
152
|
+
skip if ruby_windows?
|
153
|
+
|
159
154
|
begin
|
160
|
-
client = new_connection timeout: 2, port: 1234
|
155
|
+
client = new_connection timeout: 2, port: 1234, host: ENV["TOXIPROXY_HOST"]
|
161
156
|
assert_client_works(client)
|
162
157
|
action = lambda { client.execute("waitfor delay '00:00:05'").do }
|
163
158
|
|
@@ -167,8 +162,8 @@ class ClientTest < TinyTds::TestCase
|
|
167
162
|
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 1000).apply do
|
168
163
|
assert_raise_tinytds_error(action) do |e|
|
169
164
|
assert_equal 20047, e.db_error_number
|
170
|
-
assert_includes [1,9], e.severity
|
171
|
-
assert_match %r{dead or not enabled}i, e.message,
|
165
|
+
assert_includes [1, 9], e.severity
|
166
|
+
assert_match %r{dead or not enabled}i, e.message, "ignore if non-english test run"
|
172
167
|
end
|
173
168
|
end
|
174
169
|
ensure
|
@@ -176,100 +171,96 @@ class ClientTest < TinyTds::TestCase
|
|
176
171
|
end
|
177
172
|
end
|
178
173
|
|
179
|
-
it
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
|
184
|
-
new_connection login_timeout: 1, port: 1234
|
185
|
-
end
|
186
|
-
end
|
187
|
-
assert_raise_tinytds_error(action) do |e|
|
188
|
-
assert_equal 20003, e.db_error_number
|
189
|
-
assert_equal 6, e.severity
|
190
|
-
assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
|
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"]
|
191
178
|
end
|
192
|
-
ensure
|
193
|
-
assert_new_connections_work
|
194
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
|
195
187
|
end
|
196
188
|
|
197
|
-
it
|
198
|
-
skip if ENV[
|
199
|
-
options = connection_options :
|
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"
|
200
192
|
action = lambda { new_connection(options) }
|
201
193
|
assert_raise_tinytds_error(action) do |e|
|
202
|
-
assert_equal
|
194
|
+
assert_equal 18456, e.db_error_number
|
203
195
|
assert_equal 14, e.severity
|
204
|
-
assert_match %r{login failed}i, e.message,
|
196
|
+
assert_match %r{login failed}i, e.message, "ignore if non-english test run"
|
205
197
|
end
|
206
198
|
assert_new_connections_work
|
207
199
|
end
|
208
|
-
|
209
200
|
end
|
210
201
|
|
211
|
-
describe
|
202
|
+
describe "#parse_username" do
|
212
203
|
let(:client) { @client = new_connection }
|
213
204
|
|
214
|
-
it
|
205
|
+
it "returns username if azure is not true" do
|
215
206
|
_(
|
216
|
-
client.send(:parse_username, username:
|
217
|
-
).must_equal
|
207
|
+
client.send(:parse_username, username: "user@abc123.database.windows.net")
|
208
|
+
).must_equal "user@abc123.database.windows.net"
|
218
209
|
end
|
219
210
|
|
220
|
-
it
|
211
|
+
it "returns short username if azure is true" do
|
221
212
|
_(
|
222
213
|
client.send(
|
223
214
|
:parse_username,
|
224
|
-
username:
|
225
|
-
host:
|
226
|
-
azure:
|
215
|
+
username: "user@abc123.database.windows.net",
|
216
|
+
host: "abc123.database.windows.net",
|
217
|
+
azure: true
|
227
218
|
)
|
228
|
-
).must_equal
|
219
|
+
).must_equal "user@abc123"
|
229
220
|
end
|
230
221
|
|
231
|
-
it
|
222
|
+
it "returns full username if azure is false" do
|
232
223
|
_(
|
233
224
|
client.send(
|
234
225
|
:parse_username,
|
235
|
-
username:
|
236
|
-
host:
|
237
|
-
azure:
|
226
|
+
username: "user@abc123.database.windows.net",
|
227
|
+
host: "abc123.database.windows.net",
|
228
|
+
azure: false
|
238
229
|
)
|
239
|
-
).must_equal
|
230
|
+
).must_equal "user@abc123.database.windows.net"
|
240
231
|
end
|
241
232
|
|
242
|
-
it
|
233
|
+
it "returns short username if passed and azure is true" do
|
243
234
|
_(
|
244
235
|
client.send(
|
245
236
|
:parse_username,
|
246
|
-
username:
|
247
|
-
host:
|
248
|
-
azure:
|
237
|
+
username: "user@abc123",
|
238
|
+
host: "abc123.database.windows.net",
|
239
|
+
azure: true
|
249
240
|
)
|
250
|
-
).must_equal
|
241
|
+
).must_equal "user@abc123"
|
251
242
|
end
|
252
243
|
|
253
|
-
it
|
244
|
+
it "returns username with servername if passed and azure is true" do
|
254
245
|
_(
|
255
246
|
client.send(
|
256
247
|
:parse_username,
|
257
|
-
username:
|
258
|
-
host:
|
259
|
-
azure:
|
248
|
+
username: "user",
|
249
|
+
host: "abc123.database.windows.net",
|
250
|
+
azure: true
|
260
251
|
)
|
261
|
-
).must_equal
|
252
|
+
).must_equal "user@abc123"
|
262
253
|
end
|
263
254
|
|
264
|
-
it
|
255
|
+
it "returns username with servername if passed and azure is false" do
|
265
256
|
_(
|
266
257
|
client.send(
|
267
258
|
:parse_username,
|
268
|
-
username:
|
269
|
-
host:
|
270
|
-
azure:
|
259
|
+
username: "user",
|
260
|
+
host: "abc123.database.windows.net",
|
261
|
+
azure: false
|
271
262
|
)
|
272
|
-
).must_equal
|
263
|
+
).must_equal "user"
|
273
264
|
end
|
274
265
|
end
|
275
266
|
end
|
data/test/gem_test.rb
CHANGED
@@ -1,67 +1,65 @@
|
|
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
|
-
|
10
|
+
original_platform = RbConfig::CONFIG["arch"]
|
13
11
|
original_pwd = Dir.pwd
|
14
12
|
|
15
13
|
after do
|
16
|
-
RbConfig::CONFIG[
|
14
|
+
RbConfig::CONFIG["arch"] = original_platform
|
17
15
|
Dir.chdir original_pwd
|
18
16
|
end
|
19
17
|
|
20
|
-
describe
|
18
|
+
describe "#root_path" do
|
21
19
|
let(:root_path) { TinyTds::Gem.root_path }
|
22
20
|
|
23
|
-
it
|
21
|
+
it "should be the root path" do
|
24
22
|
_(root_path).must_equal gem_root
|
25
23
|
end
|
26
24
|
|
27
|
-
it
|
28
|
-
Dir.chdir
|
25
|
+
it "should be the root path no matter the cwd" do
|
26
|
+
Dir.chdir "/"
|
29
27
|
|
30
28
|
_(root_path).must_equal gem_root
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
describe
|
32
|
+
describe "#ports_root_path" do
|
35
33
|
let(:ports_root_path) { TinyTds::Gem.ports_root_path }
|
36
34
|
|
37
|
-
it
|
38
|
-
_(ports_root_path).must_equal File.join(gem_root,
|
35
|
+
it "should be the ports path" do
|
36
|
+
_(ports_root_path).must_equal File.join(gem_root, "ports")
|
39
37
|
end
|
40
38
|
|
41
|
-
it
|
42
|
-
Dir.chdir
|
39
|
+
it "should be the ports path no matter the cwd" do
|
40
|
+
Dir.chdir "/"
|
43
41
|
|
44
|
-
_(ports_root_path).must_equal File.join(gem_root,
|
42
|
+
_(ports_root_path).must_equal File.join(gem_root, "ports")
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
describe
|
46
|
+
describe "#ports_bin_paths" do
|
49
47
|
let(:ports_bin_paths) { TinyTds::Gem.ports_bin_paths }
|
50
48
|
|
51
|
-
describe
|
49
|
+
describe "when the ports directories exist" do
|
52
50
|
let(:fake_bin_paths) do
|
53
|
-
ports_host_root = File.join(gem_root,
|
51
|
+
ports_host_root = File.join(gem_root, "ports", "fake-host-with-dirs")
|
54
52
|
[
|
55
|
-
File.join(
|
56
|
-
File.join(
|
57
|
-
File.join(
|
53
|
+
File.join("a", "bin"),
|
54
|
+
File.join("a", "inner", "bin"),
|
55
|
+
File.join("b", "bin")
|
58
56
|
].map do |p|
|
59
57
|
File.join(ports_host_root, p)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
61
|
before do
|
64
|
-
RbConfig::CONFIG[
|
62
|
+
RbConfig::CONFIG["arch"] = "fake-host-with-dirs"
|
65
63
|
fake_bin_paths.each do |path|
|
66
64
|
FileUtils.mkdir_p(path)
|
67
65
|
end
|
@@ -69,111 +67,34 @@ class GemTest < MiniTest::Spec
|
|
69
67
|
|
70
68
|
after do
|
71
69
|
FileUtils.remove_entry_secure(
|
72
|
-
File.join(gem_root,
|
70
|
+
File.join(gem_root, "ports", "fake-host-with-dirs"), true
|
73
71
|
)
|
74
72
|
end
|
75
73
|
|
76
|
-
it
|
74
|
+
it "should return all the bin directories" do
|
77
75
|
_(ports_bin_paths.sort).must_equal fake_bin_paths.sort
|
78
76
|
end
|
79
77
|
|
80
|
-
it
|
81
|
-
Dir.chdir
|
78
|
+
it "should return all the bin directories regardless of cwd" do
|
79
|
+
Dir.chdir "/"
|
82
80
|
_(ports_bin_paths.sort).must_equal fake_bin_paths.sort
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
86
|
-
describe
|
84
|
+
describe "when the ports directories are missing" do
|
87
85
|
before do
|
88
|
-
RbConfig::CONFIG[
|
86
|
+
RbConfig::CONFIG["arch"] = "fake-host-without-dirs"
|
89
87
|
end
|
90
88
|
|
91
|
-
it
|
89
|
+
it "should return no directories" do
|
92
90
|
_(ports_bin_paths).must_be_empty
|
93
91
|
end
|
94
92
|
|
95
|
-
it
|
96
|
-
Dir.chdir
|
93
|
+
it "should return no directories regardless of cwd" do
|
94
|
+
Dir.chdir "/"
|
97
95
|
_(ports_bin_paths).must_be_empty
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|
101
|
-
|
102
|
-
describe '#ports_lib_paths' do
|
103
|
-
let(:ports_lib_paths) { TinyTds::Gem.ports_lib_paths }
|
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
|
116
|
-
|
117
|
-
before do
|
118
|
-
RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
|
119
|
-
fake_lib_paths.each do |path|
|
120
|
-
FileUtils.mkdir_p(path)
|
121
|
-
end
|
122
|
-
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
|
-
end
|
139
|
-
|
140
|
-
describe 'when the ports directories are missing' do
|
141
|
-
before do
|
142
|
-
RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
|
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
|
156
|
-
|
157
|
-
describe '#ports_host' do
|
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
|
170
|
-
|
171
|
-
it "should return a #{expected} ports host" do
|
172
|
-
_(TinyTds::Gem.ports_host).must_equal expected
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
99
|
end
|
178
100
|
end
|
179
|
-
|