gun_test 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7646869c28a47bf4ac45c3db15aeb7931b3d0c
4
- data.tar.gz: 1699e9a9270b1e942ab163ab5054b3e625fbfa01
3
+ metadata.gz: 9a14ffa8072e5c462fa5d6616b194a969709775a
4
+ data.tar.gz: c629b346f58435df2af36d31b8809298cf140160
5
5
  SHA512:
6
- metadata.gz: d77c57d4b3d64fdcc29be5bfa8f19bf4cd21f974dab38c9d5bf7150b0ac8dada52fb841fcbd9fc126858b93db82a610ab93a01b3649733575ae16b092abd66ae
7
- data.tar.gz: 0871af07db22bd527f47738102fa70f9b2d704f9cc7d53ba1068fa250709bd514285f4291684764c93bc09bf34caeb92ff5a49e3bf2dfd17e6419b9a033e463d
6
+ metadata.gz: 3982804ae0f96ab297274bd359290a069303372477c29e157d1805953f8501a17f5f4a5feaa45c4a991ca0a73f8eb7c30de38fc9a56b2c6741fcc8677e52ea30
7
+ data.tar.gz: 39b2e72bc46a84c8f978976d140f11bb7188eacd8e32f1c3b4ba908c0a07c72f57b499daf4eff73d13bf2413b0d8b58622b1a4acf2df1be89836d094f8ba9c59
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.out
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
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
@@ -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,12 @@
1
+ require 'gun_test/shell/task'
2
+
3
+ module GunTest
4
+ module Shell
5
+ def task(description, &block)
6
+ status = Task.new(description).perform(&block)
7
+ puts "" # Task separator
8
+
9
+ status
10
+ end
11
+ end
12
+ 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
@@ -1,3 +1,3 @@
1
1
  module GunTest
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gun_test.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "gun_test/version"
1
+ require 'colorize'
2
+ require 'gun_test/version'
3
+ require 'gun_test/gun'
2
4
 
3
5
  module GunTest
4
- # Your code goes here...
6
+ def self.gallery(gun, &block)
7
+ Gun.new(gun).instance_eval(&block)
8
+ end
5
9
  end
@@ -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
@@ -0,0 +1,14 @@
1
+ #include <iostream>
2
+ #include <string>
3
+
4
+ using namespace std;
5
+
6
+ int main()
7
+ {
8
+ string s;
9
+
10
+ while(cin >> s)
11
+ cout << s;
12
+
13
+ return 0;
14
+ }
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.1
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-28 00:00:00.000000000 Z
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
- description: Simple DSL to test the output of any executable.
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