polyrun 3.2.0-java
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 +7 -0
- data/CHANGELOG.md +234 -0
- data/CODE_OF_CONDUCT.md +26 -0
- data/CONTRIBUTING.md +23 -0
- data/LICENSE +21 -0
- data/README.md +251 -0
- data/SECURITY.md +25 -0
- data/bin/polyrun +6 -0
- data/docs/QUALITY.md +82 -0
- data/docs/QUALITY_CONFIGURATION.md +95 -0
- data/docs/SETUP_PROFILE.md +139 -0
- data/lib/polyrun/benchmark/pressure/cooker.rb +191 -0
- data/lib/polyrun/benchmark/pressure/process_sample.rb +127 -0
- data/lib/polyrun/benchmark/pressure.rb +144 -0
- data/lib/polyrun/benchmark/profile.rb +191 -0
- data/lib/polyrun/benchmark/report.rb +87 -0
- data/lib/polyrun/cli/benchmark_commands.rb +66 -0
- data/lib/polyrun/cli/ci_shard_hooks.rb +129 -0
- data/lib/polyrun/cli/ci_shard_run_command.rb +177 -0
- data/lib/polyrun/cli/ci_shard_run_parse.rb +68 -0
- data/lib/polyrun/cli/config_command.rb +42 -0
- data/lib/polyrun/cli/coverage_commands.rb +150 -0
- data/lib/polyrun/cli/coverage_merge_io.rb +150 -0
- data/lib/polyrun/cli/database_commands.rb +163 -0
- data/lib/polyrun/cli/default_run.rb +144 -0
- data/lib/polyrun/cli/doctor_command.rb +94 -0
- data/lib/polyrun/cli/env_commands.rb +43 -0
- data/lib/polyrun/cli/failure_commands.rb +99 -0
- data/lib/polyrun/cli/graph_command.rb +68 -0
- data/lib/polyrun/cli/help.rb +83 -0
- data/lib/polyrun/cli/helpers.rb +162 -0
- data/lib/polyrun/cli/hooks_command.rb +97 -0
- data/lib/polyrun/cli/init_command.rb +108 -0
- data/lib/polyrun/cli/mutation_command.rb +67 -0
- data/lib/polyrun/cli/partition_diagnostics.rb +22 -0
- data/lib/polyrun/cli/plan_command.rb +184 -0
- data/lib/polyrun/cli/prepare_command.rb +70 -0
- data/lib/polyrun/cli/prepare_recipe.rb +82 -0
- data/lib/polyrun/cli/quality_commands.rb +65 -0
- data/lib/polyrun/cli/queue_command.rb +161 -0
- data/lib/polyrun/cli/quick_command.rb +13 -0
- data/lib/polyrun/cli/report_commands.rb +108 -0
- data/lib/polyrun/cli/run_queue_command.rb +127 -0
- data/lib/polyrun/cli/run_shards_command.rb +164 -0
- data/lib/polyrun/cli/run_shards_parallel_children.rb +112 -0
- data/lib/polyrun/cli/run_shards_parallel_wait.rb +252 -0
- data/lib/polyrun/cli/run_shards_plan_boot_phases.rb +207 -0
- data/lib/polyrun/cli/run_shards_plan_options.rb +74 -0
- data/lib/polyrun/cli/run_shards_planning.rb +123 -0
- data/lib/polyrun/cli/run_shards_run.rb +171 -0
- data/lib/polyrun/cli/run_shards_worker_interrupt.rb +101 -0
- data/lib/polyrun/cli/skip_env.rb +34 -0
- data/lib/polyrun/cli/spec_quality_commands.rb +149 -0
- data/lib/polyrun/cli/start_bootstrap.rb +126 -0
- data/lib/polyrun/cli/timing_command.rb +31 -0
- data/lib/polyrun/cli/tool_options.rb +48 -0
- data/lib/polyrun/cli/validate_command.rb +26 -0
- data/lib/polyrun/cli.rb +272 -0
- data/lib/polyrun/config/dotted_path.rb +21 -0
- data/lib/polyrun/config/effective.rb +82 -0
- data/lib/polyrun/config/resolver.rb +114 -0
- data/lib/polyrun/config/schema.rb +39 -0
- data/lib/polyrun/config/suite.rb +109 -0
- data/lib/polyrun/config/tool_defaults.rb +42 -0
- data/lib/polyrun/config/tool_validation.rb +79 -0
- data/lib/polyrun/config/tools.rb +120 -0
- data/lib/polyrun/config.rb +97 -0
- data/lib/polyrun/coverage/cobertura_zero_lines.rb +32 -0
- data/lib/polyrun/coverage/collector.rb +169 -0
- data/lib/polyrun/coverage/collector_blob.rb +53 -0
- data/lib/polyrun/coverage/collector_finish.rb +98 -0
- data/lib/polyrun/coverage/collector_fragment_meta.rb +57 -0
- data/lib/polyrun/coverage/config_resolve.rb +131 -0
- data/lib/polyrun/coverage/example_diff.rb +184 -0
- data/lib/polyrun/coverage/example_diff_snapshot.rb +44 -0
- data/lib/polyrun/coverage/example_diff_track_filter.rb +51 -0
- data/lib/polyrun/coverage/file_stats_report.rb +36 -0
- data/lib/polyrun/coverage/filter.rb +22 -0
- data/lib/polyrun/coverage/formatter.rb +137 -0
- data/lib/polyrun/coverage/merge/formatters.rb +188 -0
- data/lib/polyrun/coverage/merge/formatters_html.rb +221 -0
- data/lib/polyrun/coverage/merge/html/_file_list.html.erb +21 -0
- data/lib/polyrun/coverage/merge/html/_file_section.html.erb +26 -0
- data/lib/polyrun/coverage/merge/html/_groups_table.html.erb +18 -0
- data/lib/polyrun/coverage/merge/html/_overview.html.erb +47 -0
- data/lib/polyrun/coverage/merge/html/report.css +147 -0
- data/lib/polyrun/coverage/merge/html/report.js +48 -0
- data/lib/polyrun/coverage/merge/html/template.html.erb +30 -0
- data/lib/polyrun/coverage/merge.rb +160 -0
- data/lib/polyrun/coverage/merge_fragment_meta.rb +58 -0
- data/lib/polyrun/coverage/merge_merge_two.rb +168 -0
- data/lib/polyrun/coverage/merge_native.rb +39 -0
- data/lib/polyrun/coverage/rails.rb +126 -0
- data/lib/polyrun/coverage/reporting.rb +41 -0
- data/lib/polyrun/coverage/result.rb +18 -0
- data/lib/polyrun/coverage/track_files.rb +150 -0
- data/lib/polyrun/data/cached_fixtures.rb +122 -0
- data/lib/polyrun/data/factory_counts.rb +48 -0
- data/lib/polyrun/data/factory_instrumentation.rb +50 -0
- data/lib/polyrun/data/fixtures.rb +68 -0
- data/lib/polyrun/data/parallel_provisioning.rb +93 -0
- data/lib/polyrun/data/snapshot.rb +84 -0
- data/lib/polyrun/database/clone_shards.rb +106 -0
- data/lib/polyrun/database/provision.rb +83 -0
- data/lib/polyrun/database/shard.rb +64 -0
- data/lib/polyrun/database/url_builder/connection/infer.rb +53 -0
- data/lib/polyrun/database/url_builder/connection/url_builders.rb +43 -0
- data/lib/polyrun/database/url_builder/connection.rb +191 -0
- data/lib/polyrun/database/url_builder/template_prepare.rb +21 -0
- data/lib/polyrun/database/url_builder.rb +188 -0
- data/lib/polyrun/debug.rb +81 -0
- data/lib/polyrun/env/ci.rb +65 -0
- data/lib/polyrun/error.rb +3 -0
- data/lib/polyrun/export/csv.rb +25 -0
- data/lib/polyrun/export/markdown.rb +47 -0
- data/lib/polyrun/graph/client.rb +64 -0
- data/lib/polyrun/graph/error.rb +13 -0
- data/lib/polyrun/graph/index.rb +75 -0
- data/lib/polyrun/graph/inspect.rb +58 -0
- data/lib/polyrun/graph/plan.rb +134 -0
- data/lib/polyrun/graph/planner.rb +117 -0
- data/lib/polyrun/graph/syntax.rb +114 -0
- data/lib/polyrun/graph/transaction.rb +81 -0
- data/lib/polyrun/graph/worker.rb +55 -0
- data/lib/polyrun/graph/workspace.rb +117 -0
- data/lib/polyrun/hooks/dsl.rb +128 -0
- data/lib/polyrun/hooks/shell_runner.rb +33 -0
- data/lib/polyrun/hooks/worker_runner.rb +27 -0
- data/lib/polyrun/hooks/worker_shell.rb +50 -0
- data/lib/polyrun/hooks.rb +190 -0
- data/lib/polyrun/log.rb +86 -0
- data/lib/polyrun/minitest_support.rb +60 -0
- data/lib/polyrun/mutation/candidates.rb +91 -0
- data/lib/polyrun/mutation/operators.rb +51 -0
- data/lib/polyrun/mutation/runner.rb +133 -0
- data/lib/polyrun/mutation/subjects.rb +88 -0
- data/lib/polyrun/partition/constraints.rb +80 -0
- data/lib/polyrun/partition/hrw.rb +70 -0
- data/lib/polyrun/partition/min_heap.rb +64 -0
- data/lib/polyrun/partition/paths.rb +175 -0
- data/lib/polyrun/partition/paths_build.rb +141 -0
- data/lib/polyrun/partition/plan.rb +250 -0
- data/lib/polyrun/partition/plan_lpt.rb +91 -0
- data/lib/polyrun/partition/plan_sharding.rb +56 -0
- data/lib/polyrun/partition/reports.rb +139 -0
- data/lib/polyrun/partition/stable_shuffle.rb +18 -0
- data/lib/polyrun/partition/suite.rb +120 -0
- data/lib/polyrun/partition/timing_diagnostics.rb +138 -0
- data/lib/polyrun/partition/timing_keys.rb +86 -0
- data/lib/polyrun/prepare/artifacts.rb +40 -0
- data/lib/polyrun/prepare/assets.rb +64 -0
- data/lib/polyrun/process_stdio.rb +96 -0
- data/lib/polyrun/quality/command.rb +84 -0
- data/lib/polyrun/quality/measure.rb +38 -0
- data/lib/polyrun/quality/observe.rb +53 -0
- data/lib/polyrun/quality/observe_hook.rb +103 -0
- data/lib/polyrun/quality/sandbox.rb +70 -0
- data/lib/polyrun/queue/duration.rb +30 -0
- data/lib/polyrun/queue/file_store.rb +413 -0
- data/lib/polyrun/queue/file_store_intent.rb +188 -0
- data/lib/polyrun/queue/file_store_pending.rb +48 -0
- data/lib/polyrun/queue/worker_loop.rb +73 -0
- data/lib/polyrun/quick/assertions.rb +32 -0
- data/lib/polyrun/quick/config.rb +56 -0
- data/lib/polyrun/quick/errors.rb +6 -0
- data/lib/polyrun/quick/example_group.rb +111 -0
- data/lib/polyrun/quick/example_runner.rb +129 -0
- data/lib/polyrun/quick/matchers.rb +159 -0
- data/lib/polyrun/quick/matchers_predicates.rb +122 -0
- data/lib/polyrun/quick/reporter.rb +76 -0
- data/lib/polyrun/quick/runner.rb +224 -0
- data/lib/polyrun/quick.rb +1 -0
- data/lib/polyrun/railtie.rb +7 -0
- data/lib/polyrun/reporting/failure_merge.rb +171 -0
- data/lib/polyrun/reporting/junit.rb +126 -0
- data/lib/polyrun/reporting/junit_emit.rb +58 -0
- data/lib/polyrun/reporting/junit_report.rb +87 -0
- data/lib/polyrun/reporting/rspec_failure_fragment_formatter.rb +95 -0
- data/lib/polyrun/reporting/rspec_junit.rb +39 -0
- data/lib/polyrun/rspec_support/active_record_timeout_recovery.rb +51 -0
- data/lib/polyrun/rspec_support/example_debug.rb +167 -0
- data/lib/polyrun/rspec_support/example_debug_instrumentation.rb +73 -0
- data/lib/polyrun/rspec_support/sharded_formatter_compat.rb +57 -0
- data/lib/polyrun/rspec_support.rb +110 -0
- data/lib/polyrun/spec_quality/config.rb +139 -0
- data/lib/polyrun/spec_quality/fragment.rb +39 -0
- data/lib/polyrun/spec_quality/merge.rb +78 -0
- data/lib/polyrun/spec_quality/minitest_hook.rb +42 -0
- data/lib/polyrun/spec_quality/plan_loader.rb +47 -0
- data/lib/polyrun/spec_quality/profile.rb +102 -0
- data/lib/polyrun/spec_quality/report.rb +363 -0
- data/lib/polyrun/spec_quality/rspec_hook.rb +55 -0
- data/lib/polyrun/spec_quality/sql_counter.rb +34 -0
- data/lib/polyrun/spec_quality.rb +212 -0
- data/lib/polyrun/sus_support.rb +55 -0
- data/lib/polyrun/templates/POLYRUN.md +51 -0
- data/lib/polyrun/templates/ci_matrix.polyrun.yml +22 -0
- data/lib/polyrun/templates/minimal_gem.polyrun.yml +13 -0
- data/lib/polyrun/templates/polyrun_hooks_spec_quality.rb +12 -0
- data/lib/polyrun/templates/polyrun_spec_quality.yml +20 -0
- data/lib/polyrun/templates/rails_prepare.polyrun.yml +51 -0
- data/lib/polyrun/templates/rails_prepare_task.rake +16 -0
- data/lib/polyrun/timing/merge.rb +36 -0
- data/lib/polyrun/timing/rspec_example_formatter.rb +60 -0
- data/lib/polyrun/timing/stats.rb +76 -0
- data/lib/polyrun/timing/summary.rb +78 -0
- data/lib/polyrun/timing/variance_report.rb +51 -0
- data/lib/polyrun/version.rb +3 -0
- data/lib/polyrun/worker_output.rb +181 -0
- data/lib/polyrun/worker_output_forwarders.rb +94 -0
- data/lib/polyrun/worker_ping.rb +77 -0
- data/lib/polyrun.rb +59 -0
- data/polyrun.gemspec +49 -0
- data/sig/polyrun/cli.rbs +6 -0
- data/sig/polyrun/config.rbs +20 -0
- data/sig/polyrun/debug.rbs +12 -0
- data/sig/polyrun/log.rbs +12 -0
- data/sig/polyrun/minitest_support.rbs +7 -0
- data/sig/polyrun/quick.rbs +19 -0
- data/sig/polyrun/rspec_support.rbs +21 -0
- data/sig/polyrun/sus_support.rbs +7 -0
- data/sig/polyrun/worker_output.rbs +11 -0
- data/sig/polyrun/worker_ping.rbs +10 -0
- data/sig/polyrun.rbs +11 -0
- metadata +463 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require_relative "errors"
|
|
2
|
+
require_relative "matchers_predicates"
|
|
3
|
+
|
|
4
|
+
module Polyrun
|
|
5
|
+
module Quick
|
|
6
|
+
# Minimal +expect(x).to …+ / +expect { }.to …+ chain without external gems.
|
|
7
|
+
class Expectation
|
|
8
|
+
def initialize(actual)
|
|
9
|
+
@actual = actual
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to(matcher)
|
|
13
|
+
return if matcher.matches?(@actual)
|
|
14
|
+
|
|
15
|
+
raise AssertionFailed, matcher.failure_message(@actual)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def not_to(matcher)
|
|
19
|
+
return if matcher.does_not_match?(@actual)
|
|
20
|
+
|
|
21
|
+
raise AssertionFailed, matcher.failure_message_when_negated(@actual)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module Matchers
|
|
26
|
+
include MatchersPredicates
|
|
27
|
+
|
|
28
|
+
def expect(actual = nil, &block)
|
|
29
|
+
Expectation.new(block_given? ? block : actual)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def eq(expected)
|
|
33
|
+
EqMatcher.new(expected)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def be_truthy
|
|
37
|
+
TruthyMatcher.new
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def be_falsey
|
|
41
|
+
FalseyMatcher.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def include(*expected)
|
|
45
|
+
IncludeMatcher.new(expected)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def match(pattern)
|
|
49
|
+
RegexMatcher.new(pattern)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class EqMatcher
|
|
54
|
+
def initialize(expected)
|
|
55
|
+
@expected = expected
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def matches?(actual)
|
|
59
|
+
@expected == actual
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def does_not_match?(actual)
|
|
63
|
+
!matches?(actual)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def failure_message(actual)
|
|
67
|
+
"expected #{@expected.inspect}, got #{actual.inspect}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def failure_message_when_negated(actual)
|
|
71
|
+
"expected #{actual.inspect} not to eq #{@expected.inspect}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class TruthyMatcher
|
|
76
|
+
def matches?(actual)
|
|
77
|
+
!!actual
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def does_not_match?(actual)
|
|
81
|
+
!matches?(actual)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def failure_message(actual)
|
|
85
|
+
"expected truthy, got #{actual.inspect}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def failure_message_when_negated(actual)
|
|
89
|
+
"expected falsey, got #{actual.inspect}"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class FalseyMatcher
|
|
94
|
+
def matches?(actual)
|
|
95
|
+
!actual
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def does_not_match?(actual)
|
|
99
|
+
!matches?(actual)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def failure_message(actual)
|
|
103
|
+
"expected falsey, got #{actual.inspect}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def failure_message_when_negated(actual)
|
|
107
|
+
"expected truthy, got #{actual.inspect}"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class IncludeMatcher
|
|
112
|
+
def initialize(expected_parts)
|
|
113
|
+
@expected_parts = expected_parts
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def matches?(actual)
|
|
117
|
+
return false unless actual.respond_to?(:include?)
|
|
118
|
+
|
|
119
|
+
@expected_parts.all? { |part| actual.include?(part) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def does_not_match?(actual)
|
|
123
|
+
!matches?(actual)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def failure_message(actual)
|
|
127
|
+
"expected #{actual.inspect} to include #{@expected_parts.map(&:inspect).join(", ")}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def failure_message_when_negated(actual)
|
|
131
|
+
"expected #{actual.inspect} not to include #{@expected_parts.map(&:inspect).join(", ")}"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
class RegexMatcher
|
|
136
|
+
def initialize(pattern)
|
|
137
|
+
@pattern = pattern
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def matches?(actual)
|
|
141
|
+
return false unless actual.respond_to?(:to_s)
|
|
142
|
+
|
|
143
|
+
@pattern === actual.to_s
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def does_not_match?(actual)
|
|
147
|
+
!matches?(actual)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def failure_message(actual)
|
|
151
|
+
"expected #{actual.inspect} to match #{@pattern.inspect}"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def failure_message_when_negated(actual)
|
|
155
|
+
"expected #{actual.inspect} not to match #{@pattern.inspect}"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Quick
|
|
3
|
+
# Predicate-style matchers (+be ==+, +be_a+, +raise_exception+) for Quick expectations.
|
|
4
|
+
module MatchersPredicates
|
|
5
|
+
def be
|
|
6
|
+
BeMatcher.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def be_a(klass)
|
|
10
|
+
BeAMatcher.new(klass)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
alias_method :be_kind_of, :be_a
|
|
14
|
+
|
|
15
|
+
def raise_exception(exception_class = StandardError, message: nil)
|
|
16
|
+
RaiseExceptionMatcher.new(exception_class, message: message)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class BeMatcher
|
|
21
|
+
def ==(other)
|
|
22
|
+
EqMatcher.new(other)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def >(other)
|
|
26
|
+
CompareMatcher.new(:>, other)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def >=(other)
|
|
30
|
+
CompareMatcher.new(:>=, other)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def <(other)
|
|
34
|
+
CompareMatcher.new(:<, other)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def <=(other)
|
|
38
|
+
CompareMatcher.new(:<=, other)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class CompareMatcher
|
|
43
|
+
def initialize(op, expected)
|
|
44
|
+
@op = op
|
|
45
|
+
@expected = expected
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def matches?(actual)
|
|
49
|
+
actual.public_send(@op, @expected)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def does_not_match?(actual)
|
|
53
|
+
!matches?(actual)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def failure_message(actual)
|
|
57
|
+
"expected #{actual.inspect} #{@op} #{@expected.inspect}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def failure_message_when_negated(actual)
|
|
61
|
+
"expected #{actual.inspect} not #{@op} #{@expected.inspect}"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class BeAMatcher
|
|
66
|
+
def initialize(klass)
|
|
67
|
+
@klass = klass
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def matches?(actual)
|
|
71
|
+
actual.is_a?(@klass)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def does_not_match?(actual)
|
|
75
|
+
!matches?(actual)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def failure_message(actual)
|
|
79
|
+
"expected #{actual.inspect} to be a #{@klass}"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def failure_message_when_negated(actual)
|
|
83
|
+
"expected #{actual.inspect} not to be a #{@klass}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class RaiseExceptionMatcher
|
|
88
|
+
def initialize(exception_class, message: nil)
|
|
89
|
+
@exception_class = exception_class
|
|
90
|
+
@message = message
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def matches?(actual)
|
|
94
|
+
return false unless actual.respond_to?(:call)
|
|
95
|
+
|
|
96
|
+
begin
|
|
97
|
+
actual.call
|
|
98
|
+
false
|
|
99
|
+
rescue @exception_class => e
|
|
100
|
+
return true if @message.nil?
|
|
101
|
+
return true if @message.is_a?(Regexp) && @message.match?(e.message)
|
|
102
|
+
|
|
103
|
+
e.message == @message.to_s
|
|
104
|
+
rescue
|
|
105
|
+
false
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def does_not_match?(actual)
|
|
110
|
+
!matches?(actual)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def failure_message(actual)
|
|
114
|
+
"expected block to raise #{@exception_class}"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def failure_message_when_negated(actual)
|
|
118
|
+
"expected block not to raise #{@exception_class}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Quick
|
|
3
|
+
class Reporter
|
|
4
|
+
SLOW_THRESHOLD_SECONDS = 0.05
|
|
5
|
+
SLOWEST_LIMIT = 5
|
|
6
|
+
|
|
7
|
+
def initialize(out, err, verbose)
|
|
8
|
+
@out = out
|
|
9
|
+
@err = err
|
|
10
|
+
@verbose = verbose
|
|
11
|
+
@passed = 0
|
|
12
|
+
@failed = 0
|
|
13
|
+
@errors = 0
|
|
14
|
+
@timings = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def pass(group, description, duration_seconds: nil)
|
|
18
|
+
@passed += 1
|
|
19
|
+
record_timing(group, description, duration_seconds)
|
|
20
|
+
return unless @verbose
|
|
21
|
+
|
|
22
|
+
@out.puts " ok #{group} #{description}#{duration_suffix(duration_seconds)}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def fail(group, description, exc, duration_seconds: nil)
|
|
26
|
+
@failed += 1
|
|
27
|
+
record_timing(group, description, duration_seconds)
|
|
28
|
+
@err.puts " FAIL #{group} #{description}#{duration_suffix(duration_seconds)}"
|
|
29
|
+
@err.puts " #{exc.message}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def error(group, description, exc, duration_seconds: nil)
|
|
33
|
+
@errors += 1
|
|
34
|
+
record_timing(group, description, duration_seconds)
|
|
35
|
+
@err.puts " ERROR #{group} #{description}#{duration_suffix(duration_seconds)}"
|
|
36
|
+
@err.puts " #{exc.class}: #{exc.message}"
|
|
37
|
+
loc = exc.backtrace&.first
|
|
38
|
+
@err.puts " #{loc}" if loc
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def summary
|
|
42
|
+
total = @passed + @failed + @errors
|
|
43
|
+
@out.puts
|
|
44
|
+
@out.puts "Polyrun::Quick: #{@passed} passed, #{@failed} failed, #{@errors} errors (#{total} examples)"
|
|
45
|
+
print_slowest!
|
|
46
|
+
(@failed + @errors).positive? ? 1 : 0
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def record_timing(group, description, duration_seconds)
|
|
52
|
+
return if duration_seconds.nil?
|
|
53
|
+
|
|
54
|
+
@timings << ["#{group} #{description}".strip, duration_seconds.to_f]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def duration_suffix(duration_seconds)
|
|
58
|
+
return "" if duration_seconds.nil?
|
|
59
|
+
|
|
60
|
+
format(" (%.3fs)", duration_seconds)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def print_slowest!
|
|
64
|
+
slow = @timings.select { |(_, sec)| sec >= SLOW_THRESHOLD_SECONDS }
|
|
65
|
+
.sort_by { |(_, sec)| -sec }
|
|
66
|
+
.first(SLOWEST_LIMIT)
|
|
67
|
+
return if slow.empty?
|
|
68
|
+
|
|
69
|
+
@out.puts "Slowest:"
|
|
70
|
+
slow.each do |label, sec|
|
|
71
|
+
@out.puts format(" %.3fs %s", sec, label)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# rubocop:disable Polyrun/FileLength -- quick runner + suite config + coverage wiring
|
|
2
|
+
require "pathname"
|
|
3
|
+
|
|
4
|
+
require_relative "assertions"
|
|
5
|
+
require_relative "config"
|
|
6
|
+
require_relative "errors"
|
|
7
|
+
require_relative "example_group"
|
|
8
|
+
require_relative "example_runner"
|
|
9
|
+
require_relative "reporter"
|
|
10
|
+
|
|
11
|
+
module Polyrun
|
|
12
|
+
# Micro test runner: nested +describe+ / +with+, +it+ / +test+, +before+ / +after+ / +around+,
|
|
13
|
+
# +let+ / +let!+ / +subject+, +expect().to+ matchers, optional +Polyrun::Quick.capybara!+.
|
|
14
|
+
#
|
|
15
|
+
# Run: +polyrun quick+ or +polyrun quick spec/foo.rb+
|
|
16
|
+
# Optional suite file: +config/polyrun_quick.rb+ (+before_suite+, +after_suite+, +add_load_path+).
|
|
17
|
+
#
|
|
18
|
+
# Coverage: when +POLYRUN_COVERAGE=1+, Covered-style +COVERAGE+, or (+config/polyrun_coverage.yml+ and
|
|
19
|
+
# +POLYRUN_QUICK_COVERAGE=1+), starts {Polyrun::Coverage::Rails} before loading quick files.
|
|
20
|
+
module Quick
|
|
21
|
+
module DSL
|
|
22
|
+
def describe(name, &block)
|
|
23
|
+
Quick.describe(name, &block)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Collector
|
|
28
|
+
attr_reader :groups
|
|
29
|
+
|
|
30
|
+
def initialize
|
|
31
|
+
@groups = []
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def register(group)
|
|
35
|
+
@groups << group
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# rubocop:disable ThreadSafety/ClassAndModuleAttributes, ThreadSafety/ClassInstanceVariable
|
|
40
|
+
class << self
|
|
41
|
+
attr_accessor :collector
|
|
42
|
+
|
|
43
|
+
def capybara!
|
|
44
|
+
@capybara_enabled = true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def capybara?
|
|
48
|
+
@capybara_enabled == true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def reset_capybara_flag!
|
|
52
|
+
@capybara_enabled = false
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def install_spec_quality!(root: nil, output_path: nil)
|
|
56
|
+
require_relative "../spec_quality"
|
|
57
|
+
return unless Polyrun::SpecQuality.enabled?
|
|
58
|
+
|
|
59
|
+
r = root || File.expand_path(Dir.pwd)
|
|
60
|
+
Polyrun::SpecQuality.start!(root: r, output_path: output_path)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def describe(name, &block)
|
|
64
|
+
group = ExampleGroup.new(name)
|
|
65
|
+
group.instance_eval(&block) if block
|
|
66
|
+
(collector || raise(Error, "Polyrun::Quick.describe used outside polyrun quick")).register(group)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
# rubocop:enable ThreadSafety/ClassAndModuleAttributes, ThreadSafety/ClassInstanceVariable
|
|
70
|
+
|
|
71
|
+
class Runner
|
|
72
|
+
def self.run(paths:, out: $stdout, err: $stderr, verbose: false)
|
|
73
|
+
new(out: out, err: err, verbose: verbose).run(paths)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Files Polyrun::Quick would run with no explicit paths (excludes normal RSpec/Minitest files).
|
|
77
|
+
def self.parallel_default_paths(cwd = Dir.pwd)
|
|
78
|
+
base = File.expand_path(cwd)
|
|
79
|
+
globs = [
|
|
80
|
+
File.join(base, "spec", "polyrun_quick", "**", "*.rb"),
|
|
81
|
+
File.join(base, "test", "polyrun_quick", "**", "*.rb"),
|
|
82
|
+
File.join(base, "spec", "**", "*.rb"),
|
|
83
|
+
File.join(base, "test", "**", "*.rb")
|
|
84
|
+
]
|
|
85
|
+
globs.flat_map { |g| Dir.glob(g) }.uniq.reject { |p| quick_path_excluded?(p, base) }.sort
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.quick_path_excluded?(path, base)
|
|
89
|
+
rel = Pathname.new(path).relative_path_from(Pathname.new(base)).to_s
|
|
90
|
+
parts = rel.split(File::SEPARATOR)
|
|
91
|
+
bn = File.basename(path)
|
|
92
|
+
return true if bn.end_with?("_spec.rb", "_test.rb")
|
|
93
|
+
return true if %w[spec_helper.rb rails_helper.rb test_helper.rb].include?(bn)
|
|
94
|
+
return true if parts[0] == "spec" && %w[support fixtures factories].include?(parts[1])
|
|
95
|
+
return true if parts[0] == "test" && %w[support fixtures].include?(parts[1])
|
|
96
|
+
|
|
97
|
+
false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def initialize(out: $stdout, err: $stderr, verbose: false)
|
|
101
|
+
@out = out
|
|
102
|
+
@err = err
|
|
103
|
+
@verbose = verbose
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def run(paths)
|
|
107
|
+
Quick.reset_capybara_flag!
|
|
108
|
+
config = Config.load!(root: Dir.pwd)
|
|
109
|
+
config.apply_load_paths!(root: Dir.pwd)
|
|
110
|
+
status = 2
|
|
111
|
+
suite_hooks = false
|
|
112
|
+
|
|
113
|
+
files = expand_paths(paths)
|
|
114
|
+
if files.empty?
|
|
115
|
+
Polyrun::Log.warn "polyrun quick: no files (pass paths or add Quick files under spec/ or test/, e.g. spec/polyrun_quick/**/*.rb or spec/**/*.rb excluding *_spec.rb / *_test.rb)"
|
|
116
|
+
return 2
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
begin
|
|
120
|
+
config.run_before_suite!
|
|
121
|
+
suite_hooks = true
|
|
122
|
+
quick_start_coverage_if_configured!
|
|
123
|
+
quick_start_spec_quality_if_configured!
|
|
124
|
+
|
|
125
|
+
collector = load_quick_files!(files)
|
|
126
|
+
unless collector
|
|
127
|
+
status = 1
|
|
128
|
+
return 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
reporter = Reporter.new(@out, @err, @verbose)
|
|
132
|
+
run_examples!(collector, reporter)
|
|
133
|
+
status = reporter.summary
|
|
134
|
+
status
|
|
135
|
+
ensure
|
|
136
|
+
config.run_after_suite!(status) if suite_hooks
|
|
137
|
+
Quick.collector = nil
|
|
138
|
+
Quick.reset_capybara_flag!
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def load_quick_files!(files)
|
|
143
|
+
collector = Collector.new
|
|
144
|
+
Quick.collector = collector
|
|
145
|
+
|
|
146
|
+
files.each do |path|
|
|
147
|
+
code = File.read(path)
|
|
148
|
+
loader = Object.new
|
|
149
|
+
loader.extend(DSL)
|
|
150
|
+
loader.instance_eval(code, path, 1)
|
|
151
|
+
rescue SyntaxError, StandardError => e
|
|
152
|
+
Polyrun::Log.warn "polyrun quick: failed to load #{path}: #{e.class}: #{e.message}"
|
|
153
|
+
Quick.collector = nil
|
|
154
|
+
return nil
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Quick.collector = nil
|
|
158
|
+
collector
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def run_examples!(collector, reporter)
|
|
162
|
+
collector.groups.each do |root|
|
|
163
|
+
root.each_example_with_ancestors do |chain, desc, block|
|
|
164
|
+
inner = chain.last
|
|
165
|
+
example_runner = ExampleRunner.new(reporter)
|
|
166
|
+
example_runner.run(
|
|
167
|
+
group_name: inner.full_name,
|
|
168
|
+
description: desc,
|
|
169
|
+
ancestor_chain: chain,
|
|
170
|
+
block: block
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def quick_start_spec_quality_if_configured!
|
|
177
|
+
return unless Polyrun::SpecQuality.spec_quality_requested_for_quick?(Dir.pwd)
|
|
178
|
+
return if Polyrun::SpecQuality.started?
|
|
179
|
+
|
|
180
|
+
require_relative "../spec_quality"
|
|
181
|
+
Polyrun::SpecQuality.start!(
|
|
182
|
+
root: File.expand_path(Dir.pwd)
|
|
183
|
+
)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def quick_start_coverage_if_configured!
|
|
187
|
+
return unless Polyrun::Coverage::Collector.coverage_requested_for_quick?(Dir.pwd)
|
|
188
|
+
return if Polyrun::Coverage::Collector.started?
|
|
189
|
+
|
|
190
|
+
require_relative "../coverage/rails"
|
|
191
|
+
Polyrun::Coverage::Rails.start!(
|
|
192
|
+
root: File.expand_path(Dir.pwd),
|
|
193
|
+
meta: {"command_name" => "polyrun quick"}
|
|
194
|
+
)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def expand_paths(paths)
|
|
198
|
+
return default_globs if paths.nil? || paths.empty?
|
|
199
|
+
|
|
200
|
+
paths.flat_map do |p|
|
|
201
|
+
expanded = File.expand_path(p)
|
|
202
|
+
if File.directory?(expanded)
|
|
203
|
+
Dir.glob(File.join(expanded, "**", "*.rb")).sort
|
|
204
|
+
elsif /[*?\[]/.match?(p)
|
|
205
|
+
Dir.glob(File.expand_path(p)).sort
|
|
206
|
+
elsif File.file?(expanded)
|
|
207
|
+
[expanded]
|
|
208
|
+
else
|
|
209
|
+
[]
|
|
210
|
+
end
|
|
211
|
+
end.uniq
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def default_globs
|
|
215
|
+
Runner.parallel_default_paths(Dir.pwd)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def default_quick_exclude?(path, base)
|
|
219
|
+
Runner.quick_path_excluded?(path, base)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
# rubocop:enable Polyrun/FileLength
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative "quick/runner"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
# Optional Rails integration. Coverage must still be started from +spec_helper.rb+ (before the app loads) via
|
|
3
|
+
# {Polyrun::Coverage::Rails.start!}; this railtie only registers the gem with Rails.
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
railtie_name :polyrun
|
|
6
|
+
end
|
|
7
|
+
end
|