polytrix 0.1.2 → 0.1.3
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/.rubocop-todo.yml +14 -5
- data/Gemfile +2 -1
- data/README.md +139 -177
- data/Rakefile +5 -12
- data/bin/polytrix +0 -1
- data/features/bootstrapping.feature +0 -3
- data/features/cloning.feature +0 -3
- data/features/show.feature +38 -0
- data/features/states.feature +12 -13
- data/features/step_definitions/sdk_steps.rb +0 -4
- data/lib/polytrix/challenge.rb +135 -53
- data/lib/polytrix/challenge_result.rb +0 -2
- data/lib/polytrix/challenge_runner.rb +28 -18
- data/lib/polytrix/cli.rb +53 -69
- data/lib/polytrix/color.rb +2 -2
- data/lib/polytrix/command/action.rb +4 -3
- data/lib/polytrix/command/list.rb +39 -28
- data/lib/polytrix/command/report.rb +9 -86
- data/lib/polytrix/command/reports/code2doc.rb +72 -0
- data/lib/polytrix/command/reports/dashboard.rb +125 -0
- data/lib/polytrix/command/show.rb +148 -0
- data/lib/polytrix/command.rb +37 -104
- data/lib/polytrix/configuration.rb +14 -18
- data/lib/polytrix/{core/hashie.rb → dash.rb} +4 -3
- data/lib/polytrix/documentation/code_segmenter.rb +8 -8
- data/lib/polytrix/documentation/comment_styles.rb +1 -1
- data/lib/polytrix/documentation/helpers/code_helper.rb +9 -0
- data/lib/polytrix/documentation_generator.rb +11 -14
- data/lib/polytrix/error.rb +104 -97
- data/lib/polytrix/executor.rb +33 -0
- data/lib/polytrix/{runners → executors}/buff_shellout_executor.rb +1 -1
- data/lib/polytrix/executors/linux_challenge_executor.rb +29 -0
- data/lib/polytrix/executors/mixlib_shellout_executor.rb +55 -0
- data/lib/polytrix/{runners/windows_challenge_runner.rb → executors/windows_challenge_executor.rb} +4 -11
- data/lib/polytrix/{core/implementor.rb → implementor.rb} +10 -6
- data/lib/polytrix/manifest.rb +2 -31
- data/lib/polytrix/{reports → reporters}/hash_reporter.rb +6 -2
- data/lib/polytrix/{reports → reporters}/json_reporter.rb +2 -2
- data/lib/polytrix/{reports → reporters}/markdown_reporter.rb +7 -2
- data/lib/polytrix/{reports → reporters}/yaml_reporter.rb +2 -2
- data/lib/polytrix/reporters.rb +27 -0
- data/lib/polytrix/result.rb +6 -5
- data/lib/polytrix/spies/file_system_spy.rb +15 -0
- data/lib/polytrix/spies.rb +61 -0
- data/lib/polytrix/state_file.rb +1 -20
- data/lib/polytrix/util.rb +157 -62
- data/lib/polytrix/validation.rb +41 -2
- data/lib/polytrix/validator.rb +9 -4
- data/lib/polytrix/version.rb +1 -1
- data/lib/polytrix.rb +110 -105
- data/polytrix.gemspec +7 -2
- data/polytrix.yml +16 -13
- data/resources/assets/pygments/autumn.css +58 -0
- data/resources/assets/pygments/borland.css +46 -0
- data/resources/assets/pygments/bw.css +34 -0
- data/resources/assets/pygments/colorful.css +61 -0
- data/resources/assets/pygments/default.css +62 -0
- data/resources/assets/pygments/emacs.css +61 -0
- data/resources/assets/pygments/friendly.css +61 -0
- data/resources/assets/pygments/fruity.css +69 -0
- data/resources/assets/pygments/github.css +61 -0
- data/resources/assets/pygments/manni.css +61 -0
- data/resources/assets/pygments/monokai.css +64 -0
- data/resources/assets/pygments/murphy.css +61 -0
- data/resources/assets/pygments/native.css +69 -0
- data/resources/assets/pygments/pastie.css +60 -0
- data/resources/assets/pygments/perldoc.css +58 -0
- data/resources/assets/pygments/tango.css +69 -0
- data/resources/assets/pygments/trac.css +59 -0
- data/resources/assets/pygments/vim.css +69 -0
- data/resources/assets/pygments/vs.css +33 -0
- data/resources/assets/pygments/zenburn.css +1 -0
- data/resources/assets/style.css +41 -0
- data/resources/templates/dashboard/files/dashboard.html.tt +82 -0
- data/resources/templates/dashboard/templates/_test_report.html.tt +87 -0
- data/samples/bootstrap.sh +2 -0
- data/samples/clone.sh +2 -0
- data/samples/code2doc.sh +4 -0
- data/samples/docs/samples/code2doc/java/katas-hello_world-java.md +17 -0
- data/samples/docs/samples/code2doc/java/katas-quine-java.md +35 -0
- data/samples/docs/samples/code2doc/python/katas-hello_world-python.md +5 -0
- data/samples/docs/samples/code2doc/python/katas-quine-python.md +6 -0
- data/samples/docs/samples/code2doc/ruby/katas-hello_world-ruby.md +11 -0
- data/samples/exec.sh +2 -0
- data/samples/polytrix.rb +2 -2
- data/samples/polytrix.yml +5 -2
- data/samples/show.sh +4 -0
- data/samples/test.sh +2 -0
- data/samples/tests/polytrix/validators.rb +2 -2
- data/samples/verify.sh +3 -0
- data/scripts/wrapper +4 -7
- data/spec/fabricators/challenge_fabricator.rb +2 -9
- data/spec/fabricators/implementor_fabricator.rb +0 -8
- data/spec/fabricators/manifest_fabricator.rb +2 -9
- data/spec/fabricators/validator_fabricator.rb +2 -4
- data/spec/polytrix/challenge_runner_spec.rb +20 -0
- data/spec/polytrix/documentation/helpers/code_helper_spec.rb +7 -7
- data/spec/polytrix/file_finder_spec.rb +5 -5
- data/spec/polytrix/manifest_spec.rb +0 -21
- data/spec/polytrix/result_spec.rb +14 -14
- data/spec/polytrix/validator_registry_spec.rb +4 -4
- data/spec/polytrix/validator_spec.rb +9 -9
- data/spec/polytrix_spec.rb +1 -25
- data/spec/spec_helper.rb +8 -1
- metadata +130 -38
- data/features/execution.feature +0 -53
- data/features/fixtures/spec/polytrix_spec.rb +0 -7
- data/lib/polytrix/cli/report.rb +0 -84
- data/lib/polytrix/command/rundoc.rb +0 -27
- data/lib/polytrix/core/file_system_helper.rb +0 -75
- data/lib/polytrix/core/manifest_section.rb +0 -4
- data/lib/polytrix/core/string_helpers.rb +0 -15
- data/lib/polytrix/documentation/view_helper.rb +0 -21
- data/lib/polytrix/rspec/documentation_formatter.rb +0 -66
- data/lib/polytrix/rspec/yaml_report.rb +0 -51
- data/lib/polytrix/rspec.rb +0 -56
- data/lib/polytrix/runners/executor.rb +0 -34
- data/lib/polytrix/runners/linux_challenge_runner.rb +0 -23
- data/lib/polytrix/runners/middleware/change_directory.rb +0 -20
- data/lib/polytrix/runners/middleware/feature_executor.rb +0 -24
- data/lib/polytrix/runners/middleware/setup_env_vars.rb +0 -42
- data/lib/polytrix/runners/mixlib_shellout_executor.rb +0 -83
- data/lib/polytrix/validations.rb +0 -23
- data/samples/scripts/wrapper +0 -7
- data/spec/polytrix/middleware/feature_executor_spec.rb +0 -48
- data/spec/polytrix/validations_spec.rb +0 -16
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module Polytrix
|
|
2
|
-
module Documentation
|
|
3
|
-
module ViewHelper
|
|
4
|
-
def polytrix_toc
|
|
5
|
-
buffer = StringIO.new
|
|
6
|
-
buffer.puts '<ul>'
|
|
7
|
-
Polytrix.manifest.suites.each do |suite_name, suite|
|
|
8
|
-
buffer.puts "<li>#{suite_name}</li>"
|
|
9
|
-
buffer.puts '<ul>'
|
|
10
|
-
suite.samples.each do |challenge_name|
|
|
11
|
-
buffer.puts "<li>#{challenge_name}</li>"
|
|
12
|
-
end
|
|
13
|
-
buffer.puts '</ul>'
|
|
14
|
-
end
|
|
15
|
-
buffer.puts '</ul>'
|
|
16
|
-
|
|
17
|
-
buffer.string
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require 'polytrix/rspec'
|
|
2
|
-
require 'hashie/mash'
|
|
3
|
-
require 'yaml'
|
|
4
|
-
require 'fileutils'
|
|
5
|
-
|
|
6
|
-
module Polytrix
|
|
7
|
-
module RSpec
|
|
8
|
-
class DocumentationFormatter < ::RSpec::Core::Formatters::BaseFormatter
|
|
9
|
-
include Polytrix::Core::FileSystemHelper
|
|
10
|
-
|
|
11
|
-
def initialize(output)
|
|
12
|
-
@templates_dir = 'doc-src'
|
|
13
|
-
@output_dir = 'docs'
|
|
14
|
-
@results = Hashie::Mash.new
|
|
15
|
-
@summary_files = %w(index)
|
|
16
|
-
super
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def example_group_finished(example_group)
|
|
20
|
-
polytrix_challenges = example_group.examples.map { |e| e.metadata[:polytrix_challenge] }
|
|
21
|
-
target_file = target_file_for example_group
|
|
22
|
-
template_file = template_for example_group
|
|
23
|
-
produce_doc template_file, target_file, example_group.description, polytrix_challenges if template_file
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def dump_summary(duration, example_count, failure_count, pending_count)
|
|
27
|
-
all_challenges = examples.map { |e| e.metadata[:polytrix_challenge] }
|
|
28
|
-
grouped_challenges = all_challenges.compact.group_by(&:name)
|
|
29
|
-
@summary_files.each do |summary_file|
|
|
30
|
-
template_file = template_for summary_file, use_default: false
|
|
31
|
-
next if template_file.nil?
|
|
32
|
-
target_file = target_file_for_summary(template_file)
|
|
33
|
-
produce_doc template_file, target_file, 'Summary', grouped_challenges
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def template_for(name, opts = { use_default: true })
|
|
40
|
-
name = name.description if name.respond_to? :description
|
|
41
|
-
begin
|
|
42
|
-
find_file @templates_dir, name, ''
|
|
43
|
-
rescue Polytrix::Core::FileSystemHelper::FileNotFound
|
|
44
|
-
Polytrix.configuration.default_doc_template if opts[:use_default] == true
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def target_file_for(example_group)
|
|
49
|
-
names = [@output_dir].concat(example_group.parent_groups.reverse.map(&:description))
|
|
50
|
-
# Markdown format by default, but will be overridden to match the template
|
|
51
|
-
slugify(names.join File::SEPARATOR) + '.md'
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def target_file_for_summary(template_file)
|
|
55
|
-
name = File.basename(template_file)
|
|
56
|
-
slugify("docs/#{name}")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def produce_doc(template_file, target_file, scenario, data)
|
|
60
|
-
doc_gen = Polytrix::DocumentationGenerator.new template_file, scenario
|
|
61
|
-
doc_gen.process data
|
|
62
|
-
doc_gen.save target_file
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'polytrix/rspec'
|
|
2
|
-
require 'hashie/mash'
|
|
3
|
-
require 'yaml'
|
|
4
|
-
require 'fileutils'
|
|
5
|
-
|
|
6
|
-
module Polytrix
|
|
7
|
-
module RSpec
|
|
8
|
-
class YAMLReport < ::RSpec::Core::Formatters::BaseFormatter
|
|
9
|
-
def example_passed(example)
|
|
10
|
-
add_implementation_result example, :passed
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def example_failed(example)
|
|
14
|
-
add_implementation_result example, :failed
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def example_pending(example)
|
|
18
|
-
add_implementation_result example, :pending
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def dump_summary(duration, example_count, failure_count, pending_count)
|
|
22
|
-
results = Hashie::Mash.new(Polytrix.manifest.dup.to_hash)
|
|
23
|
-
all_challenges = examples.map { |e| e.metadata[:polytrix_challenge] }
|
|
24
|
-
grouped_challenges = all_challenges.compact.group_by(&:name)
|
|
25
|
-
results.suites.each do |suite_name, suite|
|
|
26
|
-
suite.samples = suite.samples.each_with_object({}) do |sample_name, sample_results|
|
|
27
|
-
sample_results[sample_name] ||= {}
|
|
28
|
-
if grouped_challenges[sample_name]
|
|
29
|
-
challenge_results = grouped_challenges[sample_name]
|
|
30
|
-
challenge_results.each do |challenge|
|
|
31
|
-
sample_results[sample_name][challenge.implementor.name] = challenge.result
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
@output.puts YAML.dump(results.to_hash)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def add_implementation_result(example, state)
|
|
42
|
-
validation = Validation.new(
|
|
43
|
-
validated_by: 'polytrix',
|
|
44
|
-
result: state.to_s
|
|
45
|
-
)
|
|
46
|
-
challenge = example.metadata[:polytrix_challenge]
|
|
47
|
-
challenge.result.validations << validation unless challenge.nil? || challenge.result.nil?
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
data/lib/polytrix/rspec.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require 'polytrix'
|
|
2
|
-
begin
|
|
3
|
-
require 'rspec/core'
|
|
4
|
-
require 'rspec/expectations'
|
|
5
|
-
require 'rspec/core/formatters/base_text_formatter'
|
|
6
|
-
rescue LoadError
|
|
7
|
-
raise 'polytrix/rspec requires rspec 2 or later'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
module Polytrix
|
|
11
|
-
module RSpec
|
|
12
|
-
class << self
|
|
13
|
-
def shared_examples(caller) # rubocop:disable MethodLength
|
|
14
|
-
# FIXME: Long method because it's hard to eval in the right context
|
|
15
|
-
caller.instance_eval do
|
|
16
|
-
Polytrix.manifest.suites.each do |suite_name, suite_config|
|
|
17
|
-
describe suite_name do
|
|
18
|
-
samples = suite_config.samples || []
|
|
19
|
-
samples.each do |scenario|
|
|
20
|
-
describe scenario.name do
|
|
21
|
-
Polytrix.implementors.each do |sdk|
|
|
22
|
-
it sdk.name, sdk.name.to_sym => true do | example |
|
|
23
|
-
begin
|
|
24
|
-
skip "#{sdk.name} is not setup" unless File.directory? sdk.basedir
|
|
25
|
-
slug = Polytrix::Challenge.slugify(suite_name, scenario.name, sdk.name)
|
|
26
|
-
challenge = Polytrix.manifest.challenges[slug]
|
|
27
|
-
# sdk.build_challenge suite: suite_name, name: scenario, vars: suite_config.env
|
|
28
|
-
example.metadata[:polytrix_challenge] = challenge
|
|
29
|
-
challenge.exec
|
|
30
|
-
validators = Polytrix::ValidatorRegistry.validators_for challenge
|
|
31
|
-
validators.each do |validator|
|
|
32
|
-
instance_exec challenge, &validator.callback
|
|
33
|
-
end
|
|
34
|
-
rescue Polytrix::FeatureNotImplementedError => e
|
|
35
|
-
skip e.message
|
|
36
|
-
rescue ThreadError => e
|
|
37
|
-
# Extra debug info for ThreadError
|
|
38
|
-
$stderr.puts "ThreadError detected: #{e.message}"
|
|
39
|
-
$stderr.puts "ThreadError backtrace: #{e.backtrace}"
|
|
40
|
-
fail e
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def run_manifest(manifest)
|
|
52
|
-
shared_examples(self)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require 'hashie/dash'
|
|
2
|
-
require 'thor'
|
|
3
|
-
require 'polytrix/core/manifest_section'
|
|
4
|
-
|
|
5
|
-
module Polytrix
|
|
6
|
-
module Runners
|
|
7
|
-
autoload :BuffShellOutExecutor, 'polytrix/runners/buff_shellout_executor'
|
|
8
|
-
autoload :MixlibShellOutExecutor, 'polytrix/runners/mixlib_shellout_executor'
|
|
9
|
-
|
|
10
|
-
class ExecutionResult < Polytrix::ManifestSection
|
|
11
|
-
property :exitstatus, require: true
|
|
12
|
-
property :stdout, required: true
|
|
13
|
-
property :stderr, required: true
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
module Executor
|
|
17
|
-
attr_writer :executor
|
|
18
|
-
attr_accessor :env
|
|
19
|
-
|
|
20
|
-
def executor
|
|
21
|
-
@executor ||= if RUBY_PLATFORM == 'java'
|
|
22
|
-
Polytrix::Runners::BuffShellOutExecutor.new
|
|
23
|
-
else
|
|
24
|
-
Polytrix::Runners::MixlibShellOutExecutor.new
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def execute(command, opts = {})
|
|
29
|
-
opts[:env] = env unless env.nil?
|
|
30
|
-
executor.execute(command, opts)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Polytrix
|
|
2
|
-
module Runners
|
|
3
|
-
class LinuxChallengeRunner < ChallengeRunner
|
|
4
|
-
def script_extension
|
|
5
|
-
'sh'
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def challenge_command(env_file, challenge_script)
|
|
9
|
-
challenge_script = "./#{challenge_script}" unless challenge_script.to_s.start_with? '/'
|
|
10
|
-
if File.exist? 'scripts/wrapper'
|
|
11
|
-
# ". #{env_file} && scripts/wrapper #{challenge_script}"
|
|
12
|
-
"scripts/wrapper #{challenge_script}"
|
|
13
|
-
else
|
|
14
|
-
"#{challenge_script}"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def save_environment_variable(key, value)
|
|
19
|
-
"export #{key}=\"#{value}\""
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module Polytrix
|
|
2
|
-
module Runners
|
|
3
|
-
module Middleware
|
|
4
|
-
class ChangeDirectory
|
|
5
|
-
def initialize(app)
|
|
6
|
-
@app = app
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def call(env)
|
|
10
|
-
sdk_dir = env[:basedir]
|
|
11
|
-
Bundler.with_clean_env do
|
|
12
|
-
Dir.chdir sdk_dir do
|
|
13
|
-
@app.call env
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module Polytrix
|
|
2
|
-
module Runners
|
|
3
|
-
module Middleware
|
|
4
|
-
class FeatureExecutor
|
|
5
|
-
include Polytrix::Core::FileSystemHelper
|
|
6
|
-
def initialize(app)
|
|
7
|
-
@app = app
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def call(env)
|
|
11
|
-
challenge_runner = env[:challenge_runner]
|
|
12
|
-
env_file = env[:env_file]
|
|
13
|
-
source_file = env[:source_file]
|
|
14
|
-
relative_source_file = relativize(source_file, env[:basedir])
|
|
15
|
-
command = challenge_runner.challenge_command(env_file, relative_source_file)
|
|
16
|
-
execution_result = challenge_runner.run_command command
|
|
17
|
-
env[:result] = Result.new(execution_result: execution_result, source_file: env[:source_file].to_s)
|
|
18
|
-
@app.call env
|
|
19
|
-
env[:result]
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
|
|
3
|
-
module Polytrix
|
|
4
|
-
module Runners
|
|
5
|
-
module Middleware
|
|
6
|
-
class SetupEnvVars
|
|
7
|
-
include Polytrix::Core::FileSystemHelper
|
|
8
|
-
|
|
9
|
-
def initialize(app)
|
|
10
|
-
@app = app
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call(env)
|
|
14
|
-
vars = begin
|
|
15
|
-
Polytrix.manifest[:global_env].dup
|
|
16
|
-
rescue
|
|
17
|
-
{}
|
|
18
|
-
end
|
|
19
|
-
vars = vars.merge env[:vars].dup
|
|
20
|
-
|
|
21
|
-
setup_env_vars(env[:name], vars, env[:challenge_runner])
|
|
22
|
-
# env[:env_file] = setup_env_vars(env[:name], vars, env[:challenge_runner])
|
|
23
|
-
@app.call env
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def setup_env_vars(challenge_name, vars, challenge_runner)
|
|
29
|
-
challenge_runner.env = vars.to_hash
|
|
30
|
-
# FileUtils.mkdir_p 'tmp'
|
|
31
|
-
# extension = challenge_runner.script_extension
|
|
32
|
-
# file = File.open(slugify("tmp/#{challenge_name}_vars.#{extension}"), 'w')
|
|
33
|
-
# vars.each do |key, value|
|
|
34
|
-
# file.puts challenge_runner.save_environment_variable(key, value)
|
|
35
|
-
# end
|
|
36
|
-
# file.close
|
|
37
|
-
# file.path
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require 'mixlib/shellout'
|
|
2
|
-
|
|
3
|
-
module Polytrix
|
|
4
|
-
module Runners
|
|
5
|
-
class IOToLog < IO
|
|
6
|
-
def initialize(logger)
|
|
7
|
-
@logger = logger
|
|
8
|
-
@buffer = ''
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def write(string)
|
|
12
|
-
(@buffer + string).lines.each do |line|
|
|
13
|
-
if line.end_with? "\n"
|
|
14
|
-
@buffer = ''
|
|
15
|
-
@logger.info(line.rstrip)
|
|
16
|
-
else
|
|
17
|
-
@buffer = line
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
class MixlibShellOutExecutor
|
|
24
|
-
include Polytrix::DefaultLogger
|
|
25
|
-
|
|
26
|
-
def log_decorator(io, prefix)
|
|
27
|
-
# OutputDecorator.new(io, prefix) unless Polytrix.configuration.suppress_output
|
|
28
|
-
# logger = Logging.logger['polytrix::exec']
|
|
29
|
-
IOToLog.new(logger)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def execute(command, opts)
|
|
33
|
-
prefix = opts.delete :prefix
|
|
34
|
-
shell = Mixlib::ShellOut.new(command, opts)
|
|
35
|
-
shell.live_stream = log_decorator $stdout, prefix
|
|
36
|
-
shell.run_command
|
|
37
|
-
execution_result = ExecutionResult.new exitstatus: shell.exitstatus, stdout: shell.stdout, stderr: shell.stderr
|
|
38
|
-
begin
|
|
39
|
-
shell.error!
|
|
40
|
-
rescue Mixlib::ShellOut::ShellCommandFailed => e
|
|
41
|
-
execution_error = ExecutionError.new(e)
|
|
42
|
-
execution_error.execution_result = execution_result
|
|
43
|
-
raise execution_error
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
execution_result
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
class OutputDecorator
|
|
50
|
-
# Reserve :red, :black, :white
|
|
51
|
-
COLORS = [:green, :yellow, :blue, :magenta, :cyan]
|
|
52
|
-
|
|
53
|
-
def self.next_color
|
|
54
|
-
@next_color ||= 0
|
|
55
|
-
@next_color += 1
|
|
56
|
-
COLORS[@next_color % COLORS.size]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def initialize(real_io, prefix = nil)
|
|
60
|
-
@real_io = real_io
|
|
61
|
-
# @prefix = set_color(prefix, :cyan)
|
|
62
|
-
@prefix = "#{prefix}: " if prefix
|
|
63
|
-
@color = self.class.next_color
|
|
64
|
-
@thor_shell = Thor::Shell::Color.new
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def puts(line)
|
|
68
|
-
line = line.gsub(/^/, @prefix) if @prefix
|
|
69
|
-
@real_io.puts @thor_shell.set_color(line, @color)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def <<(line)
|
|
73
|
-
line = line.gsub(/^/, @prefix) if @prefix
|
|
74
|
-
@real_io << @thor_shell.set_color(line, @color)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def method_missing(meth, *args, &block)
|
|
78
|
-
@real_io.send meth, *args, &block
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
data/lib/polytrix/validations.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'hashie/dash'
|
|
2
|
-
|
|
3
|
-
module Polytrix
|
|
4
|
-
class Validations < Set
|
|
5
|
-
def to_hash
|
|
6
|
-
map do |v|
|
|
7
|
-
v.to_hash
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def to_yaml
|
|
12
|
-
to_hash.to_yaml
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# Hashie Coercion - automatically treat all values as Validation
|
|
16
|
-
def self.coerce(obj)
|
|
17
|
-
data = obj.map do |value|
|
|
18
|
-
Validation.new(value)
|
|
19
|
-
end
|
|
20
|
-
new data
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
data/samples/scripts/wrapper
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module Polytrix
|
|
2
|
-
module Runners
|
|
3
|
-
module Middleware
|
|
4
|
-
describe FeatureExecutor do
|
|
5
|
-
let(:app) { double('Middleware Chain') }
|
|
6
|
-
let(:challenge_runner) { double('ChallengeRunner') }
|
|
7
|
-
subject(:middleware) { described_class.new app }
|
|
8
|
-
|
|
9
|
-
describe '#call' do
|
|
10
|
-
let(:env) do
|
|
11
|
-
{
|
|
12
|
-
basedir: Pathname.new('spec/fixtures'),
|
|
13
|
-
env_file: 'tmp/vars.sh',
|
|
14
|
-
source_file: Pathname.new('spec/fixtures/test.js'),
|
|
15
|
-
command: 'some command to execute',
|
|
16
|
-
challenge_runner: challenge_runner
|
|
17
|
-
}
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
before do
|
|
21
|
-
allow(challenge_runner).to receive(:challenge_command).with(env[:env_file], Pathname.new('test.js')).and_return('some command to execute')
|
|
22
|
-
allow(challenge_runner).to receive(:run_command).with('some command to execute').and_return Polytrix::Result.new(execution_result: 'a', source_file: 'b')
|
|
23
|
-
allow(app).to receive(:call).with(env)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Most of this belongs in the ChallengeRunner...
|
|
27
|
-
xit 'finds the challenge' do
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
xit 'setups the env vars' do
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
xit 'gets the command' do
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'returns a result' do
|
|
37
|
-
expect(middleware.call(env)).to be_an_instance_of Polytrix::Result
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'continues the middleware chain' do
|
|
41
|
-
expect(app).to receive(:call).with env
|
|
42
|
-
middleware.call(env)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Polytrix
|
|
4
|
-
describe Validations do
|
|
5
|
-
describe '#coerce' do
|
|
6
|
-
it 'accepts an array when built via Result' do
|
|
7
|
-
Polytrix::Result.new(
|
|
8
|
-
validations: [
|
|
9
|
-
{ validated_by: 'max', result: 'passed' },
|
|
10
|
-
{ validated_by: 'polytrix', result: 'skipped' }
|
|
11
|
-
]
|
|
12
|
-
)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|