cutest 1.1.0.rc1 → 1.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/bin/cutest +1 -1
  2. data/cutest.gemspec +1 -1
  3. data/lib/cutest.rb +51 -10
  4. data/test/run.rb +8 -3
  5. metadata +3 -3
data/bin/cutest CHANGED
@@ -68,6 +68,6 @@ files = Cutest::Clap.run ARGV,
68
68
 
69
69
  case files.size
70
70
  when 0 then exit
71
- when 1 then Cutest.run_file(files.first)
71
+ when 1 then Cutest.run_file(files.first) && puts
72
72
  else Cutest.run(Dir[*files])
73
73
  end
data/cutest.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cutest"
3
- s.version = "1.1.0.rc1"
3
+ s.version = "1.1.0.rc2"
4
4
  s.summary = "Forking tests."
5
5
  s.description = "Run tests in separate processes to avoid shared state."
6
6
  s.authors = ["Damian Janowski", "Michel Martens"]
data/lib/cutest.rb CHANGED
@@ -1,6 +1,30 @@
1
1
  class Cutest
2
- VERSION = "1.1.0.rc1"
2
+ VERSION = "1.1.0.rc2"
3
3
  REQUIREMENTS = []
4
+ FILTER = %r[/#{RUBY_ENGINE}[-/]([0-9\.])+]
5
+ CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
6
+
7
+ module Color
8
+ def self.title(str)
9
+ "\033[01;36m#{str}"
10
+ end
11
+
12
+ def self.exception(str)
13
+ "\033[1;33m#{str}"
14
+ end
15
+
16
+ def self.code(str)
17
+ "\033[00m#{str}"
18
+ end
19
+
20
+ def self.location(str)
21
+ "\033[01;30m#{str}"
22
+ end
23
+
24
+ def self.reset
25
+ "\033[00m"
26
+ end
27
+ end
4
28
 
5
29
  def self.flags
6
30
  "-r #{REQUIREMENTS.join(" ")}" if REQUIREMENTS.any?
@@ -9,6 +33,8 @@ class Cutest
9
33
  def self.run(files)
10
34
  files.each do |file|
11
35
  %x{cutest #{flags} #{file}}.chomp.display
36
+
37
+ break unless $?.success?
12
38
  end
13
39
 
14
40
  puts
@@ -21,20 +47,35 @@ class Cutest
21
47
  load(file)
22
48
 
23
49
  rescue LoadError, SyntaxError
24
- puts ["\n", error([file, $!.message])]
25
- exit
50
+ display_error
51
+ exit 1
26
52
 
27
53
  rescue Exception
28
- fn, ln = $!.backtrace.first.split(":")
29
- message = File.readlines(fn)[ln.to_i - 1]
30
- puts "\n#{error(message.strip)} # #{$!.message}\n#{fn} +#{ln}"
54
+ display_error
55
+
56
+ trace = $!.backtrace
57
+ pivot = trace.index { |line| line.match(file) }
58
+ other = trace[0..pivot].select { |line| line !~ FILTER }
59
+ other.reverse.each { |trace| display_trace(trace) }
60
+ exit 1
31
61
  end
62
+ end
32
63
 
33
- puts
64
+ def self.code(fn, ln)
65
+ CACHE[fn][ln.to_i - 1].strip
66
+ end
67
+
68
+ def self.display_error
69
+ print Color.title("\n\n#{$!.class}: ")
70
+ print Color.exception("#{$!.message}\n\n")
34
71
  end
35
72
 
36
- def self.error(e)
37
- "\033[01;36mException: \033[01;33m#{e}\033[00m"
73
+ def self.display_trace(line)
74
+ fn, ln = line.split(":")
75
+
76
+ print Color.code("- #{code(fn, ln)}")
77
+ print Color.location(" #{fn} +#{ln}\n")
78
+ print Color.reset
38
79
  end
39
80
 
40
81
  class AssertionFailed < StandardError
@@ -115,7 +156,7 @@ private
115
156
 
116
157
  # Assert that value is not nil or false.
117
158
  def assert(value)
118
- flunk("assertion failed") unless value
159
+ flunk("expression returned #{value.inspect}") unless value
119
160
  success
120
161
  end
121
162
 
data/test/run.rb CHANGED
@@ -21,7 +21,9 @@ test "output of successful run" do
21
21
  end
22
22
 
23
23
  test "output of failed run" do
24
- expected = "\n\e[01;36mException: \e[01;33massert false\e[00m # assertion failed\ntest/fixtures/failure.rb +2\n\n"
24
+ expected = "\e[01;36m\n\nCutest::AssertionFailed: \e[1;33mexpression retur" +
25
+ "ned false\n\n\e[00m- assert false\e[01;30m test/fixtures/failu" +
26
+ "re.rb +2\n\e[00m\n"
25
27
 
26
28
  stdout, stderr = capture do
27
29
  Cutest.run(Dir["test/fixtures/failure.rb"])
@@ -31,7 +33,8 @@ test "output of failed run" do
31
33
  end
32
34
 
33
35
  test "output of failed run" do
34
- expected = "\n\e[01;36mException: \e[01;33mraise \"Oops\"\e[00m # Oops\ntest/fixtures/exception.rb +2\n\n"
36
+ expected = "\e[01;36m\n\nRuntimeError: \e[1;33mOops\n\n\e[00m- raise \"Oop" +
37
+ "s\"\e[01;30m test/fixtures/exception.rb +2\n\e[00m\n"
35
38
 
36
39
  stdout, stderr = capture do
37
40
  Cutest.run(Dir["test/fixtures/exception.rb"])
@@ -41,7 +44,9 @@ test "output of failed run" do
41
44
  end
42
45
 
43
46
  test "output of custom assertion" do
44
- expected = "\n\e[01;36mException: \e[01;33massert_empty \"foo\"\e[00m # not empty\ntest/fixtures/fail_custom_assertion.rb +7\n\n"
47
+ expected = "\e[01;36m\n\nCutest::AssertionFailed: \e[1;33mnot empty\n\n\e[" +
48
+ "00m- assert_empty \"foo\"\e[01;30m test/fixtures/fail_custom_a" +
49
+ "ssertion.rb +7\n\e[00m\n"
45
50
 
46
51
  stdout, stderr = capture do
47
52
  Cutest.run(Dir["test/fixtures/fail_custom_assertion.rb"])
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cutest
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.1.0.rc1
5
+ version: 1.1.0.rc2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Damian Janowski
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-22 00:00:00 Z
14
+ date: 2011-05-07 00:00:00 Z
15
15
  dependencies: []
16
16
 
17
17
  description: Run tests in separate processes to avoid shared state.
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements: []
62
62
 
63
63
  rubyforge_project:
64
- rubygems_version: 1.7.2
64
+ rubygems_version: 1.8.1
65
65
  signing_key:
66
66
  specification_version: 3
67
67
  summary: Forking tests.