gun_test 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/gun_test.gemspec +4 -1
- data/lib/gun_test/gun.rb +43 -0
- data/lib/gun_test/shell/task.rb +30 -0
- data/lib/gun_test/shell.rb +12 -0
- data/lib/gun_test/shot.rb +33 -0
- data/lib/gun_test/version.rb +1 -1
- data/lib/gun_test.rb +6 -2
- data/test/gun_test/test_gun.rb +24 -0
- data/test/guns/simple.cc +14 -0
- metadata +41 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a14ffa8072e5c462fa5d6616b194a969709775a
|
4
|
+
data.tar.gz: c629b346f58435df2af36d31b8809298cf140160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3982804ae0f96ab297274bd359290a069303372477c29e157d1805953f8501a17f5f4a5feaa45c4a991ca0a73f8eb7c30de38fc9a56b2c6741fcc8677e52ea30
|
7
|
+
data.tar.gz: 39b2e72bc46a84c8f978976d140f11bb7188eacd8e32f1c3b4ba908c0a07c72f57b499daf4eff73d13bf2413b0d8b58622b1a4acf2df1be89836d094f8ba9c59
|
data/.gitignore
CHANGED
data/gun_test.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = GunTest::VERSION
|
9
9
|
spec.authors = ["Héctor"]
|
10
10
|
spec.email = ["hector0193@gmail.com"]
|
11
|
-
spec.description = %q{Simple DSL to test the output of any executable.}
|
11
|
+
spec.description = %q{Simple DSL to test the output of any executable. Test the accuracy of your gun!}
|
12
12
|
spec.summary = %q{Simple DSL to test the output of any executable.}
|
13
13
|
spec.homepage = "https://github.com/hecrj/gun_test"
|
14
14
|
spec.license = "MIT"
|
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "test-unit"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "colorize"
|
23
26
|
end
|
data/lib/gun_test/gun.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'gun_test/shell'
|
2
|
+
require 'gun_test/shot'
|
3
|
+
|
4
|
+
module GunTest
|
5
|
+
class Gun
|
6
|
+
include Shell
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload(ammo)
|
14
|
+
# Only C++ supported by now!
|
15
|
+
task "Reloading gun..." do
|
16
|
+
say_status "Reloading".blue
|
17
|
+
reloaded = system("g++ #{ammo} -O2 -o #{name} 2> /dev/null")
|
18
|
+
|
19
|
+
say_status reloaded ? "Done".green : "Failed".red
|
20
|
+
|
21
|
+
reloaded
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def shoot(target_number = 50, &block)
|
26
|
+
target_number.times do |i|
|
27
|
+
break false unless task "Shot #{i+1}" do
|
28
|
+
say_status "Reloading bullet...".blue
|
29
|
+
|
30
|
+
shot = Shot.new
|
31
|
+
shot.instance_exec(i, &block)
|
32
|
+
|
33
|
+
say_status "Shooting!".blue
|
34
|
+
headshot = shot.bang!(name)
|
35
|
+
|
36
|
+
say_status headshot ? "Headshot!".green : "Failed".red
|
37
|
+
|
38
|
+
headshot
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GunTest
|
2
|
+
module Shell
|
3
|
+
class Task
|
4
|
+
PADDING = 5
|
5
|
+
|
6
|
+
def initialize(description)
|
7
|
+
@description = description
|
8
|
+
@status_length = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform(&block)
|
12
|
+
@self_before_instance_eval = eval "self", block.binding
|
13
|
+
instance_eval &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args, &block)
|
17
|
+
@self_before_instance_eval.send method, *args, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def say_status(status)
|
21
|
+
print "\r" unless @status_length == 0
|
22
|
+
|
23
|
+
status = " " * PADDING + @description.ljust(PADDING * 5) + status
|
24
|
+
print status.ljust(@status_length)
|
25
|
+
|
26
|
+
@status_length = status.length
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'gun_test/shell'
|
2
|
+
|
3
|
+
module GunTest
|
4
|
+
class Shot
|
5
|
+
include Shell
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@bullet = nil
|
9
|
+
@target = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def bullet(bullet = nil)
|
13
|
+
@bullet = bullet
|
14
|
+
@bullet ||= yield if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def target(target = nil)
|
18
|
+
@target = target
|
19
|
+
@target ||= yield if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def bang!(gun)
|
23
|
+
cmd = (gun[0] == '/' ? '' : './') + gun
|
24
|
+
|
25
|
+
IO.popen(cmd, "r+") do |io|
|
26
|
+
io.puts @bullet
|
27
|
+
io.close_write
|
28
|
+
|
29
|
+
@target == io.gets(nil)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/gun_test/version.rb
CHANGED
data/lib/gun_test.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'gun_test'
|
3
|
+
|
4
|
+
class TestGun < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@dir = File.dirname(__FILE__) + "/../guns"
|
8
|
+
@gun = GunTest::Gun.new("#{@dir}/simple.out")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_reload
|
12
|
+
assert @gun.reload("#{@dir}/simple.cc")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_shoot
|
16
|
+
all_headshots = @gun.shoot do |i|
|
17
|
+
bullet "a" * (i+1)
|
18
|
+
target "a" * (i+1)
|
19
|
+
end
|
20
|
+
|
21
|
+
assert all_headshots
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test/guns/simple.cc
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gun_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Héctor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,36 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Simple DSL to test the output of any executable. Test the accuracy of
|
70
|
+
your gun!
|
42
71
|
email:
|
43
72
|
- hector0193@gmail.com
|
44
73
|
executables: []
|
@@ -52,7 +81,13 @@ files:
|
|
52
81
|
- Rakefile
|
53
82
|
- gun_test.gemspec
|
54
83
|
- lib/gun_test.rb
|
84
|
+
- lib/gun_test/gun.rb
|
85
|
+
- lib/gun_test/shell.rb
|
86
|
+
- lib/gun_test/shell/task.rb
|
87
|
+
- lib/gun_test/shot.rb
|
55
88
|
- lib/gun_test/version.rb
|
89
|
+
- test/gun_test/test_gun.rb
|
90
|
+
- test/guns/simple.cc
|
56
91
|
homepage: https://github.com/hecrj/gun_test
|
57
92
|
licenses:
|
58
93
|
- MIT
|
@@ -77,4 +112,6 @@ rubygems_version: 2.0.3
|
|
77
112
|
signing_key:
|
78
113
|
specification_version: 4
|
79
114
|
summary: Simple DSL to test the output of any executable.
|
80
|
-
test_files:
|
115
|
+
test_files:
|
116
|
+
- test/gun_test/test_gun.rb
|
117
|
+
- test/guns/simple.cc
|