launchy 2.5.0 → 3.0.1
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/CONTRIBUTING.md +1 -0
- data/HISTORY.md +38 -20
- data/{LICENSE → LICENSE.txt} +1 -1
- data/Manifest.txt +4 -21
- data/README.md +10 -47
- data/exe/launchy +5 -0
- data/launchy.gemspec +32 -0
- data/lib/launchy/application.rb +38 -20
- data/lib/launchy/applications/browser.rb +68 -63
- data/lib/launchy/argv.rb +11 -6
- data/lib/launchy/cli.rb +29 -34
- data/lib/launchy/descendant_tracker.rb +14 -12
- data/lib/launchy/detect/host_os.rb +21 -18
- data/lib/launchy/detect/host_os_family.rb +94 -53
- data/lib/launchy/detect/nix_desktop_environment.rb +74 -69
- data/lib/launchy/detect.rb +7 -5
- data/lib/launchy/error.rb +2 -0
- data/lib/launchy/os_family.rb +2 -0
- data/lib/launchy/runner.rb +54 -0
- data/lib/launchy/version.rb +7 -5
- data/lib/launchy.rb +76 -68
- metadata +22 -93
- data/Rakefile +0 -27
- data/bin/launchy +0 -4
- data/lib/launchy/deprecated.rb +0 -52
- data/lib/launchy/detect/ruby_engine.rb +0 -78
- data/lib/launchy/detect/runner.rb +0 -152
- data/spec/application_spec.rb +0 -43
- data/spec/applications/browser_spec.rb +0 -78
- data/spec/cli_spec.rb +0 -75
- data/spec/detect/host_os_family_spec.rb +0 -42
- data/spec/detect/host_os_spec.rb +0 -19
- data/spec/detect/nix_desktop_environment_spec.rb +0 -27
- data/spec/detect/ruby_engine_spec.rb +0 -37
- data/spec/detect/runner_spec.rb +0 -103
- data/spec/launchy_spec.rb +0 -119
- data/spec/mock_application.rb +0 -9
- data/spec/spec_helper.rb +0 -11
- data/spec/tattle-host-os.yaml +0 -427
- data/spec/version_spec.rb +0 -11
- data/tasks/default.rake +0 -242
- data/tasks/this.rb +0 -208
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
require 'shellwords'
|
|
2
|
-
require 'stringio'
|
|
3
|
-
|
|
4
|
-
module Launchy::Detect
|
|
5
|
-
class Runner
|
|
6
|
-
class NotFoundError < Launchy::Error; end
|
|
7
|
-
|
|
8
|
-
extend ::Launchy::DescendantTracker
|
|
9
|
-
|
|
10
|
-
# Detect the current command runner
|
|
11
|
-
#
|
|
12
|
-
# This will return an instance of the Runner to be used to do the
|
|
13
|
-
# application launching.
|
|
14
|
-
#
|
|
15
|
-
# If a runner cannot be detected then raise Runner::NotFoundError
|
|
16
|
-
#
|
|
17
|
-
# The runner rules are, in order:
|
|
18
|
-
#
|
|
19
|
-
# 1) If you are on windows, you use the Windows Runner no matter what
|
|
20
|
-
# 2) If you are using the jruby engine, use the Jruby Runner. Unless rule
|
|
21
|
-
# (1) took effect
|
|
22
|
-
# 3) Use Forkable (barring rules (1) and (2))
|
|
23
|
-
def self.detect
|
|
24
|
-
host_os_family = Launchy::Detect::HostOsFamily.detect
|
|
25
|
-
ruby_engine = Launchy::Detect::RubyEngine.detect
|
|
26
|
-
|
|
27
|
-
return Windows.new if host_os_family.windows?
|
|
28
|
-
if ruby_engine.jruby? then
|
|
29
|
-
return Jruby.new
|
|
30
|
-
end
|
|
31
|
-
return Forkable.new
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
# cut it down to just the shell commands that will be passed to exec or
|
|
36
|
-
# posix_spawn. The cmd argument is split according to shell rules and the
|
|
37
|
-
# args are not escaped because they whole set is passed to system as *args
|
|
38
|
-
# and in that case system shell escaping rules are not done.
|
|
39
|
-
#
|
|
40
|
-
def shell_commands( cmd, args )
|
|
41
|
-
cmdline = [ cmd.to_s.shellsplit ]
|
|
42
|
-
cmdline << args.flatten.collect{ |a| a.to_s }
|
|
43
|
-
return commandline_normalize( cmdline )
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def commandline_normalize( cmdline )
|
|
47
|
-
c = cmdline.flatten!
|
|
48
|
-
c = c.find_all { |a| (not a.nil?) and ( a.size > 0 ) }
|
|
49
|
-
Launchy.log "commandline_normalized => #{c.join(' ')}"
|
|
50
|
-
return c
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def dry_run( cmd, *args )
|
|
54
|
-
shell_commands(cmd, args).join(" ")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def run( cmd, *args )
|
|
58
|
-
raise Launchy::CommandNotFoundError, "No command found to run with args '#{args.join(' ')}'. If this is unexpected, #{Launchy.bug_report_message}" unless cmd
|
|
59
|
-
if Launchy.dry_run? then
|
|
60
|
-
$stdout.puts dry_run( cmd, *args )
|
|
61
|
-
else
|
|
62
|
-
wet_run( cmd, *args )
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
#---------------------------------------
|
|
68
|
-
# The list of known runners
|
|
69
|
-
#---------------------------------------
|
|
70
|
-
|
|
71
|
-
class Windows < Runner
|
|
72
|
-
|
|
73
|
-
def all_args( cmd, *args )
|
|
74
|
-
args = [ 'cmd', '/c', *shell_commands( cmd, *args ) ]
|
|
75
|
-
Launchy.log "Windows: all_args => #{args.inspect}"
|
|
76
|
-
return args
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def dry_run( cmd, *args )
|
|
80
|
-
all_args( cmd, *args ).join(" ")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# escape the reserved shell characters in windows command shell
|
|
84
|
-
# http://technet.microsoft.com/en-us/library/cc723564.aspx
|
|
85
|
-
#
|
|
86
|
-
# Also make sure that the item after 'start' is guaranteed to be quoted.
|
|
87
|
-
# https://github.com/copiousfreetime/launchy/issues/62
|
|
88
|
-
def shell_commands( cmd, *args )
|
|
89
|
-
parts = cmd.shellsplit
|
|
90
|
-
|
|
91
|
-
if start_idx = parts.index('start') then
|
|
92
|
-
title_idx = start_idx + 1
|
|
93
|
-
title = parts[title_idx]
|
|
94
|
-
title = title.sub(/^/,'"') unless title[0] == '"'
|
|
95
|
-
title = title.sub(/$/,'"') unless title[-1] == '"'
|
|
96
|
-
parts[title_idx] = title
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
cmdline = [ parts ]
|
|
100
|
-
cmdline << args.flatten.collect { |a| a.to_s.gsub(/([&|()<>^])/, "^\\1") }
|
|
101
|
-
return commandline_normalize( cmdline )
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def wet_run( cmd, *args )
|
|
105
|
-
system( *all_args( cmd, *args ) )
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
class Jruby < Runner
|
|
110
|
-
def wet_run( cmd, *args )
|
|
111
|
-
child_pid = spawn( *shell_commands( cmd, *args ) )
|
|
112
|
-
Process.detach( child_pid )
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
class Forkable < Runner
|
|
117
|
-
attr_reader :child_pid
|
|
118
|
-
|
|
119
|
-
def wet_run( cmd, *args )
|
|
120
|
-
@child_pid = fork do
|
|
121
|
-
close_file_descriptors unless Launchy.debug?
|
|
122
|
-
Launchy.log("wet_run: before exec in child process")
|
|
123
|
-
exec_or_raise( cmd, *args )
|
|
124
|
-
exit!
|
|
125
|
-
end
|
|
126
|
-
Process.detach( @child_pid )
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
private
|
|
130
|
-
|
|
131
|
-
# attaching to a StringIO instead of reopening so we don't loose the
|
|
132
|
-
# STDERR, needed for exec_or_raise.
|
|
133
|
-
def close_file_descriptors
|
|
134
|
-
$stdin.reopen( "/dev/null")
|
|
135
|
-
|
|
136
|
-
@saved_stdout = $stdout
|
|
137
|
-
@saved_stderr = $stderr
|
|
138
|
-
|
|
139
|
-
$stdout = StringIO.new
|
|
140
|
-
$stderr = StringIO.new
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def exec_or_raise( cmd, *args )
|
|
144
|
-
exec( *shell_commands( cmd, *args ))
|
|
145
|
-
rescue Exception => e
|
|
146
|
-
$stderr = @saved_stderr
|
|
147
|
-
$stdout = @saved_stdout
|
|
148
|
-
raise e
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
end
|
data/spec/application_spec.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'mock_application'
|
|
3
|
-
|
|
4
|
-
class JunkApp < Launchy::Application
|
|
5
|
-
def self.handles?( uri )
|
|
6
|
-
uri.scheme == "junk"
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe Launchy::Application do
|
|
11
|
-
it 'registers inherited classes' do
|
|
12
|
-
class Junk2App < Launchy::Application
|
|
13
|
-
def self.handles?( uri )
|
|
14
|
-
uri.scheme == "junk2"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
_(Launchy::Application.children).must_include( Junk2App )
|
|
18
|
-
Launchy::Application.children.delete( Junk2App )
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "can find an app" do
|
|
22
|
-
_(Launchy::Application.children).must_include( JunkApp )
|
|
23
|
-
_(Launchy::Application.children.size).must_equal 3
|
|
24
|
-
uri = Addressable::URI.parse( "junk:///foo" )
|
|
25
|
-
_(Launchy::Application.handling( uri )).must_equal( JunkApp )
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "raises an error if an application cannot be found for the given scheme" do
|
|
29
|
-
uri = Addressable::URI.parse( "foo:///bar" )
|
|
30
|
-
_(lambda { Launchy::Application.handling( uri ) }).must_raise( Launchy::ApplicationNotFoundError )
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "can find open or curl or xdg-open" do
|
|
34
|
-
found = %w[ open curl xdg-open ].any? do |app|
|
|
35
|
-
Launchy::Application.find_executable( app )
|
|
36
|
-
end
|
|
37
|
-
_(found).must_equal true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "does not find xyzzy" do
|
|
41
|
-
_(Launchy::Application.find_executable( "xyzzy" )).must_be_nil
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Launchy::Application::Browser do
|
|
4
|
-
before do
|
|
5
|
-
Launchy.reset_global_options
|
|
6
|
-
ENV['KDE_FULL_SESSION'] = "launchy"
|
|
7
|
-
@test_url = "http://example.com/"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after do
|
|
11
|
-
Launchy.reset_global_options
|
|
12
|
-
ENV.delete( 'KDE_FULL_SESSION' )
|
|
13
|
-
ENV.delete( 'BROWSER' )
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
{ 'windows' => 'start "launchy" /b' ,
|
|
17
|
-
'darwin' => [ '/usr/bin/open', '/bin/open' ], # because running tests on linux
|
|
18
|
-
'cygwin' => 'cmd /C start "launchy" /b',
|
|
19
|
-
'linux' => [nil, "xdg-open"], # because running tests on linux
|
|
20
|
-
}.each do |host_os, expected|
|
|
21
|
-
it "when host_os is '#{host_os}' the appropriate 'app_list' method is called" do
|
|
22
|
-
Launchy.host_os = host_os
|
|
23
|
-
browser = Launchy::Application::Browser.new
|
|
24
|
-
|
|
25
|
-
item = browser.app_list.first
|
|
26
|
-
item = item.to_s if item.kind_of?(::Launchy::Argv)
|
|
27
|
-
case expected
|
|
28
|
-
when Array
|
|
29
|
-
_(expected).must_include item
|
|
30
|
-
when String
|
|
31
|
-
_(item).must_equal expected
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
%w[ linux windows darwin cygwin ].each do |host_os|
|
|
37
|
-
it "the BROWSER environment variable overrides any host defaults on '#{host_os}'" do
|
|
38
|
-
ENV['BROWSER'] = "my_special_browser --new-tab '%s'"
|
|
39
|
-
Launchy.host_os = host_os
|
|
40
|
-
browser = Launchy::Application::Browser.new
|
|
41
|
-
cmd, args = browser.cmd_and_args( @test_url )
|
|
42
|
-
_(cmd).must_equal "my_special_browser --new-tab 'http://example.com/'"
|
|
43
|
-
_(args).must_equal []
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "handles a file on the file system when there is no file:// scheme" do
|
|
48
|
-
uri = Addressable::URI.parse( __FILE__ )
|
|
49
|
-
_(Launchy::Application::Browser.handles?( uri )).must_equal true
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "handles the case where $BROWSER is set and no *nix desktop environment is found" do
|
|
53
|
-
ENV.delete( "KDE_FULL_SESSION" )
|
|
54
|
-
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
|
|
55
|
-
ENV['BROWSER'] = "do-this-instead"
|
|
56
|
-
Launchy.host_os = 'linux'
|
|
57
|
-
browser = Launchy::Application::Browser.new
|
|
58
|
-
_(browser.browser_cmdline).must_equal "do-this-instead"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# NOTE: Unable to figure out how capture the stderr from the child which has
|
|
62
|
-
# moved it at least once. This test just serves the purpose of noting why
|
|
63
|
-
# something happens, and the problem we are attempting to fix.
|
|
64
|
-
#it "When BROWSER is set to something that is not executable, error still appears on stderr" do
|
|
65
|
-
# ENV['BROWSER'] = "not-an-app"
|
|
66
|
-
# url = "http://example.com/"
|
|
67
|
-
|
|
68
|
-
# _, err = capture_subprocess_io do
|
|
69
|
-
# begin
|
|
70
|
-
# Launchy.open( url )
|
|
71
|
-
# rescue => nil
|
|
72
|
-
# end
|
|
73
|
-
# end
|
|
74
|
-
# #_(err).must_match( /wibble/m )
|
|
75
|
-
# err # something
|
|
76
|
-
#end
|
|
77
|
-
end
|
|
78
|
-
|
data/spec/cli_spec.rb
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Launchy::Cli do
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
@old_stderr = $stderr
|
|
7
|
-
$stderr = StringIO.new
|
|
8
|
-
|
|
9
|
-
@old_stdout = $stdout
|
|
10
|
-
$stdout = StringIO.new
|
|
11
|
-
Launchy.reset_global_options
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after do
|
|
15
|
-
Launchy.reset_global_options
|
|
16
|
-
$stderr = @old_stderr
|
|
17
|
-
$stdout = @old_stdout
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def cli_test( argv, env, exit_val, stderr_regex, stdout_regex )
|
|
21
|
-
begin
|
|
22
|
-
Launchy::Cli.new.run( argv, env )
|
|
23
|
-
rescue SystemExit => se
|
|
24
|
-
_(se.status).must_equal exit_val
|
|
25
|
-
_($stderr.string).must_match stderr_regex if stderr_regex
|
|
26
|
-
_($stdout.string).must_match stdout_regex if stdout_regex
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "exits 1 when invalid options are given" do
|
|
31
|
-
cli_test( %w[ -z foo ], {}, 1, /invalid option/, nil )
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
%w[ -h --help ].each do |opt|
|
|
35
|
-
it "output help and exits 0 when using #{opt}" do
|
|
36
|
-
cli_test( [ opt ], {}, 0, nil, /Print this message/m )
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
%w[ -v --version ].each do |opt|
|
|
41
|
-
it "outputs version and exits 0 when using #{opt}" do
|
|
42
|
-
cli_test( [ opt ], {}, 0, nil, /Launchy version/ )
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "leaves the url on argv after parsing" do
|
|
47
|
-
l = Launchy::Cli.new
|
|
48
|
-
argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
|
|
49
|
-
l.parse( argv , {} )
|
|
50
|
-
_(argv.size).must_equal 1
|
|
51
|
-
_(argv[0]).must_equal "http://github.com/copiousfreetime/launchy"
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "prints the command on stdout when using --dry-run" do
|
|
55
|
-
argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
|
|
56
|
-
Launchy::Cli.new.good_run( argv, {} )
|
|
57
|
-
_($stdout.string).must_match %r[github.com]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
'--application' => [ :application, 'Browser'],
|
|
62
|
-
'--engine' => [ :ruby_engine, 'rbx'],
|
|
63
|
-
'--host-os' => [ :host_os, 'cygwin'] }.each_pair do |opt, val|
|
|
64
|
-
it "the commandline option #{opt} sets the program option #{val[0]}" do
|
|
65
|
-
argv = [ opt, val[1], "http://github.com/copiousfreetime/launchy" ]
|
|
66
|
-
l = Launchy::Cli.new
|
|
67
|
-
rc = l.parse( argv, {} )
|
|
68
|
-
_(rc).must_equal true
|
|
69
|
-
_(argv.size).must_equal 1
|
|
70
|
-
_(argv[0]).must_equal "http://github.com/copiousfreetime/launchy"
|
|
71
|
-
_(l.options[val[0]]).must_equal val[1]
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'yaml'
|
|
3
|
-
|
|
4
|
-
describe Launchy::Detect::HostOsFamily do
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
Launchy.reset_global_options
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after do
|
|
11
|
-
Launchy.reset_global_options
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
YAML::load( IO.read( File.expand_path( "../../tattle-host-os.yaml", __FILE__ ) ) )['host_os'].keys.sort.each do |os|
|
|
15
|
-
it "OS family of #{os} is detected" do
|
|
16
|
-
os_family = Launchy::Detect::HostOsFamily.detect( os )
|
|
17
|
-
_(os_family).must_be_kind_of Launchy::Detect::HostOsFamily
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
{ 'mswin' => :windows?,
|
|
22
|
-
'darwin' => :darwin?,
|
|
23
|
-
'linux' => :nix?,
|
|
24
|
-
'cygwin' => :cygwin? }.each_pair do |os, method|
|
|
25
|
-
it "#{method} returns true for #{os} " do
|
|
26
|
-
r = Launchy::Detect::HostOsFamily.detect( os ).send( method )
|
|
27
|
-
_(r).must_equal true
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "uses the global host_os overrides" do
|
|
32
|
-
ENV['LAUNCHY_HOST_OS'] = "fake-os-2"
|
|
33
|
-
_(lambda { Launchy::Detect::HostOsFamily.detect }).must_raise Launchy::Detect::HostOsFamily::NotFoundError
|
|
34
|
-
ENV.delete('LAUNCHY_HOST_OS')
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
it "does not find an os of 'dos'" do
|
|
39
|
-
_(lambda { Launchy::Detect::HostOsFamily.detect( 'dos' ) }).must_raise Launchy::Detect::HostOsFamily::NotFoundError
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
data/spec/detect/host_os_spec.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Launchy::Detect::HostOs do
|
|
4
|
-
|
|
5
|
-
it "uses the defult host os from ruby's config" do
|
|
6
|
-
_(Launchy::Detect::HostOs.new.host_os).must_equal RbConfig::CONFIG['host_os']
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "uses the passed in value as the host os" do
|
|
10
|
-
_(Launchy::Detect::HostOs.new( "fake-os-1").host_os).must_equal "fake-os-1"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "uses the environment variable LAUNCHY_HOST_OS to override ruby's config" do
|
|
14
|
-
ENV['LAUNCHY_HOST_OS'] = "fake-os-2"
|
|
15
|
-
_(Launchy::Detect::HostOs.new.host_os).must_equal "fake-os-2"
|
|
16
|
-
ENV.delete('LAUNCHY_HOST_OS')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Launchy::Detect::NixDesktopEnvironment do
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
Launchy.reset_global_options
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
Launchy.reset_global_options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "returns false for XFCE if xprop is not found" do
|
|
14
|
-
Launchy.host_os = "linux"
|
|
15
|
-
_(Launchy::Detect::NixDesktopEnvironment::Xfce.is_current_desktop_environment?).must_equal( false )
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "returns NotFound if it cannot determine the *nix desktop environment" do
|
|
19
|
-
Launchy.host_os = "linux"
|
|
20
|
-
ENV.delete( "KDE_FULL_SESSION" )
|
|
21
|
-
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
|
|
22
|
-
Launchy.path = %w[ / /tmp ].join(File::PATH_SEPARATOR)
|
|
23
|
-
not_found = Launchy::Detect::NixDesktopEnvironment.detect
|
|
24
|
-
_(not_found).must_equal( Launchy::Detect::NixDesktopEnvironment::NotFound )
|
|
25
|
-
_(not_found.browser).must_equal( Launchy::Argv.new )
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Launchy::Detect::RubyEngine do
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
Launchy.reset_global_options
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
Launchy.reset_global_options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
%w[ ruby jruby rbx macruby ].each do |ruby|
|
|
14
|
-
it "detects the #{ruby} RUBY_ENGINE" do
|
|
15
|
-
_(Launchy::Detect::RubyEngine.detect( ruby ).ancestors).must_include Launchy::Detect::RubyEngine
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "uses the global ruby_engine overrides" do
|
|
20
|
-
ENV['LAUNCHY_RUBY_ENGINE'] = "rbx"
|
|
21
|
-
_(Launchy::Detect::RubyEngine.detect).must_equal Launchy::Detect::RubyEngine::Rbx
|
|
22
|
-
ENV.delete('LAUNCHY_RUBY_ENGINE')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "does not find a ruby engine of 'foo'" do
|
|
26
|
-
_(lambda { Launchy::Detect::RubyEngine.detect( 'foo' ) }).must_raise Launchy::Detect::RubyEngine::NotFoundError
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
{ 'rbx' => :rbx?,
|
|
30
|
-
'ruby' => :mri?,
|
|
31
|
-
'macruby' => :macruby?,
|
|
32
|
-
'jruby' => :jruby? }.each_pair do |engine, method|
|
|
33
|
-
it "#{method} returns true for #{engine} " do
|
|
34
|
-
_(Launchy::Detect::RubyEngine.detect( engine ).send( method )).must_equal true
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
data/spec/detect/runner_spec.rb
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe Launchy::Detect::Runner do
|
|
5
|
-
before do
|
|
6
|
-
Launchy.reset_global_options
|
|
7
|
-
@test_url = "http://example.com/?foo=bar&baz=wibble"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after do
|
|
11
|
-
Launchy.reset_global_options
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "raises an error when there is an unknown host os" do
|
|
15
|
-
Launchy.host_os = "foo"
|
|
16
|
-
_(lambda{ Launchy::Detect::Runner.detect }).must_raise Launchy::Detect::HostOsFamily::NotFoundError
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "raises an error when there is an unknown ruby engine" do
|
|
20
|
-
Launchy.ruby_engine = "wibble"
|
|
21
|
-
_(lambda{ Launchy::Detect::Runner.detect }).must_raise Launchy::Detect::RubyEngine::NotFoundError
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "raises and error when there is no command found" do
|
|
25
|
-
runner = Launchy::Detect::Runner.detect
|
|
26
|
-
_(lambda{ runner.run( nil, *%w[ arg1 arg2 arg 3] ) }).must_raise Launchy::CommandNotFoundError
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# On anything that has fork, use Forkable
|
|
30
|
-
%w[ linux darwin cygwin ].each do |host_os|
|
|
31
|
-
%w[ ruby rbx macruby ].each do |engine_name|
|
|
32
|
-
it "engine '#{engine_name}' on OS '#{host_os}' uses runner Forkable" do
|
|
33
|
-
Launchy.host_os = host_os
|
|
34
|
-
Launchy.ruby_engine = engine_name
|
|
35
|
-
engine = Launchy::Detect::Runner.detect
|
|
36
|
-
_(engine).must_be_instance_of Launchy::Detect::Runner::Forkable
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# Jruby always uses the Jruby runner except on Windows
|
|
43
|
-
{ 'mingw' => Launchy::Detect::Runner::Windows,
|
|
44
|
-
'linux' => Launchy::Detect::Runner::Jruby,
|
|
45
|
-
'darwin' => Launchy::Detect::Runner::Jruby,
|
|
46
|
-
'cygwin' => Launchy::Detect::Runner::Jruby, }.each_pair do |host_os, runner|
|
|
47
|
-
it "engine 'jruby' on OS '#{host_os}' uses runner #{runner.name}" do
|
|
48
|
-
Launchy.host_os = host_os
|
|
49
|
-
Launchy.ruby_engine = 'jruby'
|
|
50
|
-
engine = Launchy::Detect::Runner.detect
|
|
51
|
-
_(engine).must_be_instance_of runner
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# If you are on windows, no matter what engine, you use the windows runner
|
|
56
|
-
%w[ ruby rbx jruby macruby ].each do |engine_name|
|
|
57
|
-
it "uses a Windows runner when the engine is '#{engine_name}'" do
|
|
58
|
-
Launchy.host_os = "mingw"
|
|
59
|
-
Launchy.ruby_engine = engine_name
|
|
60
|
-
e = Launchy::Detect::Runner.detect
|
|
61
|
-
_(e).must_be_instance_of Launchy::Detect::Runner::Windows
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "Windows launches use the 'cmd' command" do
|
|
66
|
-
win = Launchy::Detect::Runner::Windows.new
|
|
67
|
-
cmd = win.dry_run( "not-really", [ "http://example.com" ] )
|
|
68
|
-
_(cmd).must_equal 'cmd /c not-really http://example.com'
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
%w[ & | ( ) < > ^ ].each do |reserved_char|
|
|
72
|
-
it "Windows escapes '#{reserved_char}' in urls" do
|
|
73
|
-
win = Launchy::Detect::Runner::Windows.new
|
|
74
|
-
parts = [ 'http://example.com/?foo=bar', 'baz=wibble' ]
|
|
75
|
-
url = parts.join( reserved_char )
|
|
76
|
-
output_url = parts.join( "^#{reserved_char}" )
|
|
77
|
-
|
|
78
|
-
_(win.all_args( "not-really", [ url ] )).must_equal [ 'cmd', '/c', 'not-really', output_url ]
|
|
79
|
-
|
|
80
|
-
cmd = win.dry_run( "not-really", [ url ] )
|
|
81
|
-
_(cmd).must_equal "cmd /c not-really #{output_url}"
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "Jruby doesnot escapes '&' in urls" do
|
|
86
|
-
jruby = Launchy::Detect::Runner::Jruby.new
|
|
87
|
-
cmd = jruby.dry_run( "not-really", [ @test_url ])
|
|
88
|
-
_(cmd).must_equal 'not-really http://example.com/?foo=bar&baz=wibble'
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "does not escape %38 items in urls" do
|
|
92
|
-
l = Launchy::Detect::Runner::Forkable.new
|
|
93
|
-
cmd = l.dry_run( "not-really", [ "http://ja.wikipedia.org/wiki/%E3%81%82" ] )
|
|
94
|
-
_(cmd).must_equal( 'not-really http://ja.wikipedia.org/wiki/%E3%81%82' )
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "can launch a utf8 url" do
|
|
98
|
-
url = "http://ja.wikipedia.org/wiki/あ"
|
|
99
|
-
l = Launchy::Detect::Runner::Forkable.new
|
|
100
|
-
cmd = l.dry_run( "not-really", [ url ] )
|
|
101
|
-
_(cmd).must_equal( "not-really #{url}" )
|
|
102
|
-
end
|
|
103
|
-
end
|