cliver 0.2.1 → 0.2.2
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.
- data/lib/cliver/dependency.rb +1 -1
- data/lib/cliver/version.rb +1 -1
- data/lib/core_ext/file.rb +18 -1
- data/spec/cliver_spec.rb +28 -0
- data/spec/core_ext/file_spec.rb +82 -0
- metadata +4 -2
data/lib/cliver/dependency.rb
CHANGED
@@ -203,7 +203,7 @@ module Cliver
|
|
203
203
|
|
204
204
|
detected_exes = []
|
205
205
|
cmds.product(paths, exts).map do |cmd, path, ext|
|
206
|
-
exe = File.expand_path("#{cmd}#{ext}", path)
|
206
|
+
exe = File.absolute_path?(cmd) ? cmd : File.expand_path("#{cmd}#{ext}", path)
|
207
207
|
|
208
208
|
next unless File.executable?(exe)
|
209
209
|
next if detected_exes.include?(exe) # don't yield the same exe path 2x
|
data/lib/cliver/version.rb
CHANGED
data/lib/core_ext/file.rb
CHANGED
@@ -12,6 +12,23 @@ class File
|
|
12
12
|
# @param [String] - a pathname
|
13
13
|
# @return [Boolean]
|
14
14
|
def self.absolute_path?(path)
|
15
|
-
false |
|
15
|
+
false | path[ABSOLUTE_PATH_PATTERN]
|
16
16
|
end
|
17
|
+
|
18
|
+
unless defined?(POSIX_ABSOLUTE_PATH_PATTERN)
|
19
|
+
POSIX_ABSOLUTE_PATH_PATTERN = /\A\//.freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
unless defined?(WINDOWS_ABSOLUTE_PATH_PATTERN)
|
23
|
+
WINDOWS_ABSOLUTE_PATH_PATTERN = Regexp.union(
|
24
|
+
POSIX_ABSOLUTE_PATH_PATTERN,
|
25
|
+
/\A([A-Z]:)?(\\|\/)/i
|
26
|
+
).freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
ABSOLUTE_PATH_PATTERN = begin
|
30
|
+
File::ALT_SEPARATOR ?
|
31
|
+
WINDOWS_ABSOLUTE_PATH_PATTERN :
|
32
|
+
POSIX_ABSOLUTE_PATH_PATTERN
|
33
|
+
end unless defined?(ABSOLUTE_PATH_PATTERN)
|
17
34
|
end
|
data/spec/cliver_spec.rb
CHANGED
@@ -90,6 +90,34 @@ describe Cliver do
|
|
90
90
|
expect { action }.to raise_exception Cliver::Dependency::NotFound
|
91
91
|
end
|
92
92
|
end
|
93
|
+
context '(windows path)' do
|
94
|
+
before(:each) do
|
95
|
+
stub_const('File::ABSOLUTE_PATH_PATTERN', File::WINDOWS_ABSOLUTE_PATH_PATTERN)
|
96
|
+
end
|
97
|
+
let(:version_map) do
|
98
|
+
{'C:/baz/bingo/doodle.exe' => '0.2.1',
|
99
|
+
'C:/baz/fiddle/doodle.exe' => '1.1.4'}
|
100
|
+
end
|
101
|
+
context 'and executable at that path is sufficient' do
|
102
|
+
let(:executable) { 'C:/baz/fiddle/doodle.exe' }
|
103
|
+
it 'should not raise' do
|
104
|
+
expect { action }.to_not raise_exception
|
105
|
+
end
|
106
|
+
end
|
107
|
+
context 'and the executable at that path is not sufficent' do
|
108
|
+
let(:executable) { 'C:/baz/bingo/doodle.exe' }
|
109
|
+
it 'should raise' do
|
110
|
+
expect { action }.to raise_exception Cliver::Dependency::VersionMismatch
|
111
|
+
end
|
112
|
+
end
|
113
|
+
context 'and no executable exists at that path' do
|
114
|
+
let(:version_map) { Hash.new }
|
115
|
+
let(:executable) { 'C:/baz/fiddle/doodle.exe' }
|
116
|
+
it 'should raise' do
|
117
|
+
expect { action }.to raise_exception Cliver::Dependency::NotFound
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
93
121
|
context 'and the executable at that path is sufficent' do
|
94
122
|
let(:executable) { '/baz/fiddle/doodle' }
|
95
123
|
it 'should not raise' do
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'core_ext/file'
|
3
|
+
|
4
|
+
describe 'File::absolute_path?' do
|
5
|
+
context 'posix' do
|
6
|
+
before(:each) do
|
7
|
+
stub_const("File::ALT_SEPARATOR", nil)
|
8
|
+
stub_const("File::ABSOLUTE_PATH_PATTERN", File::POSIX_ABSOLUTE_PATH_PATTERN)
|
9
|
+
end
|
10
|
+
context 'when given an absolute path' do
|
11
|
+
%w(
|
12
|
+
/foo/bar
|
13
|
+
/C/Windows/system32/
|
14
|
+
).each do |path|
|
15
|
+
context "(#{path})" do
|
16
|
+
context 'the return value' do
|
17
|
+
subject { File::absolute_path?(path) }
|
18
|
+
it { should be_true }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context 'when given a relative path' do
|
24
|
+
%w(
|
25
|
+
C:/foo/bar
|
26
|
+
\\foo\\bar
|
27
|
+
C:\\foo\\bar
|
28
|
+
foo/bar
|
29
|
+
foo
|
30
|
+
./foo/bar
|
31
|
+
../foo/bar
|
32
|
+
C:foo/bar
|
33
|
+
).each do |path|
|
34
|
+
context "(#{path})" do
|
35
|
+
context 'the return value' do
|
36
|
+
subject { File::absolute_path?(path) }
|
37
|
+
it { should be_false }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'windows' do
|
45
|
+
before(:each) do
|
46
|
+
stub_const("File::ALT_SEPARATOR", '\\')
|
47
|
+
stub_const("File::ABSOLUTE_PATH_PATTERN", File::WINDOWS_ABSOLUTE_PATH_PATTERN)
|
48
|
+
end
|
49
|
+
context 'when given an absolute path' do
|
50
|
+
%w(
|
51
|
+
/foo/bar
|
52
|
+
C:/foo/bar
|
53
|
+
\\foo\\bar
|
54
|
+
C:\\foo\\bar
|
55
|
+
/C/Windows/system32/
|
56
|
+
).each do |path|
|
57
|
+
context "(#{path})" do
|
58
|
+
context 'the return value' do
|
59
|
+
subject { File::absolute_path?(path) }
|
60
|
+
it { should be_true }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
context 'when given a relative path' do
|
66
|
+
%w(
|
67
|
+
foo/bar
|
68
|
+
foo
|
69
|
+
./foo/bar
|
70
|
+
../foo/bar
|
71
|
+
C:foo/bar
|
72
|
+
).each do |path|
|
73
|
+
context "(#{path})" do
|
74
|
+
context 'the return value' do
|
75
|
+
subject { File::absolute_path?(path) }
|
76
|
+
it { should be_false }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/core_ext/file.rb
|
132
132
|
- spec/cliver/detector_spec.rb
|
133
133
|
- spec/cliver_spec.rb
|
134
|
+
- spec/core_ext/file_spec.rb
|
134
135
|
- spec/spec_helper.rb
|
135
136
|
homepage: https://www.github.com/yaauie/cliver
|
136
137
|
licenses:
|
@@ -160,5 +161,6 @@ summary: Cross-platform version constraints for cli tools
|
|
160
161
|
test_files:
|
161
162
|
- spec/cliver/detector_spec.rb
|
162
163
|
- spec/cliver_spec.rb
|
164
|
+
- spec/core_ext/file_spec.rb
|
163
165
|
- spec/spec_helper.rb
|
164
166
|
has_rdoc: yard
|