From 31d58fea25f2e00b779ef14cd34bf9e082839a05 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 13:21:37 -0600 Subject: [PATCH] Add "fail-blank" config option --- .../command_line_arguments_config_source.cr | 1 + src/spectator/config.cr | 4 ++++ src/spectator/config_builder.cr | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/spectator/command_line_arguments_config_source.cr b/src/spectator/command_line_arguments_config_source.cr index e544d10..92982d1 100644 --- a/src/spectator/command_line_arguments_config_source.cr +++ b/src/spectator/command_line_arguments_config_source.cr @@ -15,6 +15,7 @@ module Spectator OptionParser.parse(@args) do |parser| parser.on("-v", "--verbose", "Verbose output using document formatter") { builder.formatter = Formatting::DocumentFormatter.new } parser.on("-f", "--fail-fast", "Stop testing on first failure") { builder.fail_fast } + parser.on("-b", "--fail-blank", "Fail if there are no examples") { builder.fail_blank } parser.on("-h", "--help", "Show this help") { puts parser; exit } parser.on("-e", "--example STRING", "Run examples whose full nested names include STRING") { |pattern| raise NotImplementedError.new("-e") } parser.on("-l", "--line LINE", "Run examples whose line matches LINE") { |line| raise NotImplementedError.new("-l") } diff --git a/src/spectator/config.cr b/src/spectator/config.cr index 1524ace..64dc143 100644 --- a/src/spectator/config.cr +++ b/src/spectator/config.cr @@ -7,10 +7,14 @@ module Spectator # Indicates whether the test should abort on first failure. getter? fail_fast : Bool + # Indicates whether the test should fail if there are no examples. + getter? fail_blank : Bool + # Creates a new configuration. def initialize(builder) @formatter = builder.formatter @fail_fast = builder.fail_fast? + @fail_blank = builder.fail_blank? end end end diff --git a/src/spectator/config_builder.cr b/src/spectator/config_builder.cr index b26e6ac..22c93d2 100644 --- a/src/spectator/config_builder.cr +++ b/src/spectator/config_builder.cr @@ -10,6 +10,7 @@ module Spectator @formatter : Formatting::Formatter? = nil @fail_fast = false + @fail_blank = false # Sets the formatter to use for reporting test progress and results. def formatter=(formatter : Formatting::Formatter) @@ -44,6 +45,22 @@ module Spectator @fail_fast end + # Enables fail-blank mode (fail on no tests). + def fail_blank + self.fail_blank = true + end + + # Sets teh fail-blank mode. + def fail_blank=(flag) + @fail_blank = flag + end + + # Indicates whether fail-fast mode is enabled. + # That is, it is a failure if there are no tests. + def fail_blank? + @fail_blank + end + # Creates a configuration. def build : Config Config.new(self)