Module: Polytrix
- Extended by:
- Core::FileSystemHelper
- Includes:
- DefaultLogger, Logging
- Defined in:
- lib/polytrix/util.rb,
lib/polytrix.rb,
lib/polytrix/cli.rb,
lib/polytrix/color.rb,
lib/polytrix/error.rb,
lib/polytrix/rspec.rb,
lib/polytrix/logger.rb,
lib/polytrix/result.rb,
lib/polytrix/command.rb,
lib/polytrix/logging.rb,
lib/polytrix/version.rb,
lib/polytrix/manifest.rb,
lib/polytrix/challenge.rb,
lib/polytrix/validator.rb,
lib/polytrix/challenges.rb,
lib/polytrix/cli/report.rb,
lib/polytrix/state_file.rb,
lib/polytrix/validation.rb,
lib/polytrix/core/hashie.rb,
lib/polytrix/validations.rb,
lib/polytrix/command/list.rb,
lib/polytrix/command/test.rb,
lib/polytrix/configuration.rb,
lib/polytrix/command/action.rb,
lib/polytrix/command/report.rb,
lib/polytrix/command/rundoc.rb,
lib/polytrix/challenge_result.rb,
lib/polytrix/challenge_runner.rb,
lib/polytrix/core/implementor.rb,
lib/polytrix/runners/executor.rb,
lib/polytrix/rspec/yaml_report.rb,
lib/polytrix/validator_registry.rb,
lib/polytrix/core/string_helpers.rb,
lib/polytrix/core/manifest_section.rb,
lib/polytrix/reports/hash_reporter.rb,
lib/polytrix/reports/json_reporter.rb,
lib/polytrix/reports/yaml_reporter.rb,
lib/polytrix/core/file_system_helper.rb,
lib/polytrix/documentation_generator.rb,
lib/polytrix/documentation/view_helper.rb,
lib/polytrix/reports/markdown_reporter.rb,
lib/polytrix/documentation/code_segmenter.rb,
lib/polytrix/documentation/comment_styles.rb,
lib/polytrix/rspec/documentation_formatter.rb,
lib/polytrix/runners/buff_shellout_executor.rb,
lib/polytrix/runners/linux_challenge_runner.rb,
lib/polytrix/runners/mixlib_shellout_executor.rb,
lib/polytrix/runners/windows_challenge_runner.rb,
lib/polytrix/documentation/helpers/code_helper.rb,
lib/polytrix/runners/middleware/setup_env_vars.rb,
lib/polytrix/runners/middleware/change_directory.rb,
lib/polytrix/runners/middleware/feature_executor.rb
Overview
- Author
-
Fletcher Nichol (<[email protected]>)
Copyright © 2012, 2013, 2014, Fletcher Nichol
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: Color, Command, Core, DefaultLogger, Documentation, Error, Logging, RSpec, Reports, Runners, StringHelpers, Util Classes: ActionFailed, CLI, Challenge, ChallengeFailure, ChallengeResult, ChallengeRunner, Challenges, ClientError, Configuration, Dash, DocumentationGenerator, ExecutionError, FeatureNotImplementedError, Implementor, Logger, Manifest, ManifestSection, Result, StandardError, StateFile, StateFileLoadError, TransientFailure, UserError, Validation, Validations, Validator, ValidatorRegistry
Constant Summary collapse
- VERSION =
'0.1.2'
- RESOURCES_DIR =
File. '../../../resources', __FILE__
Class Attribute Summary collapse
-
.mutex ⇒ Mutex
A common mutex for global coordination.
Class Method Summary collapse
-
.bootstrap(*sdks) ⇒ Object
Invokes the bootstrap action for each SDK.
-
.clone(*sdks) ⇒ Object
Invokes the clone action for each SDK.
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .exec(*files) ⇒ Object
- .find_implementor(file) ⇒ Object
-
.implementors ⇒ Object
The set of Implementors registered with Polytrix.
- .load_tests ⇒ Object
-
.manifest ⇒ Object
The Manifest that describes the test scenarios known to Polytrix.
- .reset ⇒ Object
-
.tty? ⇒ true, false
Returns whether or not standard output is associated with a terminal device (tty).
- .validate(desc, scope = { suite: //, sample: // }, &block) ⇒ Object
-
.verify(implementors = []) ⇒ Object
Runs all of the tests described in the Polytrix.manifest.
-
.with_friendly_errors ⇒ Object
Yields to a code block in order to consistently emit a useful crash/error message and exit appropriately.
Methods included from Core::FileSystemHelper
find_file, recursive_parent_search
Methods included from StringHelpers
Methods included from StringHelpers::ClassMethods
Methods included from DefaultLogger
Methods included from DefaultLogger::ClassMethods
Class Attribute Details
.mutex ⇒ Mutex
Returns a common mutex for global coordination.
38 39 40 |
# File 'lib/polytrix.rb', line 38 def mutex @mutex end |
Class Method Details
.bootstrap(*sdks) ⇒ Object
Invokes the bootstrap action for each SDK.
76 77 78 79 80 |
# File 'lib/polytrix.rb', line 76 def bootstrap(*sdks) select_implementors(sdks).each do |implementor| implementor.bootstrap end end |
.clone(*sdks) ⇒ Object
Invokes the clone action for each SDK.
68 69 70 71 72 |
# File 'lib/polytrix.rb', line 68 def clone(*sdks) select_implementors(sdks).each do |implementor| implementor.clone end end |
.configuration ⇒ Object
141 142 143 144 |
# File 'lib/polytrix.rb', line 141 def configuration fail "configuration doesn't take a block, use configure" if block_given? @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
147 148 149 |
# File 'lib/polytrix.rb', line 147 def configure yield(configuration) end |
.exec(*files) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/polytrix.rb', line 82 def exec(*files) # files.map do | file | # Dir.glob file # end.flatten files.each do | file | implementor = find_implementor(file) # || exec_options[:default_implementor] extension = File.extname(file) name = File.basename(file, extension) challenge_data = { name: name, # language: extension, source_file: File.(file, Dir.pwd) } challenge = implementor.build_challenge challenge_data challenge.exec end end |
.find_implementor(file) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/polytrix.rb', line 55 def find_implementor(file) existing_implementor = recursive_parent_search(File.dirname(file)) do |path| implementors.find do |implementor| File.absolute_path(implementor.basedir) == File.absolute_path(path) end end return existing_implementor if existing_implementor nil end |
.implementors ⇒ Object
The set of Implementors registered with Polytrix.
51 52 53 |
# File 'lib/polytrix.rb', line 51 def implementors manifest.implementors.values end |
.load_tests ⇒ Object
112 113 114 115 |
# File 'lib/polytrix.rb', line 112 def load_tests manifest.build_challenges Polytrix::RSpec.run_manifest(manifest) end |
.manifest ⇒ Object
The Manifest that describes the test scenarios known to Polytrix.
46 47 48 |
# File 'lib/polytrix.rb', line 46 def manifest configuration.manifest end |
.reset ⇒ Object
40 41 42 43 |
# File 'lib/polytrix.rb', line 40 def reset @configuration = nil Polytrix::ValidatorRegistry.clear end |
.tty? ⇒ true, false
Returns whether or not standard output is associated with a terminal device (tty).
155 156 157 |
# File 'lib/polytrix.rb', line 155 def tty? $stdout.tty? end |
.validate(desc, scope = { suite: //, sample: // }, &block) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/polytrix.rb', line 104 def validate(desc, scope = { suite: //, sample: // }, &block) fail ArgumentError 'You must pass block' unless block_given? validator = Polytrix::Validator.new(desc, scope, &block) Polytrix::ValidatorRegistry.register validator validator end |
.verify(implementors = []) ⇒ Object
Runs all of the tests described in the manifest
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/polytrix.rb', line 118 def verify(implementors = []) test_env = ENV['TEST_ENV_NUMBER'].to_i = %W[--color -f documentation -f Polytrix::RSpec::YAMLReport -o reports/test_report#{test_env}.yaml] .concat Polytrix.configuration..split if Polytrix.configuration. unless implementors.empty? target_sdks = implementors.map(&:name) Polytrix.implementors.map(&:name).each do |sdk| # We don't have an "or" for tags, so it's easier to exclude than include multiple tags .concat %W[-t ~#{sdk.to_sym}] unless target_sdks.include? sdk end end load_tests logger.info "polytrix:test\tTesting with rspec options: #{.join ' '}" ::RSpec::Core::Runner.run logger.info "polytrix:test\tTest execution completed" end |
.with_friendly_errors ⇒ Object
Yields to a code block in order to consistently emit a useful crash/error message and exit appropriately. There are two primary failure conditions: an expected challenge failure, and any other unexpected failures.
Note This method may call ‘Kernel.exit` so may not return if the yielded code block raises an exception.
## Challenge Failure
This is an expected failure scenario which could happen if an challenge couldn’t be created, a Chef run didn’t successfully converge, a post-convergence test suite failed, etc. In other words, you can count on encountering these failures all the time–this is Polytrix’s worldview: crash early and often. In this case a cleanly formatted exception is written to ‘STDERR` and the exception message is written to the common Polytrix file logger.
## Unexpected Failure
All other forms of ‘Polytrix::Error` exceptions are considered unexpected or unplanned exceptions, typically from user configuration errors, driver or provisioner coding issues or bugs, or internal code issues. Given a stable release of Polytrix and a solid set of drivers and provisioners, the most likely cause of this is user configuration error originating in the `.polytrix.yml` setup. For this reason, the exception is written to `STDERR`, a full formatted exception trace is written to the common Polytrix file logger, and a message is displayed on `STDERR` to the user informing them to check the log files and check their configuration with the `polytrix diagnose` subcommand.
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/polytrix/error.rb', line 134 def self.with_friendly_errors yield rescue Polytrix::ChallengeFailure => e Polytrix.mutex.synchronize do handle_challenge_failure(e) end exit 10 rescue Polytrix::Error => e Polytrix.mutex.synchronize do handle_error(e) end exit 20 end |