cutest 1.1.3 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cutest CHANGED
@@ -1,4 +1,6 @@
1
- require File.expand_path("../lib/cutest", File.dirname(__FILE__))
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/cutest"
2
4
 
3
5
  if ARGV.empty?
4
6
  puts "usage: cutest [-r lib] [-v] file ..."
@@ -61,11 +63,9 @@ class Cutest
61
63
  end
62
64
 
63
65
  files = Cutest::Clap.run ARGV,
64
- "-r" => lambda { |file| Cutest::REQUIREMENTS.push(file) },
66
+ "-r" => lambda { |file| require file },
65
67
  "-v" => lambda { puts Cutest::VERSION }
66
68
 
67
- case files.size
68
- when 0 then exit
69
- when 1 then Cutest.run_file(files.first) && puts
70
- else Cutest.run(Dir[*files])
69
+ if files.any?
70
+ Cutest.run(Dir[*files])
71
71
  end
data/lib/cutest.rb CHANGED
@@ -1,38 +1,13 @@
1
1
  class Cutest
2
- VERSION = "1.1.3"
3
- REQUIREMENTS = []
2
+ VERSION = "1.2.0.rc1"
4
3
  FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
5
4
  CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
6
5
 
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
28
-
29
- def self.flags
30
- "-r #{REQUIREMENTS.join(" ")}" if REQUIREMENTS.any?
31
- end
32
-
33
6
  def self.run(files)
34
7
  files.each do |file|
35
- %x{cutest #{flags} #{file}}.chomp.display
8
+ run_file(file)
9
+
10
+ Process.wait
36
11
 
37
12
  break unless $?.success?
38
13
  end
@@ -41,23 +16,29 @@ class Cutest
41
16
  end
42
17
 
43
18
  def self.run_file(file)
44
- begin
45
- REQUIREMENTS.each { |r| require r }
19
+ fork do
20
+ begin
21
+ load(file)
22
+
23
+ rescue LoadError, SyntaxError
24
+ display_error
25
+ exit 1
46
26
 
47
- load(file)
27
+ rescue StandardError
28
+ display_error
48
29
 
49
- rescue LoadError, SyntaxError
50
- display_error
51
- exit 1
30
+ trace = $!.backtrace
31
+ pivot = trace.index { |line| line.match(file) }
52
32
 
53
- rescue Exception
54
- display_error
33
+ if pivot
34
+ other = trace[0..pivot].select { |line| line !~ FILTER }
35
+ other.reverse.each { |trace| display_trace(trace) }
36
+ else
37
+ display_trace(trace.first)
38
+ end
55
39
 
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
40
+ exit 1
41
+ end
61
42
  end
62
43
  end
63
44
 
@@ -66,17 +47,15 @@ class Cutest
66
47
  end
67
48
 
68
49
  def self.display_error
69
- print Color.title("\n\n#{$!.class}: ")
70
- print Color.exception("#{$!.message}\n\n")
71
- print Color.reset
50
+ print "\n\n#{$!.class}: "
51
+ print "#{$!.message}\n\n"
72
52
  end
73
53
 
74
54
  def self.display_trace(line)
75
55
  fn, ln = line.split(":")
76
56
 
77
- print Color.code("- #{code(fn, ln)}")
78
- print Color.location(" #{fn} +#{ln}\n")
79
- print Color.reset
57
+ puts " line: #{code(fn, ln)}"
58
+ puts " file: #{fn} +#{ln}"
80
59
  end
81
60
 
82
61
  class AssertionFailed < StandardError
@@ -0,0 +1 @@
1
+ load("test/fixtures/failure.rb")
data/test/run.rb CHANGED
@@ -1,56 +1,47 @@
1
- require "stringio"
2
-
3
- def capture
4
- stdout, $stdout = $stdout, StringIO.new
5
- stderr, $stderr = $stderr, StringIO.new
6
- yield
7
- [$stdout.string, $stderr.string]
8
- ensure
9
- $stdout = stdout
10
- $stderr = stderr
11
- end
12
-
13
1
  test "output of successful run" do
14
2
  expected = ".\n"
15
3
 
16
- stdout, stderr = capture do
17
- Cutest.run(Dir["test/fixtures/success.rb"])
18
- end
4
+ out = %x{./bin/cutest test/fixtures/success.rb}
19
5
 
20
- assert_equal(stdout, expected)
6
+ assert_equal(expected, out)
21
7
  end
22
8
 
23
9
  test "output of failed run" do
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"
10
+ expected = "\n\nCutest::AssertionFailed: expression returned false\n\n" +
11
+ " line: assert false\n" +
12
+ " file: test/fixtures/failure.rb +2\n\n"
27
13
 
28
- stdout, stderr = capture do
29
- Cutest.run(Dir["test/fixtures/failure.rb"])
30
- end
14
+ out = %x{./bin/cutest test/fixtures/failure.rb}
31
15
 
32
- assert_equal(stdout, expected)
16
+ assert_equal(expected, out)
33
17
  end
34
18
 
35
19
  test "output of failed run" do
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"
20
+ expected = "\n\nRuntimeError: Oops\n\n" +
21
+ " line: raise \"Oops\"\n" +
22
+ " file: test/fixtures/exception.rb +2\n\n"
38
23
 
39
- stdout, stderr = capture do
40
- Cutest.run(Dir["test/fixtures/exception.rb"])
41
- end
24
+ out = %x{./bin/cutest test/fixtures/exception.rb}
42
25
 
43
- assert_equal(stdout, expected)
26
+ assert_equal(expected, out)
44
27
  end
45
28
 
46
29
  test "output of custom assertion" do
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"
30
+ expected = "\n\nCutest::AssertionFailed: not empty\n\n" +
31
+ " line: assert_empty \"foo\"\n" +
32
+ " file: test/fixtures/fail_custom_assertion.rb +7\n\n"
33
+
34
+ out = %x{./bin/cutest test/fixtures/fail_custom_assertion.rb}
35
+
36
+ assert_equal(expected, out)
37
+ end
38
+
39
+ test "output of failure in nested file" do
40
+ expected = "\n\nCutest::AssertionFailed: expression returned false\n\n" +
41
+ " line: assert false\n" +
42
+ " file: test/fixtures/failure.rb +2\n\n"
50
43
 
51
- stdout, stderr = capture do
52
- Cutest.run(Dir["test/fixtures/fail_custom_assertion.rb"])
53
- end
44
+ out = %x{./bin/cutest test/fixtures/failure_in_loaded_file.rb}
54
45
 
55
- assert_equal(stdout, expected)
46
+ assert_equal(expected, out)
56
47
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cutest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
5
- prerelease:
4
+ version: 1.2.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Damian Janowski
@@ -10,8 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-20 00:00:00.000000000 +02:00
14
- default_executable:
13
+ date: 2012-07-25 00:00:00.000000000 Z
15
14
  dependencies: []
16
15
  description: Run tests in separate processes to avoid shared state.
17
16
  email:
@@ -33,13 +32,14 @@ files:
33
32
  - test/fixtures/exception.rb
34
33
  - test/fixtures/fail_custom_assertion.rb
35
34
  - test/fixtures/failure.rb
35
+ - test/fixtures/failure_in_loaded_file.rb
36
36
  - test/fixtures/success.rb
37
37
  - test/prepare.rb
38
38
  - test/run.rb
39
39
  - test/scopes.rb
40
40
  - test/setup.rb
41
- - bin/cutest
42
- has_rdoc: true
41
+ - !binary |-
42
+ YmluL2N1dGVzdA==
43
43
  homepage: http://github.com/djanowski/cutest
44
44
  licenses: []
45
45
  post_install_message:
@@ -55,12 +55,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
- - - ! '>='
58
+ - - ! '>'
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: 1.3.1
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 1.6.2
63
+ rubygems_version: 1.8.11
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: Forking tests.