mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement "fail-blank" into runner and report
This commit is contained in:
parent
165178237c
commit
209ef92d3d
3 changed files with 43 additions and 5 deletions
|
@ -15,7 +15,7 @@ def new_failure_result(result_type : Spectator::Result.class = Spectator::Failed
|
||||||
result_type.new(example, elapsed, expectations, error)
|
result_type.new(example, elapsed, expectations, error)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_report(successful_count = 5, failed_count = 5, error_count = 5, pending_count = 5, overhead_time = 1_000_000i64)
|
def new_report(successful_count = 5, failed_count = 5, error_count = 5, pending_count = 5, overhead_time = 1_000_000i64, fail_blank = false)
|
||||||
results = [] of Spectator::Result
|
results = [] of Spectator::Result
|
||||||
successful_count.times { results << new_passing_result }
|
successful_count.times { results << new_passing_result }
|
||||||
failed_count.times { results << new_failure_result }
|
failed_count.times { results << new_failure_result }
|
||||||
|
@ -24,7 +24,7 @@ def new_report(successful_count = 5, failed_count = 5, error_count = 5, pending_
|
||||||
|
|
||||||
example_runtime = results.compact_map(&.as?(Spectator::FinishedResult)).sum(&.elapsed)
|
example_runtime = results.compact_map(&.as?(Spectator::FinishedResult)).sum(&.elapsed)
|
||||||
total_runtime = example_runtime + Time::Span.new(nanoseconds: overhead_time)
|
total_runtime = example_runtime + Time::Span.new(nanoseconds: overhead_time)
|
||||||
Spectator::Report.new(results, total_runtime)
|
Spectator::Report.new(results, total_runtime, fail_blank: fail_blank)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::Report do
|
describe Spectator::Report do
|
||||||
|
@ -43,6 +43,13 @@ describe Spectator::Report do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#examples_ran" do
|
||||||
|
it "is the number of non-skipped examples" do
|
||||||
|
report = new_report(5, 4, 3, 2)
|
||||||
|
report.examples_ran.should eq(12)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#successful_count" do
|
describe "#successful_count" do
|
||||||
it "is the expected value" do
|
it "is the expected value" do
|
||||||
report = new_report(5, 4, 3, 2)
|
report = new_report(5, 4, 3, 2)
|
||||||
|
@ -94,6 +101,31 @@ describe Spectator::Report do
|
||||||
report.failed?.should be_false
|
report.failed?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with fail-blank enabled" do
|
||||||
|
context "when no tests run" do
|
||||||
|
it "is true" do
|
||||||
|
report = new_report(0, 0, 0, 5, fail_blank: true)
|
||||||
|
report.failed?.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when tests run" do
|
||||||
|
context "and there are failures" do
|
||||||
|
it "is true" do
|
||||||
|
report = new_report(5, 4, 3, 2, fail_blank: true)
|
||||||
|
report.failed?.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and there are no failures" do
|
||||||
|
it "is false" do
|
||||||
|
report = new_report(5, 0, 0, 2, fail_blank: true)
|
||||||
|
report.failed?.should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#remaining?" do
|
describe "#remaining?" do
|
||||||
|
|
|
@ -25,7 +25,8 @@ module Spectator
|
||||||
# The *results* are from running the examples in the test suite.
|
# The *results* are from running the examples in the test suite.
|
||||||
# The *runtime* is the total time it took to execute the suite.
|
# The *runtime* is the total time it took to execute the suite.
|
||||||
# The *remaining_count* is the number of tests skipped due to fail-fast.
|
# The *remaining_count* is the number of tests skipped due to fail-fast.
|
||||||
def initialize(@results : Array(Result), @runtime, @remaining_count = 0)
|
# The *fail_blank* flag indicates whether it is a failure if there were no tests run.
|
||||||
|
def initialize(@results : Array(Result), @runtime, @remaining_count = 0, @fail_blank = false)
|
||||||
@results.each do |result|
|
@results.each do |result|
|
||||||
case result
|
case result
|
||||||
when SuccessfulResult
|
when SuccessfulResult
|
||||||
|
@ -46,9 +47,14 @@ module Spectator
|
||||||
@results.size
|
@results.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Number of examples run (not skipped or pending).
|
||||||
|
def examples_ran
|
||||||
|
@successful_count + @failed_count
|
||||||
|
end
|
||||||
|
|
||||||
# Indicates whether the test suite failed.
|
# Indicates whether the test suite failed.
|
||||||
def failed?
|
def failed?
|
||||||
failed_count > 0
|
failed_count > 0 || (@fail_blank && examples_ran == 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates whether there were skipped tests
|
# Indicates whether there were skipped tests
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Spectator
|
||||||
|
|
||||||
# Generate a report and pass it along to the formatter.
|
# Generate a report and pass it along to the formatter.
|
||||||
remaining = @suite.size - results.size
|
remaining = @suite.size - results.size
|
||||||
report = Report.new(results, elapsed, remaining)
|
report = Report.new(results, elapsed, remaining, @config.fail_blank?)
|
||||||
@config.formatter.end_suite(report)
|
@config.formatter.end_suite(report)
|
||||||
|
|
||||||
!report.failed?
|
!report.failed?
|
||||||
|
|
Loading…
Reference in a new issue