2009-12-09 04:52:23 +03:00
|
|
|
require 'helper'
|
2012-04-16 18:06:00 +04:00
|
|
|
require 'hub/standalone'
|
2009-12-09 06:06:45 +03:00
|
|
|
require 'fileutils'
|
2012-04-16 18:06:00 +04:00
|
|
|
require 'stringio'
|
2009-12-09 04:52:23 +03:00
|
|
|
|
2013-11-14 17:54:40 +04:00
|
|
|
class StandaloneTest < Minitest::Test
|
2009-12-09 06:06:45 +03:00
|
|
|
include FileUtils
|
|
|
|
|
|
|
|
def setup
|
2014-01-19 07:24:10 +04:00
|
|
|
rm "hub" if File.exist? 'hub'
|
|
|
|
rm_rf "/tmp/_hub_private" if File.exist? '/tmp/_hub_private'
|
2009-12-09 06:06:45 +03:00
|
|
|
mkdir "/tmp/_hub_private"
|
|
|
|
chmod 0400, "/tmp/_hub_private"
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2014-01-19 07:24:10 +04:00
|
|
|
rm "hub" if File.exist? 'hub'
|
|
|
|
rm_rf "/tmp/_hub_private" if File.exist? "/tmp/_hub_private"
|
2009-12-09 06:06:45 +03:00
|
|
|
end
|
|
|
|
|
2009-12-09 04:52:23 +03:00
|
|
|
def test_standalone
|
2012-04-16 18:06:00 +04:00
|
|
|
io = StringIO.new
|
|
|
|
Hub::Standalone.build io
|
|
|
|
standalone = io.string
|
|
|
|
|
|
|
|
assert_includes "This file is generated code", standalone
|
2009-12-09 04:52:23 +03:00
|
|
|
assert_includes "Runner", standalone
|
|
|
|
assert_includes "Args", standalone
|
|
|
|
assert_includes "Commands", standalone
|
|
|
|
assert_includes ".execute(*ARGV)", standalone
|
|
|
|
assert_not_includes "module Standalone", standalone
|
2009-12-09 23:10:31 +03:00
|
|
|
|
|
|
|
standalone =~ /__END__\s*(.+)/m
|
|
|
|
assert_equal File.read('man/hub.1'), $1
|
2009-12-09 04:52:23 +03:00
|
|
|
end
|
2009-12-09 06:06:45 +03:00
|
|
|
|
|
|
|
def test_standalone_save
|
2009-12-09 07:14:26 +03:00
|
|
|
Hub::Standalone.save("hub")
|
2013-12-20 07:55:56 +04:00
|
|
|
output = `RUBYOPT= RUBYLIB= ./hub version 2>&1`
|
|
|
|
assert_equal <<-OUT, output
|
|
|
|
git version 1.7.0.4
|
|
|
|
hub version #{Hub::VERSION}
|
|
|
|
OUT
|
2009-12-09 06:06:45 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_standalone_save_permission_denied
|
2009-12-09 07:14:26 +03:00
|
|
|
assert_raises Errno::EACCES do
|
|
|
|
Hub::Standalone.save("hub", "/tmp/_hub_private")
|
|
|
|
end
|
2009-12-09 06:06:45 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_standalone_save_doesnt_exist
|
2009-12-09 07:14:26 +03:00
|
|
|
assert_raises Errno::ENOENT do
|
|
|
|
Hub::Standalone.save("hub", "/tmp/something/not/real")
|
|
|
|
end
|
2009-12-09 06:06:45 +03:00
|
|
|
end
|
2009-12-09 04:52:23 +03:00
|
|
|
end
|