From 87de9524c7da7ff39c3bd7f5af4b2856427470d9 Mon Sep 17 00:00:00 2001 From: "Guilherme J. Tramontina" Date: Fri, 22 May 2015 01:03:11 -0300 Subject: [PATCH 1/3] Bail on first error flag `-b`. --- bin/cutest | 5 +++-- lib/cutest.rb | 9 ++++----- test/run.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/bin/cutest b/bin/cutest index 4f4eda7..84555de 100755 --- a/bin/cutest +++ b/bin/cutest @@ -1,7 +1,7 @@ #!/usr/bin/env ruby if ARGV.empty? - puts "usage: cutest [-v] [-r lib] [-o test] [-s scope] file ..." + puts "usage: cutest [-v] [-b] [-r lib] [-o test] [-s scope] file ..." exit end @@ -12,10 +12,11 @@ files = Clap.run ARGV, "-r" => lambda { |file| require file }, "-o" => lambda { |name| cutest[:only] = name }, "-s" => lambda { |name| cutest[:scope] = name }, + "-b" => lambda { cutest[:bail] = true }, "-v" => lambda { puts Cutest::VERSION } if files.any? success = Cutest.run(Dir[*files]) - + puts exit(1) unless success end diff --git a/lib/cutest.rb b/lib/cutest.rb index 8232469..16e263d 100644 --- a/lib/cutest.rb +++ b/lib/cutest.rb @@ -6,15 +6,14 @@ class Cutest end def self.run(files) - status = files.all? do |file| + test_results = -> (file) do run_file(file) - Process.wait2.last.success? end - puts - - status + cutest[:bail] ? + files.all?(&test_results) : + files.map(&test_results).all? end def self.run_file(file) diff --git a/test/run.rb b/test/run.rb index 9f7b3ac..c1980a7 100644 --- a/test/run.rb +++ b/test/run.rb @@ -100,3 +100,34 @@ assert_equal 0, $?.to_i end + +scope "bail on first error" do + test "exit on the first error" do + expected = ".\n" + + " test: \n" + + " line: assert false\n" + + " file: test/fixtures/outside_block.rb +5\n\n" + + "Cutest::AssertionFailed: expression returned false\n\n" + + out = %x{./bin/cutest -b test/fixtures/outside_block.rb test/fixtures/failure.rb} + + assert_equal(expected, out) + end + + test "don't exit on the first error" do + expected = ".\n" + + " test: \n" + + " line: assert false\n" + + " file: test/fixtures/outside_block.rb +5\n\n" + + "Cutest::AssertionFailed: expression returned false\n" + + "\n" + + " test: failed assertion\n" + + " line: assert false\n" + + " file: test/fixtures/failure.rb +2\n\n" + + "Cutest::AssertionFailed: expression returned false\n\n" + + out = %x{./bin/cutest test/fixtures/outside_block.rb test/fixtures/failure.rb} + + assert_equal(expected, out) + end +end From d22984de1ac26a46c4a0a3a1b761dffd0ae17083 Mon Sep 17 00:00:00 2001 From: "Guilherme J. Tramontina" Date: Fri, 22 May 2015 01:15:49 -0300 Subject: [PATCH 2/3] Update changelog. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2a25e3..a41059b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * `assert` can now receive a custom failure message, which should help write better custom assertions. +* Use `-b` to bail after first test failure + 1.2.2 - 2014-11-05 ================== From efe9cf217bbcde5e861f9ff3ba3ef3e308d53a34 Mon Sep 17 00:00:00 2001 From: "Guilherme J. Tramontina" Date: Fri, 22 May 2015 01:23:04 -0300 Subject: [PATCH 3/3] Update readme. --- README.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index c706bab..115d556 100644 --- a/README.markdown +++ b/README.markdown @@ -7,8 +7,7 @@ Description ----------- Each test file is run in a forked process to avoid shared state. Once a failure -is found, you get a report detailing what failed and how to locate the error -and the rest of the file is skipped. +is found, you get a report detailing what failed and how to locate the error. You can use the `scope` command around tests: it guarantees that no instance variables are shared between tests. @@ -149,6 +148,8 @@ with test helpers, use the `-r` flag: If you want to check which version you are running, try the `-v` flag. +To bail after first test failure, use the `-b` flag. + Installation ------------