mario 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/README.rdoc +5 -7
- data/VERSION +1 -0
- data/lib/mario.rb +1 -1
- data/lib/mario/hats/nix.rb +18 -0
- data/lib/mario/hats/windows.rb +13 -0
- data/lib/mario/platform.rb +154 -30
- data/mario.gemspec +64 -0
- data/test/mario/hats/test_nix.rb +15 -0
- data/test/mario/hats/test_windows.rb +18 -0
- data/test/mario/test_plaform.rb +70 -20
- metadata +9 -4
- data/lib/mario/toolbelt.rb +0 -24
- data/test/mario/test_toolbelt.rb +0 -25
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
= mario
|
2
2
|
|
3
|
-
|
3
|
+
Mario provides some very simple tools for figuring out which platform you're on and, depending on your needs, some for helping you adapt.
|
4
4
|
|
5
5
|
== Note on Patches/Pull Requests
|
6
|
-
|
6
|
+
|
7
7
|
* Fork the project.
|
8
|
+
* `bundle install`
|
9
|
+
* `bundle lock`
|
10
|
+
* `rake test`
|
8
11
|
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
12
|
|
15
13
|
== Copyright
|
16
14
|
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.6
|
data/lib/mario.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Posix?
|
2
|
+
module Mario
|
3
|
+
module Hats
|
4
|
+
module Nix
|
5
|
+
|
6
|
+
# Escapes paths for use in execute statements
|
7
|
+
#
|
8
|
+
# @param [String]
|
9
|
+
# @return [String]
|
10
|
+
def shell_escape_path(str)
|
11
|
+
# Taken from ruby mailing list, seems to work, probably needs lots of testing :(
|
12
|
+
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').
|
13
|
+
gsub(/\n/, "'\n'").
|
14
|
+
sub(/^$/, "''")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Mario
|
2
|
+
module Hats
|
3
|
+
module Windows
|
4
|
+
# Escapes a file paths for use in system calls and execute statements
|
5
|
+
# @param [String]
|
6
|
+
# @return [String]
|
7
|
+
def shell_escape_path(str)
|
8
|
+
#Wrap windows paths with white space in quotes
|
9
|
+
str =~ /\s/ ? "\"#{str}\"" : str
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/mario/platform.rb
CHANGED
@@ -1,91 +1,215 @@
|
|
1
1
|
module Mario
|
2
2
|
class Platform
|
3
3
|
@@forced = nil
|
4
|
+
@@logger = nil
|
5
|
+
@@current = nil
|
4
6
|
|
5
7
|
class << self
|
8
|
+
|
9
|
+
# A list of unix like operating system classes
|
10
|
+
#
|
11
|
+
# @return [Array[Class]]
|
6
12
|
def nix_group
|
7
|
-
|
8
|
-
:linux => 'linux',
|
9
|
-
:osx => 'darwin',
|
10
|
-
:solaris => 'solaris',
|
11
|
-
:bsd => 'bsd'}
|
13
|
+
[Cygwin, Linux, BSD, Solaris, Darwin]
|
12
14
|
end
|
13
15
|
|
16
|
+
# A list of windows operating system classes
|
17
|
+
#
|
18
|
+
# @return [Array[Class]]
|
14
19
|
def windows_group
|
15
|
-
|
16
|
-
:win7 => 'mingw' }
|
20
|
+
[Windows7, WindowsNT]
|
17
21
|
end
|
18
22
|
|
23
|
+
# The union of the {nix_group} and {windows_group} operating system class sets
|
24
|
+
#
|
25
|
+
# @return [Array[Class]]
|
19
26
|
def targets
|
20
|
-
nix_group
|
27
|
+
nix_group | windows_group
|
21
28
|
end
|
22
29
|
|
30
|
+
# Checks if the current platform is linux
|
31
|
+
#
|
32
|
+
# @return [true, false]
|
23
33
|
def linux?
|
24
|
-
|
34
|
+
check Linux
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
# Checks if the current platform is osx
|
38
|
+
#
|
39
|
+
# @return [true, false]
|
40
|
+
def darwin?
|
41
|
+
check Darwin
|
29
42
|
end
|
30
43
|
|
44
|
+
# Checks if the current platform is solaris
|
45
|
+
#
|
46
|
+
# @return [true, false]
|
31
47
|
def solaris?
|
32
|
-
|
48
|
+
check Solaris
|
33
49
|
end
|
34
|
-
|
50
|
+
|
51
|
+
# Checks if the current platform is bsd
|
52
|
+
#
|
53
|
+
# @return [true, false]
|
35
54
|
def bsd?
|
36
|
-
|
55
|
+
check BSD
|
37
56
|
end
|
38
57
|
|
58
|
+
# Checks if the current platform is cygwin
|
59
|
+
#
|
60
|
+
# @return [true, false]
|
39
61
|
def cygwin?
|
40
|
-
|
62
|
+
check Cygwin
|
41
63
|
end
|
42
64
|
|
43
|
-
|
44
|
-
|
65
|
+
# Checks if the current platform is windows 7
|
66
|
+
#
|
67
|
+
# @return [true, false]
|
68
|
+
def windows7?
|
69
|
+
check Windows7
|
45
70
|
end
|
46
71
|
|
47
|
-
|
48
|
-
|
72
|
+
# Checks if the current platform is windows nt
|
73
|
+
#
|
74
|
+
# @return [true, false]
|
75
|
+
def windowsnt?
|
76
|
+
check WindowsNT
|
49
77
|
end
|
50
78
|
|
79
|
+
# Checks if the current platform is part of the {nix_group} and returns that class
|
80
|
+
#
|
81
|
+
# @return [Class]
|
51
82
|
def nix?
|
52
83
|
check_group nix_group
|
53
84
|
end
|
54
85
|
|
86
|
+
# Checks if the current platform is part of the {windows_group} and returns that class
|
87
|
+
#
|
88
|
+
# @return [Class]
|
55
89
|
def windows?
|
56
90
|
check_group windows_group
|
57
91
|
end
|
58
92
|
|
93
|
+
# Checks a list of possible operating system classes to see if their target os strings match the {target_os} value
|
94
|
+
#
|
95
|
+
# @return [Class]
|
59
96
|
def check_group(group)
|
60
|
-
group.each do |
|
61
|
-
return
|
97
|
+
group.each do |klass|
|
98
|
+
return klass if check klass
|
62
99
|
end
|
63
100
|
false
|
64
101
|
end
|
65
102
|
|
66
|
-
alias_method :
|
103
|
+
alias_method :osx?, :darwin?
|
67
104
|
|
68
|
-
|
69
|
-
|
105
|
+
# Uses the forced class target os string if provided otherwise uses the target_os rbconfig hash element
|
106
|
+
#
|
107
|
+
# @return [String]
|
108
|
+
def target_os
|
109
|
+
@@forced ? @@forced.target : Config::CONFIG['target_os']
|
70
110
|
end
|
71
111
|
|
72
|
-
|
73
|
-
|
112
|
+
# Checks an os class against {target_os}
|
113
|
+
#
|
114
|
+
# @return [true, false]
|
115
|
+
def check(klass)
|
116
|
+
target_os.downcase.include?(klass.target)
|
74
117
|
end
|
75
118
|
|
76
|
-
|
77
|
-
|
78
|
-
|
119
|
+
# Allows the user to force Mario to report the operating system as one of the provided operatin system classes
|
120
|
+
#
|
121
|
+
def forced=(klass)
|
122
|
+
@@current=nil
|
123
|
+
@@forced=klass
|
124
|
+
logger.warn(<<-msg)
|
125
|
+
Mario::Platform.target_os will now report as '#{target_os}' and #{klass} will be used for all functionality including operating system checks and hat based functionality (See Mario::Hats for more information)
|
126
|
+
msg
|
79
127
|
end
|
80
128
|
|
129
|
+
# Returns the value of the currently forced operating system class if any
|
130
|
+
#
|
131
|
+
# @return [Class]
|
81
132
|
def forced
|
82
133
|
@@forced
|
83
134
|
end
|
84
135
|
|
136
|
+
# Allows the setting of a logging mechanism, defaults to STDOUT
|
137
|
+
#
|
138
|
+
# @return [Logger]
|
85
139
|
def logger(out=STDOUT)
|
86
|
-
@@logger ||= Logger.new(
|
140
|
+
@@logger ||= Logger.new(out)
|
87
141
|
@@logger
|
88
142
|
end
|
143
|
+
|
144
|
+
# Returns an instance of the current operating system class as determined by {check_group} against all operating
|
145
|
+
# system classes provided by {targets}
|
146
|
+
#
|
147
|
+
# @return [OperatingSystem]
|
148
|
+
def current
|
149
|
+
# Search for the current target os
|
150
|
+
current_target_klass = check_group(targets)
|
151
|
+
@@current ||= current_target_klass.new
|
152
|
+
@@current
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Any additional fucniontality and they should be moved to a lib/platforms/<OS>.rb
|
157
|
+
class Cygwin
|
158
|
+
include Hats::Nix
|
159
|
+
|
160
|
+
def self.target
|
161
|
+
'cygwin'
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
class Darwin
|
167
|
+
include Hats::Nix
|
168
|
+
|
169
|
+
def self.target
|
170
|
+
'darwin'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class Linux
|
175
|
+
include Hats::Nix
|
176
|
+
|
177
|
+
def self.target
|
178
|
+
'linux'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class BSD
|
183
|
+
include Hats::Nix
|
184
|
+
|
185
|
+
def self.target
|
186
|
+
'bsd'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
class Solaris
|
191
|
+
include Hats::Nix
|
192
|
+
|
193
|
+
def self.target
|
194
|
+
'solaris'
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
class Windows7
|
200
|
+
include Hats::Windows
|
201
|
+
|
202
|
+
def self.target
|
203
|
+
'mingw'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
class WindowsNT
|
208
|
+
include Hats::Windows
|
209
|
+
|
210
|
+
def self.target
|
211
|
+
'mswin'
|
212
|
+
end
|
89
213
|
end
|
90
214
|
end
|
91
215
|
end
|
data/mario.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mario}
|
8
|
+
s.version = "0.0.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Bender"]
|
12
|
+
s.date = %q{2010-03-20}
|
13
|
+
s.description = %q{Mario is a collection of utilities for dealing with platform specific issues}
|
14
|
+
s.email = %q{john.m.bender@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/mario.rb",
|
27
|
+
"lib/mario/hats/nix.rb",
|
28
|
+
"lib/mario/hats/windows.rb",
|
29
|
+
"lib/mario/platform.rb",
|
30
|
+
"mario.gemspec",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/mario/hats/test_nix.rb",
|
33
|
+
"test/mario/hats/test_windows.rb",
|
34
|
+
"test/mario/test_plaform.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/johnbender/mario}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Mario is a collection of utilities for dealing with platform specific issues}
|
41
|
+
s.test_files = [
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/mario/hats/test_nix.rb",
|
44
|
+
"test/mario/hats/test_windows.rb",
|
45
|
+
"test/mario/test_plaform.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestNixHat < Test::Unit::TestCase
|
4
|
+
context "Mario's Nix Hat" do
|
5
|
+
setup do
|
6
|
+
Mario::Platform.forced = Mario::Platform::Linux
|
7
|
+
end
|
8
|
+
|
9
|
+
should "escape weird characters in paths meant for a shell command " do
|
10
|
+
%w( $ @ % ^ & * ).each do |char|
|
11
|
+
assert Mario::Platform.current.shell_escape_path(char).include?('\\')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestWindowsHat < Test::Unit::TestCase
|
4
|
+
context "Mario's windows hat" do
|
5
|
+
setup do
|
6
|
+
Mario::Platform.forced = Mario::Platform::Windows7
|
7
|
+
end
|
8
|
+
|
9
|
+
should "wrap file paths with white space in double quotes" do
|
10
|
+
result = Mario::Platform.current.shell_escape_path(' something serious ')
|
11
|
+
assert result =~ /^".+"$/
|
12
|
+
end
|
13
|
+
|
14
|
+
should "not have spaces escaped" do
|
15
|
+
assert !Mario::Platform.current.shell_escape_path( 'a b' ).include?('\\')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/mario/test_plaform.rb
CHANGED
@@ -1,53 +1,64 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestPlatform < Test::Unit::TestCase
|
4
|
-
context "Mario
|
5
|
-
|
4
|
+
context "Mario platforms" do
|
5
|
+
context 'on any platform' do
|
6
|
+
setup do
|
7
|
+
Mario::Platform.forced = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
should "find at least one os representing a class" do
|
11
|
+
assert Mario::Platform.check_group(Mario::Platform.targets)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
6
15
|
context 'when testing for *nix' do
|
7
16
|
should 'return true for all known variants' do
|
8
|
-
Mario::Platform::nix_group.each do |
|
9
|
-
assert check_nix(
|
17
|
+
Mario::Platform::nix_group.each do |klass|
|
18
|
+
assert check_nix(klass)
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
13
22
|
should 'return false for all other' do
|
14
23
|
# TODO use relative complement of nix_group in targets
|
15
|
-
Mario::Platform::windows_group.each do |
|
16
|
-
assert !check_nix(
|
24
|
+
Mario::Platform::windows_group.each do |klass|
|
25
|
+
assert !check_nix(klass)
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
30
|
context 'when testing for windows' do
|
22
|
-
should '
|
23
|
-
Mario::Platform.windows_group.each do |
|
24
|
-
assert check_win(
|
31
|
+
should 'return true for all known variants' do
|
32
|
+
Mario::Platform.windows_group.each do |klass|
|
33
|
+
assert check_win(klass)
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
28
37
|
should 'return false for others' do
|
29
38
|
# TODO use relative complement of windows_group in targets
|
30
|
-
Mario::Platform.nix_group.each do |
|
31
|
-
assert !check_win(
|
39
|
+
Mario::Platform.nix_group.each do |klass|
|
40
|
+
assert !check_win(klass)
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
36
45
|
context 'when checking any os with abnormal target strings' do
|
37
46
|
should 'handle extranious characters' do
|
38
|
-
|
47
|
+
Mario::Platform.expects(:target_os).twice.returns("12%#{first_os_klass.target}&%$")
|
48
|
+
assert check_nix first_os_klass
|
39
49
|
end
|
40
50
|
|
41
51
|
should 'handle capitals' do
|
42
|
-
|
52
|
+
Mario::Platform.expects(:target_os).twice.returns(first_os_klass.target.upcase)
|
53
|
+
assert check_nix first_os_klass
|
43
54
|
end
|
44
55
|
end
|
45
56
|
|
46
57
|
context 'when checking an os' do
|
47
58
|
should 'respond positively to each os listed in targets' do
|
48
|
-
Mario::Platform.targets.each do |
|
49
|
-
Mario::Platform.forced =
|
50
|
-
assert Mario::Platform.send(
|
59
|
+
Mario::Platform.targets.each do |klass|
|
60
|
+
Mario::Platform.forced = klass
|
61
|
+
assert Mario::Platform.send(klass.to_s.split('::').last.downcase + '?')
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
@@ -56,19 +67,58 @@ class TestPlatform < Test::Unit::TestCase
|
|
56
67
|
should 'log at a warning level' do
|
57
68
|
logger = mock('logger')
|
58
69
|
Mario::Platform.expects(:logger).returns(logger)
|
59
|
-
logger.expects(:warn).with
|
60
|
-
|
70
|
+
logger.expects(:warn).with do |string|
|
71
|
+
string =~ /#{first_os_klass.target}/ && string =~ /#{first_os_klass}/
|
72
|
+
end
|
73
|
+
Mario::Platform.forced = first_os_klass
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'reset the current os' do
|
77
|
+
mock_klass = mock('platform klass')
|
78
|
+
Mario::Platform.forced = first_os_klass
|
79
|
+
Mario::Platform.expects(:check_group).with(Mario::Platform.targets).returns(mock_klass)
|
80
|
+
mock_klass.expects(:new).returns(nil)
|
81
|
+
assert !Mario::Platform.current
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'checking a group' do
|
86
|
+
setup do
|
87
|
+
@forced = mock_os_klass('force')
|
88
|
+
Mario::Platform.forced = @forced
|
89
|
+
end
|
90
|
+
|
91
|
+
should "return the os class itself when found" do
|
92
|
+
assert Mario::Platform.check_group([mock_os_klass, @forced, mock_os_klass]) == @forced
|
93
|
+
end
|
94
|
+
|
95
|
+
should "return once if one is found in a group of classes that respond to target" do
|
96
|
+
assert Mario::Platform.check_group([mock_os_klass, @forced, mock_os_klass])
|
97
|
+
end
|
98
|
+
|
99
|
+
should "return not return one if non are found" do
|
100
|
+
assert !Mario::Platform.check_group([mock_os_klass, mock_os_klass])
|
61
101
|
end
|
62
102
|
end
|
63
103
|
end
|
64
104
|
|
65
105
|
def check_nix(force)
|
66
|
-
Mario::Platform.forced =
|
106
|
+
Mario::Platform.forced = force
|
67
107
|
Mario::Platform.nix?
|
68
108
|
end
|
69
109
|
|
70
110
|
def check_win(force)
|
71
|
-
Mario::Platform.forced =
|
111
|
+
Mario::Platform.forced = force
|
72
112
|
Mario::Platform.windows?
|
73
113
|
end
|
114
|
+
|
115
|
+
def first_os_klass
|
116
|
+
Mario::Platform.targets.first
|
117
|
+
end
|
118
|
+
|
119
|
+
def mock_os_klass(str='foo')
|
120
|
+
mock = mock('os klass')
|
121
|
+
mock.stubs(:target).returns(str)
|
122
|
+
mock
|
123
|
+
end
|
74
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bender
|
@@ -47,12 +47,16 @@ files:
|
|
47
47
|
- LICENSE
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
|
+
- VERSION
|
50
51
|
- lib/mario.rb
|
52
|
+
- lib/mario/hats/nix.rb
|
53
|
+
- lib/mario/hats/windows.rb
|
51
54
|
- lib/mario/platform.rb
|
52
|
-
-
|
55
|
+
- mario.gemspec
|
53
56
|
- test/helper.rb
|
57
|
+
- test/mario/hats/test_nix.rb
|
58
|
+
- test/mario/hats/test_windows.rb
|
54
59
|
- test/mario/test_plaform.rb
|
55
|
-
- test/mario/test_toolbelt.rb
|
56
60
|
has_rdoc: true
|
57
61
|
homepage: http://github.com/johnbender/mario
|
58
62
|
licenses: []
|
@@ -83,5 +87,6 @@ specification_version: 3
|
|
83
87
|
summary: Mario is a collection of utilities for dealing with platform specific issues
|
84
88
|
test_files:
|
85
89
|
- test/helper.rb
|
90
|
+
- test/mario/hats/test_nix.rb
|
91
|
+
- test/mario/hats/test_windows.rb
|
86
92
|
- test/mario/test_plaform.rb
|
87
|
-
- test/mario/test_toolbelt.rb
|
data/lib/mario/toolbelt.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Mario
|
2
|
-
class Toolbelt
|
3
|
-
class << self
|
4
|
-
|
5
|
-
# Stolen shamelessly from Mitchell Hashimoto's Virtualbox gem!
|
6
|
-
# TODO more research
|
7
|
-
def shell_escape_path(str)
|
8
|
-
if Platform.windows?
|
9
|
-
#Wrap windows paths with white space in quotes
|
10
|
-
str = "\"#{str}\"" if str =~ /\s/
|
11
|
-
return str
|
12
|
-
end
|
13
|
-
|
14
|
-
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').
|
15
|
-
gsub(/\n/, "'\n'").
|
16
|
-
sub(/^$/, "''")
|
17
|
-
end
|
18
|
-
|
19
|
-
# Mario would just jumpt to escape a shell's path
|
20
|
-
alias_method :jump, :shell_escape_path
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/test/mario/test_toolbelt.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestPlatform < Test::Unit::TestCase
|
4
|
-
context "Mario's toolbelt" do
|
5
|
-
context "on all platforms" do
|
6
|
-
should "escape weird characters in paths meant for a shell command " do
|
7
|
-
%w( $ @ % ^ & * ).each do |char|
|
8
|
-
assert Mario::Toolbelt.shell_escape_path(char).include?('\\')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "on windows" do
|
14
|
-
setup do
|
15
|
-
Mario::Platform.forced = Mario::Platform.targets[:win7]
|
16
|
-
end
|
17
|
-
|
18
|
-
should "wrap file paths with white space in double quotes" do
|
19
|
-
result = Mario::Toolbelt.shell_escape_path(' something serious ')
|
20
|
-
assert result =~ /^"/
|
21
|
-
assert result =~ /"$/
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|