test_case_generator 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bd99d30932e8775eac157f3eb7142f12dd11c4a
4
+ data.tar.gz: d0b84e08569ca7b155eeed76d25d12e1f5454d41
5
+ SHA512:
6
+ metadata.gz: 7c5ca5df5345806f5dc4698fa7a25ba6707d4287e7704c7bff70aa32bf2c273b4cfa8ec933f6a66d1305a782916e3d061c384bd31bb65e885abbaf0594a59065
7
+ data.tar.gz: 6d07720070479490331372e3e5904efff1b55a7766ffb09999fa57d8143a0e7c4e8b84295134beaf0e1c7ff310da84dd4891f35a861ec2e0db62cd8a9ca78c08
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ vendor/bundle/
12
+ .idea/
13
+ *.pyc
14
+ *.bak
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test_case_generator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 kaoru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # TestCaseGenerator
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/test_case_generator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'test_case_generator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install test_case_generator
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec test_case_generator` to use the gem in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ym-kaoru/test_case_generator.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'test_case_generator'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'test_case_generator'
5
+
6
+ TestCaseGenerator::CLI.start
@@ -0,0 +1,24 @@
1
+ before { |items|
2
+ items << :prepare_success
3
+ }
4
+
5
+ choice { |items|
6
+ items << [:start, :stop]
7
+ items << [:start, :resume, :pause, :stop]
8
+ }
9
+
10
+ after { |items|
11
+ items << :should_be_not_error
12
+ }
13
+
14
+ concat {
15
+ choice { |items|
16
+ items << [:A1, :A2]
17
+ items << [:B1, :B2]
18
+ }
19
+
20
+ choice { |items|
21
+ items << [:C1, :C2]
22
+ items << [:D1, :D2]
23
+ }
24
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test_case_generator'
4
+ TestCaseGenerator::CLI.start
@@ -0,0 +1,5 @@
1
+ require 'test_case_generator/version'
2
+ require 'test_case_generator/cli'
3
+
4
+ module TestCaseGenerator
5
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+
3
+ require 'thor'
4
+ require 'test_case_generator/dsl_context'
5
+ require 'test_case_generator/generator_objective_c'
6
+
7
+ module TestCaseGenerator
8
+ class CLI < Thor
9
+ desc 'Injects test-cases', 'Injects test-cases into source file '
10
+ def inject(testcase_fn, source_fn)
11
+ puts "Injects #{testcase_fn} into #{source_fn}"
12
+
13
+ loader = TestCaseGenerator::DSLContextLoader.new
14
+ ctx = loader.load testcase_fn
15
+ gen = TestCaseGenerator::GeneratorObjectiveC.new
16
+ gen.write_header ctx, File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn)) + 'Generated.h')
17
+ gen.write_source ctx, source_fn
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,108 @@
1
+ require 'test_case_generator/utils'
2
+
3
+ module TestCaseGenerator
4
+ class DSLContext
5
+ attr_reader :children
6
+ attr_reader :labels
7
+
8
+ def initialize
9
+ @patterns = []
10
+ @before = []
11
+ @after = []
12
+ @children = []
13
+ @labels = []
14
+ end
15
+
16
+ def <<(events)
17
+ if events.is_a?(String) || events.is_a?(Symbol)
18
+ @patterns << [events]
19
+ @labels << events unless @labels.include? events
20
+ else
21
+ @patterns << events
22
+ events.each do |label|
23
+ @labels << label unless @labels.include? label
24
+ end
25
+ end
26
+ end
27
+
28
+ def def_labels
29
+ yield @labels
30
+ end
31
+
32
+ def before
33
+ yield @before
34
+ end
35
+
36
+ def after
37
+ yield @after
38
+ end
39
+
40
+ def pattern
41
+ child_context = DSLContext.new
42
+ yield child_context
43
+ @children << child_context
44
+
45
+ child_context.raw_each do |ptn|
46
+ @patterns << ptn
47
+ ptn.each do |label|
48
+ @labels << label unless @labels.include? label
49
+ end
50
+ end
51
+ end
52
+ alias_method :choice, :pattern
53
+
54
+ def concat(&block)
55
+ child_context = DSLContext.new
56
+ child_context.instance_eval &block
57
+
58
+ first = true
59
+ tmp = []
60
+ child_context.children.each do |ctx|
61
+ tmp2 = []
62
+ ctx.raw_each do |ptn|
63
+ if first
64
+ tmp2 << ptn
65
+ else
66
+ tmp.each do |x|
67
+ tmp2 << x + ptn
68
+ end
69
+ end
70
+ end
71
+
72
+ tmp = tmp2
73
+ first = false
74
+ end
75
+
76
+ tmp.each do |x|
77
+ @patterns << x
78
+ x.each do |label|
79
+ @labels << label unless @labels.include? label
80
+ end
81
+ end
82
+ end
83
+ alias_method :seq, :concat
84
+
85
+ def raw_each
86
+ @patterns.each { |ptn| yield @before + ptn + @after }
87
+ end
88
+
89
+ def each
90
+ raw_each do |raw_ptn|
91
+ yield raw_ptn.map { |p|
92
+ # p.to_s.split('_').inject([]) { |buffer, e|
93
+ # buffer << (buffer.empty? ? e : e.capitalize)
94
+ # }.join
95
+ TestCaseGenerator::Utils.make_method_name p
96
+ }
97
+ end
98
+ end
99
+ end
100
+
101
+ class DSLContextLoader
102
+ def load(filename)
103
+ ctx = DSLContext.new
104
+ ctx.instance_eval(File.read(filename), filename)
105
+ ctx
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_case_generator/dsl_context'
2
+
3
+ module TestCaseGenerator
4
+ class IndentedWriter
5
+ def initialize(out)
6
+ @out = out
7
+ @indent = []
8
+ @current_indent = ''
9
+ end
10
+
11
+ def puts(line)
12
+ @out.puts @current_indent + line
13
+ end
14
+
15
+ def blank
16
+ @out.puts
17
+ end
18
+
19
+ def indent(txt)
20
+ @indent.push @current_indent
21
+ @current_indent += txt
22
+ end
23
+
24
+ def unindent
25
+ @current_indent = @indent.pop
26
+ end
27
+
28
+ def block_indent(txt)
29
+ indent txt
30
+ yield
31
+ unindent
32
+ end
33
+ end
34
+
35
+ class GeneratorObjectiveC
36
+ def write_header(dsl_context, header_fn)
37
+ protocol_name = File.basename(header_fn, File.extname(header_fn))
38
+ tmp_fn = header_fn + '.tmp'
39
+ File.open(tmp_fn, 'w') do |f|
40
+ writer = IndentedWriter.new f
41
+
42
+ writer.puts '#import <Foundation/Foundation.h>'
43
+ writer.blank
44
+ writer.puts "@protocol #{protocol_name} <NSObject>"
45
+
46
+ dsl_context.labels.each do |label|
47
+ method_name = label
48
+ writer.puts "- (void)#{method_name};"
49
+ end
50
+
51
+ writer.puts '@end'
52
+ end
53
+
54
+ FileUtils.move tmp_fn, header_fn
55
+ end
56
+
57
+ def write_source(dsl_context, source_fn)
58
+ tmp_fn = source_fn + '.tmp'
59
+ source = File.open(source_fn).read
60
+ File.open(tmp_fn, 'w') do |f|
61
+ source.each_line do |line|
62
+ f.puts line
63
+ break if line =~ /^\s*\/\/\s*%%\s*$/
64
+ end
65
+
66
+ writer = IndentedWriter.new f
67
+
68
+ dsl_context.each do |pattern|
69
+ method_name = pattern.join '_'
70
+ writer.blank
71
+ writer.puts "- (void)test_#{method_name} {"
72
+
73
+ pattern.each do |ptn|
74
+ writer.block_indent ' ' do
75
+ writer.puts "[self #{ptn}];"
76
+ end
77
+ end
78
+
79
+ writer.puts '}'
80
+ end
81
+
82
+ writer.blank
83
+ writer.puts '@end'
84
+ end
85
+
86
+ FileUtils.move tmp_fn, source_fn
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,9 @@
1
+ module TestCaseGenerator
2
+ class Utils
3
+ def self.make_method_name(label)
4
+ label.to_s.split('_').inject([]) do |buffer, e|
5
+ buffer << (buffer.empty? ? e : e.capitalize)
6
+ end.join
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TestCaseGenerator
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test_case_generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'test_case_generator'
8
+ spec.version = TestCaseGenerator::VERSION
9
+ spec.authors = ['Kaoru Yanase']
10
+ spec.email = ['kaoru@yumemi.co.jp']
11
+
12
+ spec.summary = 'Generates test-cases for Objective-C.'
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/ym-kaoru/test_case_generator'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'thor'
31
+ spec.add_development_dependency 'bundler', '~> 1.10'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'rubocop'
35
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_case_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kaoru Yanase
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - kaoru@yumemi.co.jp
86
+ executables:
87
+ - test_case_generator
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - bin/test_case_generator
101
+ - example/demo.testcase
102
+ - exe/test_case_generator
103
+ - lib/test_case_generator.rb
104
+ - lib/test_case_generator/cli.rb
105
+ - lib/test_case_generator/dsl_context.rb
106
+ - lib/test_case_generator/generator_objective_c.rb
107
+ - lib/test_case_generator/utils.rb
108
+ - lib/test_case_generator/version.rb
109
+ - test_case_generator.gemspec
110
+ homepage: https://github.com/ym-kaoru/test_case_generator
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ allowed_push_host: https://rubygems.org
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Generates test-cases for Objective-C.
135
+ test_files: []