polytrix 0.0.1 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.rspec +1 -6
  4. data/.rubocop-todo.yml +19 -0
  5. data/.rubocop.yml +10 -0
  6. data/.travis.yml +11 -0
  7. data/Gemfile +0 -16
  8. data/README.md +119 -28
  9. data/Rakefile +18 -123
  10. data/bin/polytrix +5 -0
  11. data/doc-src/_markdown.md +5 -0
  12. data/doc-src/default_bootstrap.md +13 -0
  13. data/docs/influences.md +28 -0
  14. data/docs/samples/code2doc/java/HelloWorld.md +13 -0
  15. data/docs/samples/code2doc/java/Quine.md +33 -0
  16. data/docs/samples/code2doc/python/hello_world.md +3 -0
  17. data/docs/samples/code2doc/python/quine.md +4 -0
  18. data/docs/samples/code2doc/ruby/hello_world.md +7 -0
  19. data/features/execution.feature +67 -0
  20. data/features/fixtures/configs/empty.yml +12 -0
  21. data/features/fixtures/configs/hello_world.yml +10 -0
  22. data/features/fixtures/spec/polytrix_merge.rb +5 -0
  23. data/features/fixtures/spec/polytrix_spec.rb +10 -0
  24. data/features/reporting.feature +140 -0
  25. data/features/step_definitions/sdk_steps.rb +12 -0
  26. data/features/support/env.rb +8 -0
  27. data/lib/polytrix/challenge.rb +20 -7
  28. data/lib/polytrix/challenge_runner.rb +9 -44
  29. data/lib/polytrix/cli/add.rb +67 -0
  30. data/lib/polytrix/cli/report.rb +88 -0
  31. data/lib/polytrix/cli/reports/hash_reporter.rb +30 -0
  32. data/lib/polytrix/cli/reports/json_reporter.rb +14 -0
  33. data/lib/polytrix/cli/reports/markdown_reporter.rb +23 -0
  34. data/lib/polytrix/cli/reports/yaml_reporter.rb +14 -0
  35. data/lib/polytrix/cli.rb +158 -0
  36. data/lib/polytrix/configuration.rb +65 -4
  37. data/lib/polytrix/core/file_system_helper.rb +75 -0
  38. data/lib/polytrix/core/implementor.rb +31 -3
  39. data/lib/polytrix/documentation/code_segmenter.rb +168 -0
  40. data/lib/polytrix/documentation/comment_styles.rb +87 -0
  41. data/lib/polytrix/documentation/helpers/code_helper.rb +85 -0
  42. data/lib/polytrix/documentation/view_helper.rb +21 -0
  43. data/lib/polytrix/documentation_generator.rb +59 -10
  44. data/lib/polytrix/executor.rb +89 -0
  45. data/lib/polytrix/logger.rb +17 -0
  46. data/lib/polytrix/manifest.rb +64 -7
  47. data/lib/polytrix/result.rb +16 -2
  48. data/lib/polytrix/rspec/documentation_formatter.rb +41 -16
  49. data/lib/polytrix/rspec/yaml_report.rb +51 -0
  50. data/lib/polytrix/rspec.rb +32 -53
  51. data/lib/polytrix/runners/middleware/feature_executor.rb +4 -3
  52. data/lib/polytrix/runners/middleware/setup_env_vars.rb +6 -4
  53. data/lib/polytrix/validation.rb +20 -0
  54. data/lib/polytrix/validations.rb +23 -0
  55. data/lib/polytrix/validator.rb +20 -0
  56. data/lib/polytrix/validator_registry.rb +34 -0
  57. data/lib/polytrix/version.rb +1 -1
  58. data/lib/polytrix.rb +125 -22
  59. data/polytrix.gemspec +7 -2
  60. data/polytrix.rb +6 -0
  61. data/polytrix_tests.yml +20 -0
  62. data/resources/code_sample.tt +2 -0
  63. data/samples/.gitignore +2 -0
  64. data/samples/_markdown.md +5 -0
  65. data/samples/default_bootstrap.rb +14 -0
  66. data/samples/polytrix.rb +28 -0
  67. data/samples/polytrix_cli.sh +7 -0
  68. data/samples/polytrix_tests.yml +10 -0
  69. data/{sdks/fog → samples}/scripts/bootstrap +0 -2
  70. data/samples/scripts/wrapper +7 -0
  71. data/samples/sdks/custom/polytrix.yml +2 -0
  72. data/samples/sdks/java/.gitignore +2 -0
  73. data/samples/sdks/java/build.gradle +14 -0
  74. data/samples/sdks/java/challenges/HelloWorld.java +10 -0
  75. data/samples/sdks/java/challenges/Quine.java +31 -0
  76. data/samples/sdks/java/code_sample.tt +11 -0
  77. data/samples/sdks/java/scripts/bootstrap +2 -0
  78. data/samples/sdks/java/scripts/wrapper +8 -0
  79. data/samples/sdks/python/challenges/hello_world.py +2 -0
  80. data/samples/sdks/python/challenges/quine.py +2 -0
  81. data/{sdks/pkgcloud → samples/sdks/python}/scripts/wrapper +1 -1
  82. data/samples/sdks/ruby/challenges/hello_world.rb +4 -0
  83. data/scripts/bootstrap +1 -9
  84. data/scripts/wrapper +7 -0
  85. data/spec/fabricators/challenge_fabricator.rb +17 -0
  86. data/spec/fabricators/manifest_fabricator.rb +50 -0
  87. data/spec/fabricators/validator_fabricator.rb +12 -0
  88. data/spec/fixtures/{polytrix.yml → polytrix_tests.yml} +0 -0
  89. data/spec/fixtures/src-doc/_scenario.md.erb +1 -0
  90. data/spec/polytrix/challenge_runner_spec.rb +3 -3
  91. data/spec/polytrix/challenge_spec.rb +3 -4
  92. data/spec/polytrix/cli_spec.rb +39 -0
  93. data/spec/polytrix/configuration_spec.rb +45 -1
  94. data/spec/polytrix/documentation/helpers/code_helper_spec.rb +120 -0
  95. data/spec/polytrix/documentation_generator_spec.rb +41 -20
  96. data/spec/polytrix/file_finder_spec.rb +4 -3
  97. data/spec/polytrix/implementor_spec.rb +33 -0
  98. data/spec/polytrix/manifest_spec.rb +32 -14
  99. data/spec/polytrix/middleware/feature_executor_spec.rb +1 -1
  100. data/spec/polytrix/result_spec.rb +49 -0
  101. data/spec/polytrix/validations_spec.rb +16 -0
  102. data/spec/polytrix/validator_registry_spec.rb +39 -0
  103. data/spec/polytrix/validator_spec.rb +63 -0
  104. data/spec/polytrix_spec.rb +33 -7
  105. data/spec/spec_helper.rb +14 -1
  106. data/spec/thor_spy.rb +64 -0
  107. metadata +177 -160
  108. data/.rspec_parallel +0 -10
  109. data/Vagrantfile +0 -41
  110. data/features/0_identity_spec.rb +0 -40
  111. data/features/1_cloud_files_spec.rb +0 -48
  112. data/features/2_servers_spec.rb +0 -19
  113. data/features/features_helper.rb +0 -46
  114. data/features/helpers/cloudfiles_helper.rb +0 -31
  115. data/features/helpers/pacto_helper.rb +0 -33
  116. data/features/helpers/teardown_helper.rb +0 -49
  117. data/features/pacto/extensions/loaders/api_blueprint_loader.rb +0 -63
  118. data/features/pacto/extensions/loaders/simple_loader.rb +0 -55
  119. data/features/pacto/extensions/loaders/yaml_or_json_loader.rb +0 -17
  120. data/features/pacto/extensions/matchers.rb +0 -38
  121. data/features/phase2/feature_coverage_report.rb +0 -109
  122. data/features/phase2/run_all_features.rb +0 -14
  123. data/features/static_site/fixtures/index.html +0 -6
  124. data/lib/polytrix/challenge_builder.rb +0 -16
  125. data/lib/polytrix/core/file_finder.rb +0 -43
  126. data/lib/polytrix/core/result_tracker.rb +0 -25
  127. data/lib/polytrix/runners/middleware/pacto.rb +0 -59
  128. data/packer/.gitignore +0 -3
  129. data/packer/Berksfile +0 -15
  130. data/packer/Gemfile +0 -5
  131. data/packer/Vagrantfile +0 -128
  132. data/packer/cookbooks/drg/metadata.rb +0 -27
  133. data/packer/cookbooks/drg/recipes/admins.rb +0 -22
  134. data/packer/cookbooks/drg/recipes/default.rb +0 -9
  135. data/packer/cookbooks/drg/recipes/dotnet.rb +0 -4
  136. data/packer/cookbooks/drg/recipes/golang.rb +0 -4
  137. data/packer/cookbooks/drg/recipes/java.rb +0 -5
  138. data/packer/cookbooks/drg/recipes/php.rb +0 -10
  139. data/packer/cookbooks/drg/recipes/ruby.rb +0 -29
  140. data/packer/cookbooks/drg/recipes/system.rb +0 -13
  141. data/packer/create_box.sh +0 -10
  142. data/packer/http/preseed.cfg +0 -87
  143. data/packer/packer.json +0 -91
  144. data/packer/scripts/root_setup.sh +0 -37
  145. data/packer/scripts/setup.sh +0 -32
  146. data/pacto/config/pacto_server.rb +0 -40
  147. data/pacto/contracts/dfw.servers.api.rackspacecloud.com/v2/account_id/extensions.json +0 -64
  148. data/pacto/contracts/dfw.servers.api.rackspacecloud.com/v2/account_id/flavors/id.json +0 -100
  149. data/pacto/contracts/dfw.servers.api.rackspacecloud.com/v2/account_id/images/id.json +0 -176
  150. data/pacto/contracts/dfw.servers.api.rackspacecloud.com/v2/account_id/servers/id.json +0 -189
  151. data/pacto/contracts/dfw.servers.api.rackspacecloud.com/v2/account_id/servers.json +0 -63
  152. data/pacto/contracts/dns.api.rackspacecloud.com/v1.0/_tenant_id/domains.json +0 -62
  153. data/pacto/contracts/identity.api.rackspacecloud.com/v2.0/tokens.json +0 -192
  154. data/pacto/contracts/monitoring.api.rackspacecloud.com/v1.0/_tenant_id/account.json +0 -39
  155. data/pacto/contracts/ord.autoscale.api.rackspacecloud.com/v1.0/_tenant_id/groups.json +0 -38
  156. data/pacto/contracts/ord.blockstorage.api.rackspacecloud.com/v1/_tenant_id/volumes.json +0 -30
  157. data/pacto/contracts/ord.databases.api.rackspacecloud.com/v1.0/_tenant_id/instances.json +0 -30
  158. data/pacto/contracts/ord.loadbalancers.api.rackspacecloud.com/v1.0/_tenant_id/loadbalancers.json +0 -114
  159. data/pacto/contracts/ord.queues.api.rackspacecloud.com/v1/_tenant_id/queues.json +0 -13
  160. data/pacto/contracts/ord.servers.api.rackspacecloud.com/v2/_tenant_id/os-networksv2.json +0 -46
  161. data/pacto/contracts/ord.servers.api.rackspacecloud.com/v2/_tenant_id/servers/detail.json +0 -230
  162. data/pacto/contracts/storage101.dfw1.clouddrive.com/v1/mosso_account/container/object.json +0 -15
  163. data/pacto/contracts/storage101.dfw1.clouddrive.com/v1/mosso_account.json +0 -43
  164. data/pacto/contracts/storage101.ord1.clouddrive.com/v1/_mosso_id.json +0 -44
  165. data/pacto/pacto_server.rb +0 -100
  166. data/pacto/rackspace_uri_map.yaml +0 -229
  167. data/scripts/cibuild +0 -4
  168. data/sdks/fog/.gitignore +0 -1
  169. data/sdks/fog/Gemfile +0 -5
  170. data/sdks/fog/challenges/all_connections.rb +0 -45
  171. data/sdks/fog/challenges/authenticate_token.rb +0 -15
  172. data/sdks/fog/challenges/cdn_enable_container.rb +0 -20
  173. data/sdks/fog/challenges/create_a_container.rb +0 -17
  174. data/sdks/fog/challenges/create_server.rb +0 -36
  175. data/sdks/fog/challenges/get_object_metadata.rb +0 -13
  176. data/sdks/fog/challenges/list_containers.rb +0 -10
  177. data/sdks/fog/challenges/provision_scalable_webapp.rb +0 -30
  178. data/sdks/fog/challenges/upload_folder.rb +0 -25
  179. data/sdks/fog/scripts/bootstrap.ps1 +0 -1
  180. data/sdks/fog/scripts/wrapper +0 -2
  181. data/sdks/fog/scripts/wrapper.ps1 +0 -1
  182. data/sdks/gophercloud/.gitignore +0 -2
  183. data/sdks/gophercloud/challenges/authenticate_token.go +0 -23
  184. data/sdks/gophercloud/scripts/bootstrap +0 -6
  185. data/sdks/gophercloud/scripts/wrapper +0 -10
  186. data/sdks/jclouds/.gitignore +0 -1
  187. data/sdks/jclouds/challenges/AuthenticateToken.java +0 -115
  188. data/sdks/jclouds/pom.xml +0 -34
  189. data/sdks/jclouds/scripts/bootstrap +0 -3
  190. data/sdks/jclouds/scripts/wrapper +0 -7
  191. data/sdks/openstack.net/.gitignore +0 -4
  192. data/sdks/openstack.net/.nuget/Microsoft.Build.dll +0 -0
  193. data/sdks/openstack.net/.nuget/NuGet.Config +0 -6
  194. data/sdks/openstack.net/.nuget/NuGet.exe +0 -0
  195. data/sdks/openstack.net/.nuget/NuGet.targets +0 -136
  196. data/sdks/openstack.net/Challenge.cs +0 -10
  197. data/sdks/openstack.net/RunChallenge.cs +0 -19
  198. data/sdks/openstack.net/challenges/AuthenticateToken.cs +0 -24
  199. data/sdks/openstack.net/challenges/Weird.cs +0 -133
  200. data/sdks/openstack.net/openstack.net.csproj +0 -58
  201. data/sdks/openstack.net/openstack.net.sln +0 -27
  202. data/sdks/openstack.net/openstack.net.userprefs +0 -8
  203. data/sdks/openstack.net/packages.config +0 -6
  204. data/sdks/openstack.net/scripts/bootstrap +0 -2
  205. data/sdks/openstack.net/scripts/bootstrap.ps1 +0 -2
  206. data/sdks/openstack.net/scripts/wrapper +0 -7
  207. data/sdks/openstack.net/scripts/wrapper.ps1 +0 -1
  208. data/sdks/php-opencloud/.gitignore +0 -4
  209. data/sdks/php-opencloud/challenges/all_connections.php +0 -64
  210. data/sdks/php-opencloud/challenges/authenticate_token.php +0 -14
  211. data/sdks/php-opencloud/challenges/create_server.php +0 -39
  212. data/sdks/php-opencloud/challenges/get_object_metadata.php +0 -19
  213. data/sdks/php-opencloud/composer.json +0 -5
  214. data/sdks/php-opencloud/scripts/bootstrap +0 -4
  215. data/sdks/php-opencloud/scripts/bootstrap.ps1 +0 -2
  216. data/sdks/php-opencloud/scripts/wrapper +0 -2
  217. data/sdks/php-opencloud/scripts/wrapper.ps1 +0 -1
  218. data/sdks/pkgcloud/.gitignore +0 -1
  219. data/sdks/pkgcloud/challenges/authenticate_token.js +0 -17
  220. data/sdks/pkgcloud/challenges/get_object_metadata.js +0 -18
  221. data/sdks/pkgcloud/scripts/bootstrap +0 -2
  222. data/sdks/pkgcloud/scripts/bootstrap.ps1 +0 -1
  223. data/sdks/pkgcloud/scripts/wrapper.ps1 +0 -1
  224. data/sdks/pyrax/.gitignore +0 -2
  225. data/sdks/pyrax/challenges/all_connections.py +0 -61
  226. data/sdks/pyrax/challenges/authenticate_token.py +0 -17
  227. data/sdks/pyrax/challenges/cdn_enable_container.py +0 -22
  228. data/sdks/pyrax/challenges/create_a_container.py +0 -21
  229. data/sdks/pyrax/challenges/create_server.py +0 -35
  230. data/sdks/pyrax/challenges/get_object_metadata.py +0 -17
  231. data/sdks/pyrax/challenges/upload_folder.py +0 -32
  232. data/sdks/pyrax/requirements.txt +0 -21
  233. data/sdks/pyrax/scripts/bootstrap +0 -9
  234. data/sdks/pyrax/scripts/bootstrap.ps1 +0 -7
  235. data/sdks/pyrax/scripts/wrapper +0 -3
  236. data/sdks/pyrax/scripts/wrapper.ps1 +0 -2
  237. data/spec/polytrix/challenge_builder_spec.rb +0 -16
  238. data/spec/rspec_spec.rb +0 -17
@@ -0,0 +1,10 @@
1
+ ---
2
+ global_env:
3
+ LOCALE: <%= ENV['LANG'] %>
4
+ FAVORITE_NUMBER: 5
5
+ suites:
6
+ Katas:
7
+ env:
8
+ NAME: 'Max'
9
+ samples:
10
+ - hello world
@@ -0,0 +1,5 @@
1
+ require 'polytrix'
2
+
3
+ File.open('reports/polytrix.yaml', 'wb') do |f|
4
+ f.write Polytrix.merge_results(ARGV)
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'polytrix/rspec'
2
+
3
+ Polytrix.configure do |polytrix|
4
+ Dir['sdks/*'].each do |sdk|
5
+ polytrix.implementor sdk
6
+ end
7
+ polytrix.test_manifest = 'polytrix_tests.yml'
8
+ end
9
+ Polytrix.bootstrap
10
+ Polytrix.load_tests
@@ -0,0 +1,140 @@
1
+ Feature: Reporting
2
+
3
+ Polytrix creates YAML reports on teach test run. The reports are designed to be "deep mergable", so that you can split a test suite into separate threads running in parallel, each generating a separate report, and then merge them all to create a combined report.
4
+
5
+ Scenario: A report for a single SDK
6
+ Given the ruby SDK
7
+ And the hello_world polytrix config
8
+ And the standard rspec setup
9
+ When I successfully run `bundle exec rspec -f Polytrix::RSpec::YAMLReport -o reports/polytrix.yaml`
10
+ Then the file "reports/polytrix.yaml" should contain exactly:
11
+ """
12
+ ---
13
+ global_env:
14
+ LOCALE: en_US.UTF-8
15
+ FAVORITE_NUMBER: '5'
16
+ suites:
17
+ Katas:
18
+ env:
19
+ NAME: Max
20
+ samples:
21
+ hello world:
22
+ ruby:
23
+ validations:
24
+ - validated_by: polytrix
25
+ result: passed
26
+ execution_result:
27
+ exitstatus: 0
28
+ stdout: |
29
+ Hello, world!
30
+ stderr: ''
31
+ source_file: challenges/hello_world.rb
32
+
33
+ """
34
+
35
+ Scenario: A report for several SDKS
36
+ Given the ruby SDK
37
+ And the java SDK
38
+ And the python SDK
39
+ And the hello_world polytrix config
40
+ And the standard rspec setup
41
+ When I successfully run `bundle exec rspec -f Polytrix::RSpec::YAMLReport -o reports/polytrix.yaml`
42
+ Then the file "reports/polytrix.yaml" should contain exactly:
43
+ """
44
+ ---
45
+ global_env:
46
+ LOCALE: en_US.UTF-8
47
+ FAVORITE_NUMBER: '5'
48
+ suites:
49
+ Katas:
50
+ env:
51
+ NAME: Max
52
+ samples:
53
+ hello world:
54
+ java:
55
+ validations:
56
+ - validated_by: polytrix
57
+ result: passed
58
+ execution_result:
59
+ exitstatus: 0
60
+ stdout: |
61
+ Hello, world!
62
+ stderr: ''
63
+ source_file: challenges/HelloWorld.java
64
+ python:
65
+ validations:
66
+ - validated_by: polytrix
67
+ result: passed
68
+ execution_result:
69
+ exitstatus: 0
70
+ stdout: |
71
+ Hello, world!
72
+ stderr: ''
73
+ source_file: challenges/hello_world.py
74
+ ruby:
75
+ validations:
76
+ - validated_by: polytrix
77
+ result: passed
78
+ execution_result:
79
+ exitstatus: 0
80
+ stdout: |
81
+ Hello, world!
82
+ stderr: ''
83
+ source_file: challenges/hello_world.rb
84
+
85
+ """
86
+
87
+ Scenario: Merging separate reports
88
+ Given the ruby SDK
89
+ And the java SDK
90
+ And the python SDK
91
+ And the hello_world polytrix config
92
+ And the standard rspec setup
93
+ When I successfully run `bundle exec rspec -f Polytrix::RSpec::YAMLReport -t ruby -o reports/polytrix-ruby.yaml`
94
+ When I successfully run `bundle exec rspec -f Polytrix::RSpec::YAMLReport -t java -o reports/polytrix-java.yaml`
95
+ When I successfully run `bundle exec rspec -f Polytrix::RSpec::YAMLReport -t python -o reports/polytrix-python.yaml`
96
+ And I successfully run `bundle exec ruby spec/polytrix_merge.rb reports/polytrix-java.yaml reports/polytrix-python.yaml reports/polytrix-ruby.yaml`
97
+ Then the file "reports/polytrix.yaml" should contain exactly:
98
+ """
99
+ ---
100
+ global_env:
101
+ LOCALE: en_US.UTF-8
102
+ FAVORITE_NUMBER: '5'
103
+ suites:
104
+ Katas:
105
+ env:
106
+ NAME: Max
107
+ samples:
108
+ hello world:
109
+ java:
110
+ validations:
111
+ - validated_by: polytrix
112
+ result: passed
113
+ execution_result:
114
+ exitstatus: 0
115
+ stdout: |
116
+ Hello, world!
117
+ stderr: ''
118
+ source_file: challenges/HelloWorld.java
119
+ python:
120
+ validations:
121
+ - validated_by: polytrix
122
+ result: passed
123
+ execution_result:
124
+ exitstatus: 0
125
+ stdout: |
126
+ Hello, world!
127
+ stderr: ''
128
+ source_file: challenges/hello_world.py
129
+ ruby:
130
+ validations:
131
+ - validated_by: polytrix
132
+ result: passed
133
+ execution_result:
134
+ exitstatus: 0
135
+ stdout: |
136
+ Hello, world!
137
+ stderr: ''
138
+ source_file: challenges/hello_world.rb
139
+
140
+ """
@@ -0,0 +1,12 @@
1
+ Given(/^the (\w+) SDK$/) do |sdk|
2
+ FileUtils.mkdir_p "#{current_dir}/sdks"
3
+ FileUtils.cp_r "samples/sdks/#{sdk}", "#{current_dir}/sdks"
4
+ end
5
+
6
+ Given(/^the (\w+) polytrix config$/) do |config|
7
+ FileUtils.cp_r "features/fixtures/configs/#{config}.yml", "#{current_dir}/polytrix_tests.yml"
8
+ end
9
+
10
+ Given(/^the standard rspec setup$/) do
11
+ FileUtils.cp_r 'features/fixtures/spec/', "#{current_dir}/"
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'aruba/cucumber'
5
+
6
+ Before do
7
+ @aruba_timeout_seconds = 20
8
+ end
@@ -1,27 +1,40 @@
1
1
  require 'hashie/dash'
2
2
  require 'hashie/extensions/coercion'
3
3
  require 'hashie/extensions/indifferent_access'
4
+ require 'polytrix/documentation/helpers/code_helper'
4
5
 
5
6
  module Polytrix
6
7
  class Challenge < Hashie::Dash
7
8
  include Hashie::Extensions::Coercion
8
- include Hashie::Extensions::IndifferentAccess
9
+
10
+ # View heleprs
11
+ include Polytrix::Documentation::Helpers::CodeHelper
12
+
9
13
  property :name
14
+ property :description
10
15
  property :implementor
11
- property :vars, :default => {}
16
+ property :suite, required: true
17
+ property :vars, default: {}
12
18
  property :source_file
13
19
  coerce_key :source_file, Pathname
14
20
  property :basedir
15
21
  coerce_key :basedir, Pathname
16
- property :challenge_runner, :default => ChallengeRunner.createRunner
22
+ property :challenge_runner, default: ChallengeRunner.create_runner
17
23
  property :result
18
24
  property :env_file
19
- coerce_key :vars, Polytrix::Manifest::Environment
20
- property :plugin_data, :default => {}
25
+ # coerce_key :vars, Polytrix::Manifest::Environment
26
+ property :plugin_data, default: {}
21
27
 
22
28
  def run
23
- challenge_runner.run_challenge self
29
+ @result = challenge_runner.run_challenge self
24
30
  end
25
31
 
32
+ def validate
33
+ run unless @result
34
+ # validators = Polytrix::ValidatorRegistry.validators_for self
35
+ # validators.each do |validator|
36
+ # validator.validate self
37
+ # end
38
+ end
26
39
  end
27
- end
40
+ end
@@ -8,16 +8,11 @@ module Polytrix
8
8
  autoload :WindowsChallengeRunner, 'polytrix/runners/windows_challenge_runner'
9
9
  end
10
10
 
11
- class FeatureNotImplementedError < StandardError
12
- def initialize(feature)
13
- super "Feature #{feature} is not implemented"
14
- end
15
- end
11
+ class ChallengeRunner < Thor::Shell::Color
12
+ include Polytrix::Core::FileSystemHelper
13
+ include Polytrix::Executor
16
14
 
17
- class ChallengeRunner
18
- include Polytrix::Core::FileFinder
19
-
20
- def self.createRunner
15
+ def self.create_runner
21
16
  case RbConfig::CONFIG['host_os']
22
17
  when /mswin(\d+)|mingw/i
23
18
  Runners::WindowsChallengeRunner.new
@@ -34,23 +29,12 @@ module Polytrix
34
29
  ENV['CHALLENGE_EDITOR']
35
30
  end
36
31
 
37
- def interactive?
38
- ENV['INTERACTIVE']
39
- end
40
-
41
- def show_output?
42
- ENV['SHOW_OUTPUT']
43
- end
44
-
45
32
  def run_command(command)
46
- if interactive? # allows use of pry, code.interact, etc.
47
- system command
48
- else # better error messages and interrupt handling
49
- challenge_process = Mixlib::ShellOut.new(command)
50
- challenge_process.live_stream = $stdout if show_output?
51
- challenge_process.run_command
52
- challenge_process.error!
53
- challenge_process
33
+ if Polytrix.configuration.dry_run
34
+ puts "Would have run #{command}"
35
+ else
36
+ say_status 'polytrix:execute', command
37
+ execute command
54
38
  end
55
39
  end
56
40
 
@@ -59,25 +43,6 @@ module Polytrix
59
43
  challenge
60
44
  end
61
45
 
62
- def find_challenge!(challenge, basedir = Dir.pwd)
63
- find_file basedir, challenge
64
- rescue Polytrix::Core::FileFinder::FileNotFound
65
- raise FeatureNotImplementedError, challenge
66
- end
67
-
68
- def edit_challenge(challenge)
69
- suffix = infer_suffix File.dirname(challenge)
70
- challenge_file = "#{challenge}#{suffix}"
71
- puts "Would you like to create #{challenge_file} (y/n)? "
72
- system "#{challenge_editor} #{challenge_file}" if $stdin.gets.strip == 'y'
73
- File.absolute_path challenge_file
74
- end
75
-
76
- def infer_suffix(source_dir)
77
- # FIXME: Should be configurable or have a better way to infer
78
- Dir["#{source_dir}/**/*.*"].map { |f| File.extname f }.first
79
- end
80
-
81
46
  private
82
47
 
83
48
  def middleware
@@ -0,0 +1,67 @@
1
+ module Polytrix
2
+ module CLI
3
+ class Add < Polytrix::CLI::Base
4
+ include Thor::Actions
5
+ desc 'sample IMPLEMENTOR SCENARIO', 'Add a code sample for an implementor'
6
+ # sdk_options
7
+ method_option :language, type: 'string', desc: 'Programming language to use (if not already configured by the implementor)', default: 'rb'
8
+ def sample(implementor, scenario)
9
+ # implementor = pick_implementor(options[:sdk])
10
+ implementor = pick_implementor implementor
11
+ language = implementor.language || options[:language]
12
+ generate_source implementor, scenario, language
13
+ end
14
+
15
+ protected
16
+
17
+ source_root Polytrix.configuration.template_dir
18
+ # source_root implementor.basedir
19
+
20
+ def generate_source(implementor, scenario, language)
21
+ source_paths.prepend File.expand_path(implementor.basedir)
22
+ @implementor = implementor
23
+ @scenario = implementor.build_challenge(
24
+ name: scenario
25
+ )
26
+ @language = language
27
+
28
+ output_file = File.join(implementor.basedir, "#{scenario.gsub(' ', '_')}.#{language}")
29
+ template('code_sample.tt', output_file)
30
+ end
31
+
32
+ def commented(comment)
33
+ return if comment.nil?
34
+
35
+ buffer = StringIO.new
36
+ _lang, comment_style = Polytrix::Documentation::CommentStyles.infer @language
37
+ if use_multiline? comment, comment_style
38
+ buffer.puts comment_style[:multi][:start]
39
+ comment.lines.each do |line|
40
+ buffer.puts comment_line(line, comment_style[:multi][:middle])
41
+ end
42
+ buffer.puts comment_style[:multi][:end]
43
+ else
44
+ comment.lines.each do |line|
45
+ buffer.puts comment_line(line, comment_style[:single])
46
+ end
47
+ end
48
+ buffer.string
49
+ end
50
+
51
+ def comment_line(line, comment_string)
52
+ comment_string ||= ''
53
+ if line.strip.empty?
54
+ whitespace, line = line.gsub("\n", ''), ''
55
+ else
56
+ whitespace, line = line.rstrip.match(/([\s]*)(.*)/).captures
57
+ end
58
+
59
+ "#{whitespace}#{comment_string} #{line}"
60
+ end
61
+
62
+ def use_multiline?(comment, comment_style)
63
+ comment.lines.size > 1 && !comment_style[:multi].nil? && (comment_style[:multi][:idiomatic] != false)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,88 @@
1
+ module Polytrix
2
+ module CLI
3
+ module Reports
4
+ # autoload :TextReporter, 'polytrix/cli/reports/text_reporter'
5
+ autoload :MarkdownReporter, 'polytrix/cli/reports/markdown_reporter'
6
+ # autoload :HTMLReporter, 'polytrix/cli/reports/html_reporter'
7
+ autoload :JSONReporter, 'polytrix/cli/reports/json_reporter'
8
+ autoload :YAMLReporter, 'polytrix/cli/reports/yaml_reporter'
9
+ end
10
+ class Report < Polytrix::CLI::Base
11
+ # class_options = super.class_options
12
+ class_option :format, desc: 'Output format for the report', default: 'text', enum: %w(text markdown json yaml)
13
+
14
+ desc 'report summary', 'Generate a summary report by SDK'
15
+ config_options
16
+ log_options
17
+ def summary
18
+ setup
19
+ results = load_results
20
+ table = [%w(sdk passed failed pending skipped)]
21
+ results.each do |sdk, summary|
22
+ table << [sdk, summary[:passed], summary[:failed], summary[:pending], summary[:skipped]]
23
+ end
24
+ reporter.print_table table
25
+ end
26
+
27
+ desc 'report matrix', 'Generate a feature matrix report'
28
+ config_options
29
+ log_options
30
+ def matrix
31
+ setup
32
+ sdk_names = Polytrix.implementors.map(&:name)
33
+ table = [%w(Product Feature).concat(sdk_names)]
34
+
35
+ matrix_data.suites.each do |suite_name, suite_data|
36
+ suite_data.samples.each do |scenario_name, scenario_results|
37
+
38
+ statuses = sdk_names.map do |sdk|
39
+ result = Result.new(scenario_results[sdk])
40
+ result.status
41
+ end
42
+
43
+ table << [suite_name, scenario_name].concat(statuses)
44
+ end
45
+ end
46
+ reporter.print_table table
47
+ end
48
+
49
+ protected
50
+
51
+ def matrix_data
52
+ @matrix ||= Polytrix::Manifest.new(YAML.load(Polytrix.merge_results(Dir['reports/test_report*.yaml'])))
53
+ end
54
+
55
+ def load_results
56
+ result_stats = Hash.new do |hash, sdk|
57
+ hash[sdk] = { passed: 0, failed: 0, pending: 0, skipped: 0 }
58
+ end
59
+ matrix_data.suites.reduce(result_stats) do |hash, (suite_name, suite)|
60
+ suite.samples.each do |sample, suite_results|
61
+ Polytrix.implementors.map(&:name).each do |sdk|
62
+ result = Result.new(suite_results[sdk])
63
+ result.validations << Validation.new(validated_by: 'polytrix', result: 'skipped')
64
+ hash[sdk][result.status.to_sym] += 1
65
+ end
66
+ end
67
+ hash
68
+ end
69
+ result_stats
70
+ end
71
+
72
+ def reporter
73
+ @reporter ||= case options[:format]
74
+ when 'text'
75
+ self
76
+ when 'markdown'
77
+ Polytrix::CLI::Reports::MarkdownReporter.new
78
+ when 'json'
79
+ Polytrix::CLI::Reports::JSONReporter.new
80
+ when 'yaml'
81
+ Polytrix::CLI::Reports::YAMLReporter.new
82
+ else
83
+ fail "Unknown report format #{options[:format]}"
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,30 @@
1
+ require 'csv'
2
+
3
+ module Polytrix
4
+ module CLI
5
+ module Reports
6
+ class HashReporter
7
+ def initialize(io = $stdout)
8
+ @buffer = io
9
+ end
10
+
11
+ def print_table(table)
12
+ headers = table[0]
13
+ data = []
14
+ table[1..-1].map do |row|
15
+ row_data = {}
16
+ row.each_with_index do |value, index|
17
+ row_data[headers[index]] = value
18
+ end
19
+ data << row_data
20
+ end
21
+ @buffer.puts convert(data)
22
+ end
23
+
24
+ def convert(data)
25
+ fail 'Subclass HashReporter and convert the data to the target format'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+ require 'polytrix/cli/reports/hash_reporter'
3
+
4
+ module Polytrix
5
+ module CLI
6
+ module Reports
7
+ class JSONReporter < HashReporter
8
+ def convert(data)
9
+ JSON.pretty_generate data
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module Polytrix
2
+ module CLI
3
+ module Reports
4
+ class MarkdownReporter
5
+ def initialize(io = $stdout)
6
+ @buffer = io
7
+ end
8
+
9
+ def print_table(table)
10
+ @buffer.puts # Markdown tables don't always render properly without a break
11
+ header_data = table[0]
12
+ header_line = header_data.join ' | '
13
+ @buffer.puts header_line
14
+ @buffer.puts header_line.gsub(/[^|]/, '-')
15
+
16
+ table[1..-1].each do |data_line|
17
+ @buffer.puts data_line.join ' | '
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'polytrix/cli/reports/hash_reporter'
3
+
4
+ module Polytrix
5
+ module CLI
6
+ module Reports
7
+ class YAMLReporter < HashReporter
8
+ def convert(data)
9
+ YAML.dump data
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end