benhamill-gherkin 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +11 -0
  3. data/.mailmap +2 -0
  4. data/.rspec +1 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +7 -0
  7. data/History.txt +363 -0
  8. data/LICENSE +20 -0
  9. data/README.rdoc +149 -0
  10. data/Rakefile +19 -0
  11. data/VERSION +1 -0
  12. data/build_native_gems.sh +8 -0
  13. data/cucumber.yml +3 -0
  14. data/features/escaped_pipes.feature +8 -0
  15. data/features/feature_parser.feature +237 -0
  16. data/features/json_formatter.feature +377 -0
  17. data/features/json_parser.feature +318 -0
  18. data/features/native_lexer.feature +19 -0
  19. data/features/parser_with_native_lexer.feature +205 -0
  20. data/features/pretty_formatter.feature +15 -0
  21. data/features/step_definitions/eyeball_steps.rb +3 -0
  22. data/features/step_definitions/gherkin_steps.rb +29 -0
  23. data/features/step_definitions/json_formatter_steps.rb +28 -0
  24. data/features/step_definitions/json_parser_steps.rb +20 -0
  25. data/features/step_definitions/pretty_formatter_steps.rb +84 -0
  26. data/features/steps_parser.feature +46 -0
  27. data/features/support/env.rb +38 -0
  28. data/gherkin.gemspec +61 -0
  29. data/ikvm/.gitignore +3 -0
  30. data/java/.gitignore +5 -0
  31. data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
  32. data/java/src/main/resources/gherkin/.gitignore +1 -0
  33. data/js/lib/gherkin/lexer/i18n/ar.js +1094 -0
  34. data/js/lib/gherkin/lexer/i18n/bg.js +1308 -0
  35. data/js/lib/gherkin/lexer/i18n/ca.js +1236 -0
  36. data/js/lib/gherkin/lexer/i18n/cs.js +1090 -0
  37. data/js/lib/gherkin/lexer/i18n/cy_gb.js +958 -0
  38. data/js/lib/gherkin/lexer/i18n/da.js +974 -0
  39. data/js/lib/gherkin/lexer/i18n/de.js +1082 -0
  40. data/js/lib/gherkin/lexer/i18n/en.js +965 -0
  41. data/js/lib/gherkin/lexer/i18n/en_au.js +902 -0
  42. data/js/lib/gherkin/lexer/i18n/en_lol.js +859 -0
  43. data/js/lib/gherkin/lexer/i18n/en_pirate.js +1136 -0
  44. data/js/lib/gherkin/lexer/i18n/en_scouse.js +1289 -0
  45. data/js/lib/gherkin/lexer/i18n/en_tx.js +942 -0
  46. data/js/lib/gherkin/lexer/i18n/eo.js +916 -0
  47. data/js/lib/gherkin/lexer/i18n/es.js +1049 -0
  48. data/js/lib/gherkin/lexer/i18n/et.js +915 -0
  49. data/js/lib/gherkin/lexer/i18n/fi.js +894 -0
  50. data/js/lib/gherkin/lexer/i18n/fr.js +1116 -0
  51. data/js/lib/gherkin/lexer/i18n/he.js +1044 -0
  52. data/js/lib/gherkin/lexer/i18n/hr.js +994 -0
  53. data/js/lib/gherkin/lexer/i18n/hu.js +1043 -0
  54. data/js/lib/gherkin/lexer/i18n/id.js +884 -0
  55. data/js/lib/gherkin/lexer/i18n/it.js +1007 -0
  56. data/js/lib/gherkin/lexer/i18n/ja.js +1344 -0
  57. data/js/lib/gherkin/lexer/i18n/ko.js +1028 -0
  58. data/js/lib/gherkin/lexer/i18n/lt.js +972 -0
  59. data/js/lib/gherkin/lexer/i18n/lu.js +1057 -0
  60. data/js/lib/gherkin/lexer/i18n/lv.js +1092 -0
  61. data/js/lib/gherkin/lexer/i18n/nl.js +1036 -0
  62. data/js/lib/gherkin/lexer/i18n/no.js +986 -0
  63. data/js/lib/gherkin/lexer/i18n/pl.js +1140 -0
  64. data/js/lib/gherkin/lexer/i18n/pt.js +1000 -0
  65. data/js/lib/gherkin/lexer/i18n/ro.js +1089 -0
  66. data/js/lib/gherkin/lexer/i18n/ru.js +1560 -0
  67. data/js/lib/gherkin/lexer/i18n/sk.js +972 -0
  68. data/js/lib/gherkin/lexer/i18n/sr_cyrl.js +1728 -0
  69. data/js/lib/gherkin/lexer/i18n/sr_latn.js +1220 -0
  70. data/js/lib/gherkin/lexer/i18n/sv.js +997 -0
  71. data/js/lib/gherkin/lexer/i18n/tr.js +1014 -0
  72. data/js/lib/gherkin/lexer/i18n/uk.js +1572 -0
  73. data/js/lib/gherkin/lexer/i18n/uz.js +1302 -0
  74. data/js/lib/gherkin/lexer/i18n/vi.js +1124 -0
  75. data/js/lib/gherkin/lexer/i18n/zh_cn.js +902 -0
  76. data/js/lib/gherkin/lexer/i18n/zh_tw.js +940 -0
  77. data/lib/.gitignore +4 -0
  78. data/lib/gherkin.rb +2 -0
  79. data/lib/gherkin/c_lexer.rb +17 -0
  80. data/lib/gherkin/formatter/ansi_escapes.rb +95 -0
  81. data/lib/gherkin/formatter/argument.rb +16 -0
  82. data/lib/gherkin/formatter/escaping.rb +15 -0
  83. data/lib/gherkin/formatter/filter_formatter.rb +136 -0
  84. data/lib/gherkin/formatter/hashable.rb +19 -0
  85. data/lib/gherkin/formatter/json_formatter.rb +102 -0
  86. data/lib/gherkin/formatter/line_filter.rb +26 -0
  87. data/lib/gherkin/formatter/model.rb +236 -0
  88. data/lib/gherkin/formatter/pretty_formatter.rb +243 -0
  89. data/lib/gherkin/formatter/regexp_filter.rb +21 -0
  90. data/lib/gherkin/formatter/step_printer.rb +17 -0
  91. data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
  92. data/lib/gherkin/formatter/tag_filter.rb +19 -0
  93. data/lib/gherkin/i18n.rb +175 -0
  94. data/lib/gherkin/i18n.yml +588 -0
  95. data/lib/gherkin/json_parser.rb +137 -0
  96. data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
  97. data/lib/gherkin/listener/event.rb +45 -0
  98. data/lib/gherkin/listener/formatter_listener.rb +113 -0
  99. data/lib/gherkin/native.rb +7 -0
  100. data/lib/gherkin/native/ikvm.rb +55 -0
  101. data/lib/gherkin/native/java.rb +55 -0
  102. data/lib/gherkin/native/null.rb +9 -0
  103. data/lib/gherkin/parser/meta.txt +5 -0
  104. data/lib/gherkin/parser/parser.rb +164 -0
  105. data/lib/gherkin/parser/root.txt +11 -0
  106. data/lib/gherkin/parser/steps.txt +4 -0
  107. data/lib/gherkin/rb_lexer.rb +8 -0
  108. data/lib/gherkin/rb_lexer/.gitignore +1 -0
  109. data/lib/gherkin/rb_lexer/README.rdoc +8 -0
  110. data/lib/gherkin/rubify.rb +24 -0
  111. data/lib/gherkin/tag_expression.rb +62 -0
  112. data/lib/gherkin/version.rb +3 -0
  113. data/ragel/i18n/.gitignore +1 -0
  114. data/ragel/lexer.c.rl.erb +439 -0
  115. data/ragel/lexer.java.rl.erb +208 -0
  116. data/ragel/lexer.rb.rl.erb +167 -0
  117. data/ragel/lexer_common.rl.erb +50 -0
  118. data/spec/gherkin/c_lexer_spec.rb +21 -0
  119. data/spec/gherkin/fixtures/1.feature +8 -0
  120. data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
  121. data/spec/gherkin/fixtures/complex.feature +45 -0
  122. data/spec/gherkin/fixtures/complex.json +143 -0
  123. data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
  124. data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
  125. data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
  126. data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
  127. data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
  128. data/spec/gherkin/fixtures/i18n_no.feature +7 -0
  129. data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
  130. data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
  131. data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
  132. data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
  133. data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
  134. data/spec/gherkin/fixtures/with_bom.feature +3 -0
  135. data/spec/gherkin/formatter/ansi_escapes_spec.rb +19 -0
  136. data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
  137. data/spec/gherkin/formatter/model_spec.rb +28 -0
  138. data/spec/gherkin/formatter/pretty_formatter_spec.rb +158 -0
  139. data/spec/gherkin/formatter/spaces.feature +9 -0
  140. data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
  141. data/spec/gherkin/formatter/tabs.feature +9 -0
  142. data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
  143. data/spec/gherkin/i18n_spec.rb +152 -0
  144. data/spec/gherkin/java_lexer_spec.rb +20 -0
  145. data/spec/gherkin/java_libs.rb +20 -0
  146. data/spec/gherkin/json_parser_spec.rb +113 -0
  147. data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
  148. data/spec/gherkin/output_stream_string_io.rb +20 -0
  149. data/spec/gherkin/parser/parser_spec.rb +16 -0
  150. data/spec/gherkin/rb_lexer_spec.rb +19 -0
  151. data/spec/gherkin/sexp_recorder.rb +56 -0
  152. data/spec/gherkin/shared/lexer_group.rb +593 -0
  153. data/spec/gherkin/shared/py_string_group.rb +153 -0
  154. data/spec/gherkin/shared/row_group.rb +125 -0
  155. data/spec/gherkin/shared/tags_group.rb +54 -0
  156. data/spec/gherkin/tag_expression_spec.rb +137 -0
  157. data/spec/spec_helper.rb +69 -0
  158. data/tasks/bench.rake +184 -0
  159. data/tasks/bench/feature_builder.rb +49 -0
  160. data/tasks/bench/generated/.gitignore +1 -0
  161. data/tasks/bench/null_listener.rb +4 -0
  162. data/tasks/compile.rake +102 -0
  163. data/tasks/cucumber.rake +20 -0
  164. data/tasks/gems.rake +35 -0
  165. data/tasks/ikvm.rake +79 -0
  166. data/tasks/ragel_task.rb +70 -0
  167. data/tasks/rdoc.rake +9 -0
  168. data/tasks/release.rake +30 -0
  169. data/tasks/rspec.rake +8 -0
  170. metadata +609 -0
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'rspec'
6
+ require 'gherkin'
7
+ require 'stringio'
8
+ require 'gherkin/sexp_recorder'
9
+ require 'gherkin/output_stream_string_io'
10
+ require 'gherkin/java_libs'
11
+ require 'gherkin/shared/lexer_group'
12
+ require 'gherkin/shared/tags_group'
13
+ require 'gherkin/shared/py_string_group'
14
+ require 'gherkin/shared/row_group'
15
+
16
+ module GherkinSpecHelper
17
+ def scan_file(file)
18
+ @lexer.scan(fixture(file))
19
+ end
20
+
21
+ def fixture(file)
22
+ File.new(File.dirname(__FILE__) + "/gherkin/fixtures/" + file).read
23
+ end
24
+
25
+ def rubify_hash(hash)
26
+ if defined?(JRUBY_VERSION)
27
+ h = {}
28
+ hash.keySet.each{|key| h[key] = hash[key]}
29
+ h
30
+ else
31
+ hash
32
+ end
33
+ end
34
+ end
35
+
36
+ RSpec.configure do |c|
37
+ c.include(GherkinSpecHelper)
38
+ end
39
+
40
+ # Allows comparison of Java List with Ruby Array (rows)
41
+ RSpec::Matchers.define :r do |expected|
42
+ match do |row|
43
+ def row.inspect
44
+ "r " + self.map{|cell| cell}.inspect
45
+ end
46
+ row.map{|cell| cell}.should == expected
47
+ end
48
+ end
49
+
50
+ RSpec::Matchers.define :a do |expected|
51
+ match do |array|
52
+ def array.inspect
53
+ "a " + self.map{|e| e.to_sym}.inspect
54
+ end
55
+ array.map{|e| e.to_sym}.should == expected
56
+ end
57
+ end
58
+
59
+ RSpec::Matchers.define :sym do |expected|
60
+ match do |actual|
61
+ expected.to_s == actual.to_s
62
+ end
63
+ end
64
+
65
+ RSpec::Matchers.define :allow do |event|
66
+ match do |parser|
67
+ parser.expected.index(event)
68
+ end
69
+ end
data/tasks/bench.rake ADDED
@@ -0,0 +1,184 @@
1
+ %w{/../lib /bench}.each do |l|
2
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + l)
3
+ end
4
+
5
+ require 'benchmark'
6
+
7
+ GENERATED_FEATURES = File.expand_path(File.dirname(__FILE__) + "/bench/generated")
8
+
9
+ class RandomFeatureGenerator
10
+ def initialize(number)
11
+ require 'faker'
12
+ require 'feature_builder'
13
+
14
+ @number = number
15
+ end
16
+
17
+ def generate
18
+ @number.times do
19
+ name = catch_phrase
20
+ feature = FeatureBuilder.new(name) do |f|
21
+ num_scenarios = rand_in(1..10)
22
+ num_scenarios.times do
23
+ f.scenario(bs) do |steps|
24
+ num_steps = rand_in(3..10)
25
+ num_steps.times do
26
+ steps.step(sentence, self)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ write feature.to_s, name
32
+ end
33
+ end
34
+
35
+ def write(content, name)
36
+ File.open(GENERATED_FEATURES + "/#{name.downcase.gsub(/[\s\-\/]/, '_')}.feature", "w+") do |file|
37
+ file << content
38
+ end
39
+ end
40
+
41
+ def rand_in(range)
42
+ ary = range.to_a
43
+ ary[rand(ary.length - 1)]
44
+ end
45
+
46
+ def catch_phrase
47
+ Faker::Company.catch_phrase
48
+ end
49
+
50
+ def bs
51
+ Faker::Company.bs.capitalize
52
+ end
53
+
54
+ def sentence
55
+ Faker::Lorem.sentence
56
+ end
57
+
58
+ def table_cell
59
+ Faker::Lorem.words(rand(2)+1).join(" ")
60
+ end
61
+ end
62
+
63
+ class Benchmarker
64
+ def initialize
65
+ @features = Dir[GENERATED_FEATURES + "/**/*feature"]
66
+ end
67
+
68
+ def report(lexer)
69
+ Benchmark.bm do |x|
70
+ x.report("#{lexer}:") { send :"run_#{lexer}" }
71
+ end
72
+ end
73
+
74
+ def report_all
75
+ Benchmark.bmbm do |x|
76
+ x.report("native_gherkin:") { run_native_gherkin }
77
+ x.report("native_gherkin_no_parser:") { run_native_gherkin_no_parser }
78
+ x.report("rb_gherkin:") { run_rb_gherkin }
79
+ x.report("cucumber:") { run_cucumber }
80
+ x.report("tt:") { run_tt }
81
+ end
82
+ end
83
+
84
+ def run_cucumber
85
+ require 'cucumber'
86
+ require 'logger'
87
+ step_mother = Cucumber::StepMother.new
88
+ logger = Logger.new(STDOUT)
89
+ logger.level = Logger::INFO
90
+ step_mother.log = logger
91
+ step_mother.load_plain_text_features(@features)
92
+ end
93
+
94
+ def run_tt
95
+ require 'cucumber'
96
+ # Using Cucumber's Treetop lexer, but never calling #build to build the AST
97
+ lexer = Cucumber::Parser::NaturalLanguage.new(nil, 'en').parser
98
+ @features.each do |file|
99
+ source = IO.read(file)
100
+ parse_tree = lexer.parse(source)
101
+ if parse_tree.nil?
102
+ raise Cucumber::Parser::SyntaxError.new(lexer, file, 0)
103
+ end
104
+ end
105
+ end
106
+
107
+ def run_rb_gherkin
108
+ require 'gherkin'
109
+ require 'null_formatter'
110
+ parser = Gherkin::Parser::Parser.new(NullFormatter.new, true, "root", true)
111
+ @features.each do |feature|
112
+ parser.parse(File.read(feature), feature, 0)
113
+ end
114
+ end
115
+
116
+ def run_native_gherkin
117
+ require 'gherkin'
118
+ require 'null_listener'
119
+ parser = Gherkin::Parser::Parser.new(NullFormatter.new, true, "root", false)
120
+ @features.each do |feature|
121
+ parser.parse(File.read(feature), feature, 0)
122
+ end
123
+ end
124
+
125
+ def run_native_gherkin_no_parser
126
+ require 'gherkin'
127
+ require 'gherkin/lexer/i18n_lexer'
128
+ require 'null_listener'
129
+ lexer = Gherkin::Lexer::I18nLexer.new(NullListener.new, false)
130
+ @features.each do |feature|
131
+ lexer.scan(File.read(feature), feature, 0)
132
+ end
133
+ end
134
+ end
135
+
136
+ desc "Generate 500 random features and benchmark Cucumber, Treetop and Gherkin with them"
137
+ task :bench => ["bench:clean", "bench:gen"] do
138
+ benchmarker = Benchmarker.new
139
+ benchmarker.report_all
140
+ end
141
+
142
+ namespace :bench do
143
+ desc "Generate [number] features with random content, or 500 features if number is not provided"
144
+ task :gen, :number do |t, args|
145
+ args.with_defaults(:number => 500)
146
+ generator = RandomFeatureGenerator.new(args.number.to_i)
147
+ generator.generate
148
+ end
149
+
150
+ desc "Benchmark Cucumber AST building from the features in tasks/bench/generated"
151
+ task :cucumber do
152
+ benchmarker = Benchmarker.new
153
+ benchmarker.report("cucumber")
154
+ end
155
+
156
+ desc "Benchmark the Treetop parser with the features in tasks/bench/generated"
157
+ task :tt do
158
+ benchmarker = Benchmarker.new
159
+ benchmarker.report("tt")
160
+ end
161
+
162
+ desc "Benchmark the Ruby Gherkin lexer+parser with the features in tasks/bench/generated"
163
+ task :rb_gherkin do
164
+ benchmarker = Benchmarker.new
165
+ benchmarker.report("rb_gherkin")
166
+ end
167
+
168
+ desc "Benchmark the ntive Gherkin lexer+parser with the features in tasks/bench/generated"
169
+ task :native_gherkin do
170
+ benchmarker = Benchmarker.new
171
+ benchmarker.report("native_gherkin")
172
+ end
173
+
174
+ desc "Benchmark the native Gherkin lexer (no parser) with the features in tasks/bench/generated"
175
+ task :native_gherkin_no_parser do
176
+ benchmarker = Benchmarker.new
177
+ benchmarker.report("native_gherkin_no_parser")
178
+ end
179
+
180
+ desc "Remove all generated features in tasks/bench/generated"
181
+ task :clean do
182
+ rm_f FileList[GENERATED_FEATURES + "/**/*feature"]
183
+ end
184
+ end
@@ -0,0 +1,49 @@
1
+ class StepsBuilder
2
+ def initialize
3
+ @steps = []
4
+ end
5
+
6
+ def step(content, generator)
7
+ @steps << " Given #{content}"
8
+ if(rand(5) == 0)
9
+ cols = rand(8) + 1
10
+ rows = rand(10)
11
+ rows.times do
12
+ row = " |"
13
+ cols.times do
14
+ row << generator.table_cell << "|"
15
+ end
16
+ @steps << row
17
+ end
18
+ end
19
+ end
20
+
21
+ def to_s
22
+ @steps.join("\n")
23
+ end
24
+ end
25
+
26
+ class FeatureBuilder
27
+ def initialize(name, &block)
28
+ @name = name
29
+ @scenarios = {}
30
+ block.call(self)
31
+ end
32
+
33
+ def scenario(name, &block)
34
+ @scenarios[name] = StepsBuilder.new
35
+ block.call(@scenarios[name])
36
+ end
37
+
38
+ def to_s
39
+ str = "Feature: #{@name}\n"
40
+ @scenarios.each do |scenario, steps|
41
+ str += "\n"
42
+ str += " Scenario: #{scenario}\n"
43
+ str += steps.to_s
44
+ str += "\n"
45
+ end
46
+ str
47
+ end
48
+ end
49
+
@@ -0,0 +1 @@
1
+ *.feature
@@ -0,0 +1,4 @@
1
+ class NullListener
2
+ def method_missing(*args)
3
+ end
4
+ end
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/ragel_task'
2
+ BYPASS_NATIVE_IMPL = true
3
+ require 'gherkin/i18n'
4
+
5
+ CLEAN.include [
6
+ 'pkg', 'tmp',
7
+ '**/*.{o,bundle,jar,so,obj,pdb,lib,def,exp,log,rbc}', 'ext',
8
+ 'java/target',
9
+ 'ragel/i18n/*.rl',
10
+ 'lib/gherkin/rb_lexer/*.rb',
11
+ 'lib/*.dll',
12
+ 'ext/**/*.c',
13
+ 'java/src/main/java/gherkin/lexer/i18n/*.java',
14
+ 'java/src/main/resources/gherkin/*.properties',
15
+ ]
16
+
17
+ desc "Compile the Java extensions"
18
+ task :jar => 'lib/gherkin.jar'
19
+
20
+ file 'lib/gherkin.jar' => Dir['java/src/main/java/**/*.java'] do
21
+ sh("mvn -f java/pom.xml package")
22
+ end
23
+
24
+ rl_langs = ENV['RL_LANGS'] ? ENV['RL_LANGS'].split(',') : []
25
+ langs = Gherkin::I18n.all.select { |lang| rl_langs.empty? || rl_langs.include?(lang.iso_code) }
26
+
27
+ # http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457127
28
+ file 'lib/gherkin.jar' => "java/src/main/resources/gherkin/I18nKeywords_in.properties"
29
+ file "java/src/main/resources/gherkin/I18nKeywords_in.properties" => "java/src/main/resources/gherkin/I18nKeywords_id.properties" do
30
+ cp "java/src/main/resources/gherkin/I18nKeywords_id.properties", "java/src/main/resources/gherkin/I18nKeywords_in.properties"
31
+ end
32
+
33
+ # http://forums.sun.com/thread.jspa?threadID=5335461
34
+ file 'lib/gherkin.jar' => "java/src/main/resources/gherkin/I18nKeywords_iw.properties"
35
+ file "java/src/main/resources/gherkin/I18nKeywords_iw.properties" => "java/src/main/resources/gherkin/I18nKeywords_he.properties" do
36
+ cp "java/src/main/resources/gherkin/I18nKeywords_he.properties", "java/src/main/resources/gherkin/I18nKeywords_iw.properties"
37
+ end
38
+
39
+ langs.each do |i18n|
40
+ java = RagelTask.new('java', i18n)
41
+ rb = RagelTask.new('rb', i18n)
42
+
43
+ lang_country = i18n.iso_code.split(/-/)
44
+ suffix = lang_country.length == 1 ? lang_country[0] : "#{lang_country[0]}_#{lang_country[1].upcase}"
45
+ java_properties = "java/src/main/resources/gherkin/I18nKeywords_#{suffix}.properties"
46
+ file java_properties => 'lib/gherkin/i18n.yml' do
47
+ File.open(java_properties, 'wb') do |io|
48
+ io.puts("# Generated file. Do not edit.")
49
+ (Gherkin::I18n::KEYWORD_KEYS + %w{name native}).each do |key|
50
+ value = Gherkin::I18n.unicode_escape(i18n.keywords(key).join("|"))
51
+ io.puts("#{key}:#{value}")
52
+ end
53
+ end
54
+ end
55
+ file 'lib/gherkin.jar' => [java.target, rb.target, java_properties]
56
+
57
+ begin
58
+ if !defined?(JRUBY_VERSION)
59
+ require 'rake/extensiontask'
60
+
61
+ c = RagelTask.new('c', i18n)
62
+
63
+ extconf = "ext/gherkin_lexer_#{i18n.underscored_iso_code}/extconf.rb"
64
+ file extconf do
65
+ FileUtils.mkdir(File.dirname(extconf)) unless File.directory?(File.dirname(extconf))
66
+ File.open(extconf, "w") do |io|
67
+ io.write(<<-EOF)
68
+ require 'mkmf'
69
+ CONFIG['warnflags'].gsub!(/-Wshorten-64-to-32/, '') if CONFIG['warnflags']
70
+ $CFLAGS << ' -O0 -Wall -Werror' if CONFIG['CC'] =~ /gcc/
71
+ dir_config("gherkin_lexer_#{i18n.underscored_iso_code}")
72
+ have_library("c", "main")
73
+ create_makefile("gherkin_lexer_#{i18n.underscored_iso_code}")
74
+ EOF
75
+ end
76
+ end
77
+
78
+ Rake::ExtensionTask.new("gherkin_lexer_#{i18n.underscored_iso_code}") do |ext|
79
+ if ENV['RUBY_CC_VERSION']
80
+ ext.cross_compile = true
81
+ ext.cross_platform = 'x86-mingw32'
82
+ end
83
+ end
84
+
85
+ # The way tasks are defined with compile:xxx (but without namespace) in rake-compiler forces us
86
+ # to use these hacks for setting up dependencies. Ugly!
87
+ Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(extconf)
88
+ Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(c.target)
89
+ Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(rb.target)
90
+
91
+ Rake::Task["compile"].prerequisites.unshift(extconf)
92
+ Rake::Task["compile"].prerequisites.unshift(c.target)
93
+ Rake::Task["compile"].prerequisites.unshift(rb.target)
94
+ end
95
+ rescue LoadError
96
+ unless defined?($c_warned)
97
+ warn "WARNING: Rake::ExtensionTask not installed. Skipping C compilation."
98
+ $c_warned = true
99
+ task :compile # no-op
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,20 @@
1
+ unless ENV['RUBY_CC_VERSION']
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new(:cucumber) do |t|
5
+ t.cucumber_opts = "--profile default"
6
+ end
7
+
8
+ namespace :cucumber do
9
+ Cucumber::Rake::Task.new(:rcov, "Run Cucumber using RCov") do |t|
10
+ t.cucumber_opts = "--profile default"
11
+ t.rcov = true
12
+ t.rcov_opts = %w{--exclude spec\/}
13
+ end
14
+
15
+ Cucumber::Rake::Task.new(:native_lexer, "Run Native lexer Cucumber features") do |t|
16
+ t.cucumber_opts = "--profile native_lexer"
17
+ end
18
+ task :native_lexer => [:clean, :compile]
19
+ end
20
+ end
data/tasks/gems.rake ADDED
@@ -0,0 +1,35 @@
1
+ namespace :gems do
2
+ task :win do
3
+ unless File.directory?(File.expand_path('~/.rake-compiler'))
4
+ STDERR.puts "[ERROR] You must install MinGW rubies to build gherkin gems for Windows. See README.rdoc"
5
+ exit(1)
6
+ end
7
+ # rvm and mingw ruby versions have to match to avoid errors
8
+ sh "rvm 1.8.6-p399@cucumber rake cross compile RUBY_CC_VERSION=1.8.6"
9
+ sh "rvm 1.9.1-p243@cucumber rake cross compile RUBY_CC_VERSION=1.9.1"
10
+ # This will copy the .so files to the proper place
11
+ sh "rake cross compile RUBY_CC_VERSION=1.8.6:1.9.1"
12
+ end
13
+
14
+ desc 'Prepare JRuby binares'
15
+ task :jruby => [:jar] do
16
+ sh "rvm jruby@cucumber exec rspec spec"
17
+ end
18
+
19
+ desc 'Prepare IronRuby binaries'
20
+ task :ironruby => [:jruby, 'ikvm:dll', 'ikvm:copy_ikvm_dlls']
21
+
22
+ task :sanity do
23
+ raise "The jruby gem looks too small" if File.stat("release/gherkin-#{Gherkin::VERSION}-java.gem").size < 1000000
24
+ end
25
+
26
+ desc "Prepare binaries for all gems"
27
+ task :prepare => [
28
+ :clean,
29
+ :spec,
30
+ :win,
31
+ :jruby,
32
+ :ironruby
33
+ ]
34
+
35
+ end