dev_commands 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/{timer.rb → Timer.rb} +40 -40
- data/lib/add.rb +19 -8
- data/lib/array.rb +24 -24
- data/lib/build.rb +31 -7
- data/lib/clean.rb +13 -13
- data/lib/clobber.rb +13 -12
- data/lib/command.rb +128 -128
- data/lib/commands.rb +33 -28
- data/lib/commit.rb +14 -14
- data/lib/dev_commands.rb +20 -14
- data/lib/doc.rb +8 -8
- data/lib/gemspec.rb +35 -35
- data/lib/git.rb +8 -8
- data/lib/hash.rb +20 -20
- data/lib/msbuild.rb +27 -0
- data/lib/publish.rb +6 -6
- data/lib/pull.rb +9 -0
- data/lib/push.rb +7 -7
- data/lib/setup.rb +8 -8
- data/lib/test.rb +4 -4
- data/lib/text.rb +14 -14
- data/lib/update.rb +5 -0
- data/spec/command_spec.rb +109 -109
- data/spec/commands_spec.rb +14 -6
- data/spec/gem-example/rakefile.rb +5 -0
- data/spec/text_spec.rb +11 -11
- metadata +55 -29
- checksums.yaml +0 -7
data/lib/commands.rb
CHANGED
@@ -1,29 +1,34 @@
|
|
1
|
-
require_relative('hash.rb')
|
2
|
-
require_relative('
|
3
|
-
require_relative('
|
4
|
-
require_relative('
|
5
|
-
require_relative('
|
6
|
-
require_relative('
|
7
|
-
require_relative('
|
8
|
-
require_relative('
|
9
|
-
require_relative('
|
10
|
-
require_relative('
|
11
|
-
require_relative('
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
self[:
|
20
|
-
self[:
|
21
|
-
self[:
|
22
|
-
self[:
|
23
|
-
self[:
|
24
|
-
self[:
|
25
|
-
self[:
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
require_relative('hash.rb')
|
2
|
+
require_relative('pull.rb')
|
3
|
+
require_relative('update.rb')
|
4
|
+
require_relative('setup.rb')
|
5
|
+
require_relative('build.rb')
|
6
|
+
require_relative('test.rb')
|
7
|
+
require_relative('publish.rb')
|
8
|
+
require_relative('doc.rb')
|
9
|
+
require_relative('clean.rb')
|
10
|
+
require_relative('clobber.rb')
|
11
|
+
require_relative('add.rb')
|
12
|
+
require_relative('commit.rb')
|
13
|
+
require_relative('push.rb')
|
14
|
+
|
15
|
+
class Commands < Hash
|
16
|
+
|
17
|
+
def initialize directory=Dir.pwd
|
18
|
+
Dir.chdir(directory) do
|
19
|
+
self[:pull]=Pull.new
|
20
|
+
self[:update]=Update.new
|
21
|
+
self[:setup]=Setup.new
|
22
|
+
self[:build]=Build.new
|
23
|
+
self[:test]=Test.new
|
24
|
+
self[:doc]=Doc.new
|
25
|
+
self[:clean]=Clean.new
|
26
|
+
self[:publish]=Publish.new
|
27
|
+
self[:clobber]=Clobber.new
|
28
|
+
self[:add]=Add.new
|
29
|
+
self[:commit]=Commit.new
|
30
|
+
self[:push]=Push.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
29
34
|
end
|
data/lib/commit.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
class Commit < Array
|
2
|
-
def update
|
3
|
-
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
4
|
-
if(!`git status`.include?('nothing to commit') &&
|
5
|
-
!`git status`.include?('untracked files present'))
|
6
|
-
if(File.exists?('commit.message') && File.read('commit.message').gsub(/\s+/,"").length >0)
|
7
|
-
add "git commit -a -v -m \"#{File.read('commit.message')}\""
|
8
|
-
else
|
9
|
-
add "git commit -m'all'"
|
10
|
-
end
|
11
|
-
add "<%FileUtils.rm('commit.message')%>" if File.exists?('commit.message')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
class Commit < Array
|
2
|
+
def update
|
3
|
+
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
4
|
+
if(!`git status`.include?('nothing to commit') &&
|
5
|
+
!`git status`.include?('untracked files present'))
|
6
|
+
if(File.exists?('commit.message') && File.read('commit.message').gsub(/\s+/,"").length >0)
|
7
|
+
add "git commit -a -v -m \"#{File.read('commit.message')}\""
|
8
|
+
else
|
9
|
+
add "git commit -m'all'"
|
10
|
+
end
|
11
|
+
add "<%FileUtils.rm('commit.message')%>" if File.exists?('commit.message')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
15
|
end
|
data/lib/dev_commands.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'rake/clean'
|
3
|
-
|
4
|
-
#CLEAN.include('.yardoc','log','tmp','*.gem','obj')
|
5
|
-
#CLEAN.include('**/*.{suo,sdf}')
|
6
|
-
CLOBBER.include('bin','doc')
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
require 'json'
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
#CLEAN.include('.yardoc','log','tmp','*.gem','obj')
|
5
|
+
#CLEAN.include('**/*.{suo,sdf}')
|
6
|
+
CLOBBER.include('bin','doc')
|
7
|
+
|
8
|
+
SOURCE=FileList.new('LICENSE','README','README.md',"Gemfile")
|
9
|
+
SOURCE.include('**/*.{gitignore,yml,gemspec,rb}')
|
10
|
+
SOURCE.include('**/*.{cs}')
|
11
|
+
SOURCE.include('**/*.{c,h}')
|
12
|
+
SOURCE.include('**/*.{cpp,hpp}')
|
13
|
+
|
14
|
+
|
15
|
+
require_relative('command.rb')
|
16
|
+
require_relative('commands.rb')
|
17
|
+
require_relative('text.rb')
|
18
|
+
require_relative('gemspec.rb')
|
19
|
+
require_relative('git.rb')
|
20
|
+
|
15
21
|
COMMANDS=Commands.new
|
data/lib/doc.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Doc < Array
|
2
|
-
def update
|
3
|
-
#cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
|
4
|
-
#cmd.execute
|
5
|
-
if(Command.exit_code('yard --version'))
|
6
|
-
add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
|
7
|
-
end
|
8
|
-
end
|
1
|
+
class Doc < Array
|
2
|
+
def update
|
3
|
+
#cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
|
4
|
+
#cmd.execute
|
5
|
+
if(Command.exit_code('yard --version'))
|
6
|
+
add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/gemspec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
class Gemspec
|
2
|
-
def self.update gemspec_file
|
3
|
-
Text.replace_in_file gemspec_file,
|
4
|
-
/('\d{4}-\d{2}-\d{2}')/,
|
5
|
-
"'#{Time.now.strftime('%Y-%m-%d')}'"
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.gemfile gemspec_file
|
9
|
-
spec=Gem::Specification.load(gemspec_file)
|
10
|
-
return "#{spec.name}-#{spec.version}.gem"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.version gemspec_file
|
14
|
-
spec=Gem::Specification.load(gemspec_file)
|
15
|
-
return spec.version.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.published_version gemspec_file
|
19
|
-
published_version=''
|
20
|
-
spec=Gem::Specification.load(gemspec_file)
|
21
|
-
begin
|
22
|
-
published_version = `gem list #{spec.name} -r`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
|
23
|
-
rescue
|
24
|
-
published_version=''
|
25
|
-
end
|
26
|
-
published_version
|
27
|
-
end
|
28
|
-
def self.published? gemspec_file
|
29
|
-
published_version(gemspec_file)==version(gemspec_file) ? true : false
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.normalize gemspec_file
|
33
|
-
spec=Gem::Specification.load(gemspec_file)
|
34
|
-
File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
|
35
|
-
end
|
1
|
+
class Gemspec
|
2
|
+
def self.update gemspec_file
|
3
|
+
Text.replace_in_file gemspec_file,
|
4
|
+
/('\d{4}-\d{2}-\d{2}')/,
|
5
|
+
"'#{Time.now.strftime('%Y-%m-%d')}'"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.gemfile gemspec_file
|
9
|
+
spec=Gem::Specification.load(gemspec_file)
|
10
|
+
return "#{spec.name}-#{spec.version}.gem"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.version gemspec_file
|
14
|
+
spec=Gem::Specification.load(gemspec_file)
|
15
|
+
return spec.version.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.published_version gemspec_file
|
19
|
+
published_version=''
|
20
|
+
spec=Gem::Specification.load(gemspec_file)
|
21
|
+
begin
|
22
|
+
published_version = `gem list #{spec.name} -r`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
|
23
|
+
rescue
|
24
|
+
published_version=''
|
25
|
+
end
|
26
|
+
published_version
|
27
|
+
end
|
28
|
+
def self.published? gemspec_file
|
29
|
+
published_version(gemspec_file)==version(gemspec_file) ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.normalize gemspec_file
|
33
|
+
spec=Gem::Specification.load(gemspec_file)
|
34
|
+
File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
|
35
|
+
end
|
36
36
|
end
|
data/lib/git.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Git
|
2
|
-
def self.branch
|
3
|
-
begin
|
4
|
-
`git branch`.scan(/\* ([.\w-]+)/)[0][0]
|
5
|
-
rescue
|
6
|
-
''
|
7
|
-
end
|
8
|
-
end
|
1
|
+
class Git
|
2
|
+
def self.branch
|
3
|
+
begin
|
4
|
+
`git branch`.scan(/\* ([.\w-]+)/)[0][0]
|
5
|
+
rescue
|
6
|
+
''
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/hash.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
class Hash
|
2
|
-
def execute
|
3
|
-
self.each{|k,v|
|
4
|
-
v.update if v.respond_to?(:update)
|
5
|
-
if(v.is_a?(Array) && v.length==0)
|
6
|
-
self.delete k
|
7
|
-
else
|
8
|
-
#puts "executing #{k}"
|
9
|
-
|
10
|
-
v.execute if v.respond_to?(:execute)
|
11
|
-
end
|
12
|
-
}
|
13
|
-
end
|
14
|
-
def to_html
|
15
|
-
[
|
16
|
-
'<div>',
|
17
|
-
map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
|
18
|
-
'</div>'
|
19
|
-
].join
|
20
|
-
end
|
1
|
+
class Hash
|
2
|
+
def execute
|
3
|
+
self.each{|k,v|
|
4
|
+
v.update if v.respond_to?(:update)
|
5
|
+
if(v.is_a?(Array) && v.length==0)
|
6
|
+
self.delete k
|
7
|
+
else
|
8
|
+
#puts "executing #{k}"
|
9
|
+
|
10
|
+
v.execute if v.respond_to?(:execute)
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
def to_html
|
15
|
+
[
|
16
|
+
'<div>',
|
17
|
+
map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
|
18
|
+
'</div>'
|
19
|
+
].join
|
20
|
+
end
|
21
21
|
end
|
data/lib/msbuild.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class MSBuild
|
2
|
+
def self.get_vs_version(sln_filename)
|
3
|
+
sln_text=File.read(sln_filename,:encoding=>'UTF-8')
|
4
|
+
return :vs9 if sln_text.include?('Format Version 10.00')
|
5
|
+
return :vs12
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_configurations(sln_filename)
|
9
|
+
configs=Array.new
|
10
|
+
sln_text=File.read(sln_filename,:encoding=>'UTF-8')
|
11
|
+
sln_text.scan( /= ([\w]+)\|/ ).each{|m|
|
12
|
+
c=m.first.to_s
|
13
|
+
configs << c if !configs.include?(c)
|
14
|
+
}
|
15
|
+
return configs
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_platforms(sln_filename)
|
19
|
+
platforms=Array.new
|
20
|
+
sln_text=File.read(sln_filename,:encoding=>"UTF-8")
|
21
|
+
sln_text.scan( /= [\w]+\|([\w ]+)/ ).each{|m|
|
22
|
+
p=m.first.to_s
|
23
|
+
platforms << p if !platforms.include?(p)
|
24
|
+
}
|
25
|
+
return platforms
|
26
|
+
end
|
27
|
+
end
|
data/lib/publish.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class Publish < Array
|
2
|
-
def update
|
3
|
-
Dir.glob('*.gemspec').each{|gemspec_file|
|
4
|
-
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
5
|
-
}
|
6
|
-
end
|
1
|
+
class Publish < Array
|
2
|
+
def update
|
3
|
+
Dir.glob('*.gemspec').each{|gemspec_file|
|
4
|
+
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
5
|
+
}
|
6
|
+
end
|
7
7
|
end
|
data/lib/pull.rb
ADDED
data/lib/push.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class Push < Array
|
2
|
-
def update
|
3
|
-
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
4
|
-
add 'git config --global push.default simple'
|
5
|
-
self << 'git push' if Git.branch != 'develop'
|
6
|
-
end
|
7
|
-
end
|
1
|
+
class Push < Array
|
2
|
+
def update
|
3
|
+
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
4
|
+
add 'git config --global push.default simple'
|
5
|
+
self << 'git push' if Git.branch != 'develop'
|
6
|
+
end
|
7
|
+
end
|
8
8
|
end
|
data/lib/setup.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Setup < Array
|
2
|
-
def update
|
3
|
-
add 'bundle install' if(File.exists?('Gemfile'))
|
4
|
-
|
5
|
-
Dir.glob('*.gemspec').each{|gemspec_file|
|
6
|
-
add "<%Gemspec.update('#{gemspec_file}')%>"
|
7
|
-
}
|
8
|
-
end
|
1
|
+
class Setup < Array
|
2
|
+
def update
|
3
|
+
add 'bundle install' if(File.exists?('Gemfile'))
|
4
|
+
|
5
|
+
Dir.glob('*.gemspec').each{|gemspec_file|
|
6
|
+
add "<%Gemspec.update('#{gemspec_file}')%>"
|
7
|
+
}
|
8
|
+
end
|
9
9
|
end
|
data/lib/test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Test < Array
|
2
|
-
def update
|
3
|
-
add 'rspec' if File.exists?('spec')
|
4
|
-
end
|
1
|
+
class Test < Array
|
2
|
+
def update
|
3
|
+
add 'rspec' if File.exists?('spec')
|
4
|
+
end
|
5
5
|
end
|
data/lib/text.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
class Text
|
2
|
-
def self.replace_in_glob(glob,search,replace)
|
3
|
-
Dir.glob(glob).each{ |f| replace_text_in_file(f,search,replace) }
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.replace_in_file(filename,search,replace)
|
7
|
-
text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
|
8
|
-
#File.read(f,:encoding=>'UTF-8')
|
9
|
-
text2 = text1.gsub(search) { |str| str=replace }
|
10
|
-
unless text1==text2
|
11
|
-
File.open(filename,"w") { |f| f.puts text2 }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
1
|
+
class Text
|
2
|
+
def self.replace_in_glob(glob,search,replace)
|
3
|
+
Dir.glob(glob).each{ |f| replace_text_in_file(f,search,replace) }
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.replace_in_file(filename,search,replace)
|
7
|
+
text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
|
8
|
+
#File.read(f,:encoding=>'UTF-8')
|
9
|
+
text2 = text1.gsub(search) { |str| str=replace }
|
10
|
+
unless text1==text2
|
11
|
+
File.open(filename,"w") { |f| f.puts text2 }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
15
|
end
|
data/lib/update.rb
ADDED
data/spec/command_spec.rb
CHANGED
@@ -1,110 +1,110 @@
|
|
1
|
-
require_relative '../lib/command.rb'
|
2
|
-
require 'json'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
describe Command do
|
6
|
-
it "should be able to execute ruby --version command" do
|
7
|
-
cmd=Command.new("ruby --version")
|
8
|
-
# Timeout
|
9
|
-
expect(cmd[:timeout]).to eq(0)
|
10
|
-
cmd[:timeout]=3000
|
11
|
-
expect(cmd[:timeout]).to eq(3000)
|
12
|
-
|
13
|
-
# Directory
|
14
|
-
expect(cmd[:directory]).to eq("")
|
15
|
-
cmd[:directory] = File.dirname(__FILE__)
|
16
|
-
expect(cmd[:directory]).to eq(File.dirname(__FILE__))
|
17
|
-
|
18
|
-
# ExitCode
|
19
|
-
expect(cmd[:exit_code]).to eq(0)
|
20
|
-
cmd[:exit_code] = 1
|
21
|
-
expect(cmd[:exit_code]).to eq(1)
|
22
|
-
|
23
|
-
# Input
|
24
|
-
expect(cmd[:input]).to eq("ruby --version")
|
25
|
-
cmd2 = Command.new('')
|
26
|
-
expect(cmd2[:input]).to eq('')
|
27
|
-
|
28
|
-
# Output
|
29
|
-
expect(cmd[:output]).to eq('')
|
30
|
-
cmd[:output]='test'
|
31
|
-
expect(cmd[:output]).to eq('test')
|
32
|
-
|
33
|
-
# Error
|
34
|
-
expect(cmd[:error]).to eq('')
|
35
|
-
cmd[:error]='error_test'
|
36
|
-
expect(cmd[:error]).to eq('error_test')
|
37
|
-
|
38
|
-
# Machine
|
39
|
-
expect(cmd[:machine]).to eq('')
|
40
|
-
cmd[:machine]='machine_test'
|
41
|
-
expect(cmd[:machine]).to eq('machine_test')
|
42
|
-
|
43
|
-
# User
|
44
|
-
expect(cmd[:user]).to eq('')
|
45
|
-
cmd[:user]='user_test'
|
46
|
-
expect(cmd[:user]).to eq('user_test')
|
47
|
-
|
48
|
-
# StartTime
|
49
|
-
expect(cmd[:start_time]).to eq(nil)
|
50
|
-
cmd[:start_time]=Time.now
|
51
|
-
expect(cmd[:start_time]).not_to eq(nil)
|
52
|
-
|
53
|
-
# EndTime
|
54
|
-
expect(cmd[:end_time]).to eq(nil)
|
55
|
-
cmd[:end_time]=Time.now
|
56
|
-
expect(cmd[:end_time]).not_to eq(nil)
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should be able to write to/load from JSON" do
|
61
|
-
cmd=Command.new("ruby --version")
|
62
|
-
expect(cmd[:timeout]).to eq(0)
|
63
|
-
expect(cmd[:input]).to eq("ruby --version")
|
64
|
-
cmd2=Command.new(JSON.parse(cmd.to_json))
|
65
|
-
expect(cmd2[:timeout]).to eq(0)
|
66
|
-
expect(cmd2[:input]).to eq("ruby --version")
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should be able to execute rake command in specific directory" do
|
70
|
-
dir="#{File.dirname(__FILE__)}/tmp/rake_test"
|
71
|
-
FileUtils.mkdir_p(dir) if(!File.exists?(dir))
|
72
|
-
File.open("#{dir}/rakefile.rb","w") { |f|
|
73
|
-
f.puts "task :default do"
|
74
|
-
f.puts " puts 'rake_test'"
|
75
|
-
f.puts "end"
|
76
|
-
}
|
77
|
-
cmd=Command.new("rake")
|
78
|
-
cmd[:directory]=dir
|
79
|
-
cmd.execute
|
80
|
-
FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
|
81
|
-
expect(cmd[:output].include?('rake_test')).to eq(true)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should be able to execute an array of commands" do
|
85
|
-
help=['git --help','rake --help','ruby --help']
|
86
|
-
help.execute
|
87
|
-
File.open('help.html','w'){|f|f.write(help.to_html)}
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should be able to execute a hash with arrays or commands" do
|
91
|
-
commands=Hash.new
|
92
|
-
commands[:help]=['git --help','rake --help','ruby --help']
|
93
|
-
commands[:version]=['git --version','rake --version','ruby --version']
|
94
|
-
commands.execute
|
95
|
-
File.open('commands.html','w'){|f|f.write(commands.to_html)}
|
96
|
-
end
|
97
|
-
|
98
|
-
it "hsould be able to get the output" do
|
99
|
-
expect(Command.output('git --version').include?('git version')).to eq(true)
|
100
|
-
expect(Command.output('bogus --version').include?('bogus version')).to eq(false)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should be able to get the exit_code" do
|
104
|
-
expect(Command.exit_code('rake --version')).to eq(0)
|
105
|
-
expect(Command.exit_code('bogus --version')).not_to eq(0)
|
106
|
-
end
|
107
|
-
#it "should fail this test" do
|
108
|
-
# expect(false).to eq(true)
|
109
|
-
#end
|
1
|
+
require_relative '../lib/command.rb'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe Command do
|
6
|
+
it "should be able to execute ruby --version command" do
|
7
|
+
cmd=Command.new("ruby --version")
|
8
|
+
# Timeout
|
9
|
+
expect(cmd[:timeout]).to eq(0)
|
10
|
+
cmd[:timeout]=3000
|
11
|
+
expect(cmd[:timeout]).to eq(3000)
|
12
|
+
|
13
|
+
# Directory
|
14
|
+
expect(cmd[:directory]).to eq("")
|
15
|
+
cmd[:directory] = File.dirname(__FILE__)
|
16
|
+
expect(cmd[:directory]).to eq(File.dirname(__FILE__))
|
17
|
+
|
18
|
+
# ExitCode
|
19
|
+
expect(cmd[:exit_code]).to eq(0)
|
20
|
+
cmd[:exit_code] = 1
|
21
|
+
expect(cmd[:exit_code]).to eq(1)
|
22
|
+
|
23
|
+
# Input
|
24
|
+
expect(cmd[:input]).to eq("ruby --version")
|
25
|
+
cmd2 = Command.new('')
|
26
|
+
expect(cmd2[:input]).to eq('')
|
27
|
+
|
28
|
+
# Output
|
29
|
+
expect(cmd[:output]).to eq('')
|
30
|
+
cmd[:output]='test'
|
31
|
+
expect(cmd[:output]).to eq('test')
|
32
|
+
|
33
|
+
# Error
|
34
|
+
expect(cmd[:error]).to eq('')
|
35
|
+
cmd[:error]='error_test'
|
36
|
+
expect(cmd[:error]).to eq('error_test')
|
37
|
+
|
38
|
+
# Machine
|
39
|
+
expect(cmd[:machine]).to eq('')
|
40
|
+
cmd[:machine]='machine_test'
|
41
|
+
expect(cmd[:machine]).to eq('machine_test')
|
42
|
+
|
43
|
+
# User
|
44
|
+
expect(cmd[:user]).to eq('')
|
45
|
+
cmd[:user]='user_test'
|
46
|
+
expect(cmd[:user]).to eq('user_test')
|
47
|
+
|
48
|
+
# StartTime
|
49
|
+
expect(cmd[:start_time]).to eq(nil)
|
50
|
+
cmd[:start_time]=Time.now
|
51
|
+
expect(cmd[:start_time]).not_to eq(nil)
|
52
|
+
|
53
|
+
# EndTime
|
54
|
+
expect(cmd[:end_time]).to eq(nil)
|
55
|
+
cmd[:end_time]=Time.now
|
56
|
+
expect(cmd[:end_time]).not_to eq(nil)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to write to/load from JSON" do
|
61
|
+
cmd=Command.new("ruby --version")
|
62
|
+
expect(cmd[:timeout]).to eq(0)
|
63
|
+
expect(cmd[:input]).to eq("ruby --version")
|
64
|
+
cmd2=Command.new(JSON.parse(cmd.to_json))
|
65
|
+
expect(cmd2[:timeout]).to eq(0)
|
66
|
+
expect(cmd2[:input]).to eq("ruby --version")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be able to execute rake command in specific directory" do
|
70
|
+
dir="#{File.dirname(__FILE__)}/tmp/rake_test"
|
71
|
+
FileUtils.mkdir_p(dir) if(!File.exists?(dir))
|
72
|
+
File.open("#{dir}/rakefile.rb","w") { |f|
|
73
|
+
f.puts "task :default do"
|
74
|
+
f.puts " puts 'rake_test'"
|
75
|
+
f.puts "end"
|
76
|
+
}
|
77
|
+
cmd=Command.new("rake")
|
78
|
+
cmd[:directory]=dir
|
79
|
+
cmd.execute
|
80
|
+
FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
|
81
|
+
expect(cmd[:output].include?('rake_test')).to eq(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be able to execute an array of commands" do
|
85
|
+
help=['git --help','rake --help','ruby --help']
|
86
|
+
help.execute
|
87
|
+
File.open('help.html','w'){|f|f.write(help.to_html)}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should be able to execute a hash with arrays or commands" do
|
91
|
+
commands=Hash.new
|
92
|
+
commands[:help]=['git --help','rake --help','ruby --help']
|
93
|
+
commands[:version]=['git --version','rake --version','ruby --version']
|
94
|
+
commands.execute
|
95
|
+
File.open('commands.html','w'){|f|f.write(commands.to_html)}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "hsould be able to get the output" do
|
99
|
+
expect(Command.output('git --version').include?('git version')).to eq(true)
|
100
|
+
expect(Command.output('bogus --version').include?('bogus version')).to eq(false)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be able to get the exit_code" do
|
104
|
+
expect(Command.exit_code('rake --version')).to eq(0)
|
105
|
+
expect(Command.exit_code('bogus --version')).not_to eq(0)
|
106
|
+
end
|
107
|
+
#it "should fail this test" do
|
108
|
+
# expect(false).to eq(true)
|
109
|
+
#end
|
110
110
|
end
|