tconsole 1.1.2pre4 → 1.1.2pre5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tconsole.rb +2 -2
- data/lib/tconsole/config.rb +34 -3
- data/lib/tconsole/console.rb +54 -26
- data/lib/tconsole/minitest_handler.rb +9 -5
- data/lib/tconsole/util.rb +12 -0
- data/lib/tconsole/version.rb +1 -1
- data/test/unit/config_test.rb +23 -3
- data/test/unit/util_test.rb +29 -0
- metadata +8 -6
data/lib/tconsole.rb
CHANGED
@@ -6,6 +6,7 @@ require "tconsole/pipe_server"
|
|
6
6
|
require "tconsole/test_result"
|
7
7
|
require "tconsole/util"
|
8
8
|
|
9
|
+
require "optparse"
|
9
10
|
require "readline"
|
10
11
|
require "benchmark"
|
11
12
|
require "drb/drb"
|
@@ -31,8 +32,7 @@ module TConsole
|
|
31
32
|
# set up the config
|
32
33
|
Config.load_config(File.join(Dir.home, ".tconsole"))
|
33
34
|
Config.load_config(File.join(Dir.pwd, ".tconsole"))
|
34
|
-
config = Config.configure
|
35
|
-
config.trace_execution = true if argv.include?("--trace")
|
35
|
+
config = Config.configure(argv)
|
36
36
|
|
37
37
|
config_errors = config.validation_errors
|
38
38
|
if config_errors.length > 0
|
data/lib/tconsole/config.rb
CHANGED
@@ -31,7 +31,13 @@ module TConsole
|
|
31
31
|
# Element names we know
|
32
32
|
attr_accessor :cached_elements
|
33
33
|
|
34
|
-
|
34
|
+
# First command to run when tconsole loads
|
35
|
+
attr_accessor :run_command
|
36
|
+
|
37
|
+
# Only runs the command passed on the command line, and then exits
|
38
|
+
attr_accessor :once
|
39
|
+
|
40
|
+
def initialize(argv)
|
35
41
|
self.trace_execution = false
|
36
42
|
self.test_dir = "./test"
|
37
43
|
self.include_paths = ["./test", "./lib"]
|
@@ -41,6 +47,9 @@ module TConsole
|
|
41
47
|
"all" => ["#{test_dir}/**/*_test.rb"]
|
42
48
|
}
|
43
49
|
|
50
|
+
# load any args into this config that were passed
|
51
|
+
load_args(argv)
|
52
|
+
|
44
53
|
@after_load = nil
|
45
54
|
@before_load = nil
|
46
55
|
@before_test_run = nil
|
@@ -49,6 +58,28 @@ module TConsole
|
|
49
58
|
@cached_elements = {}
|
50
59
|
end
|
51
60
|
|
61
|
+
def option_parser
|
62
|
+
@option_parser ||= OptionParser.new do |opts|
|
63
|
+
opts.on("-t", "--trace", "Enable verbose output.") do
|
64
|
+
self.trace_execution = true
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on("-o", "--once", "Run whatever command is passed and then exit.") do
|
68
|
+
self.once = true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Public: Loads any passed command line arguments into the config.
|
74
|
+
#
|
75
|
+
# argv - The array of command line arguments we're loading
|
76
|
+
def load_args(argv)
|
77
|
+
args = argv.clone
|
78
|
+
|
79
|
+
option_parser.parse!(args)
|
80
|
+
self.run_command = args.join(" ")
|
81
|
+
end
|
82
|
+
|
52
83
|
def trace?
|
53
84
|
self.trace_execution
|
54
85
|
end
|
@@ -125,8 +156,8 @@ module TConsole
|
|
125
156
|
end
|
126
157
|
|
127
158
|
# Returns an appropriate tconsole config based on the environment
|
128
|
-
def self.configure
|
129
|
-
config = Config.new
|
159
|
+
def self.configure(argv = [])
|
160
|
+
config = Config.new(argv)
|
130
161
|
|
131
162
|
if is_rails?
|
132
163
|
config.preload_paths = ["./config/application"]
|
data/lib/tconsole/console.rb
CHANGED
@@ -42,38 +42,27 @@ module TConsole
|
|
42
42
|
print prompt
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# Run any commands that have been passed
|
46
|
+
result = process_command(@config.run_command)
|
47
|
+
if result == :exit || @config.once
|
48
|
+
send_message(:stop)
|
49
|
+
return false
|
50
|
+
elsif result == :reload
|
51
|
+
send_message(:stop)
|
52
|
+
return true
|
53
|
+
end
|
48
54
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
# The command entry loop
|
56
|
+
while command = Readline.readline(prompt, false)
|
57
|
+
command.strip!
|
58
|
+
result = process_command(command)
|
53
59
|
|
54
|
-
if
|
55
|
-
# do nothing
|
56
|
-
elsif args[0] == "exit"
|
60
|
+
if result == :exit
|
57
61
|
send_message(:stop)
|
58
|
-
self.pipe_server = nil
|
59
62
|
return false
|
60
|
-
elsif
|
63
|
+
elsif result == :reload
|
61
64
|
send_message(:stop)
|
62
65
|
return true
|
63
|
-
elsif args[0] == "help"
|
64
|
-
print_help
|
65
|
-
elsif args[0] == "!failed"
|
66
|
-
send_message(:run_failed)
|
67
|
-
elsif args[0] == "!timings"
|
68
|
-
send_message(:show_performance, args[1])
|
69
|
-
elsif args[0] == "info"
|
70
|
-
send_message(:run_info)
|
71
|
-
elsif args[0] == "set"
|
72
|
-
send_message(:set, args[1], args[2])
|
73
|
-
elsif @config.file_sets.has_key?(args[0])
|
74
|
-
send_message(:run_file_set, args[0])
|
75
|
-
else
|
76
|
-
send_message(:run_all_tests, args)
|
77
66
|
end
|
78
67
|
end
|
79
68
|
|
@@ -81,6 +70,45 @@ module TConsole
|
|
81
70
|
false
|
82
71
|
end
|
83
72
|
|
73
|
+
# Public: Process a command however it needs to be handled.
|
74
|
+
#
|
75
|
+
# command - The command we need to parse and handle
|
76
|
+
def process_command(command)
|
77
|
+
args = Shellwords.shellwords(command)
|
78
|
+
|
79
|
+
# save the command unless we're exiting or repeating the last command
|
80
|
+
unless args[0] == "exit" || (Readline::HISTORY.length > 0 && Readline::HISTORY[Readline::HISTORY.length - 1] == command)
|
81
|
+
Readline::HISTORY << command
|
82
|
+
end
|
83
|
+
|
84
|
+
if command == ""
|
85
|
+
# do nothing
|
86
|
+
elsif args[0] == "exit"
|
87
|
+
send_message(:stop)
|
88
|
+
self.pipe_server = nil
|
89
|
+
return :exit
|
90
|
+
elsif args[0] == "reload"
|
91
|
+
send_message(:stop)
|
92
|
+
return :reload
|
93
|
+
elsif args[0] == "help"
|
94
|
+
print_help
|
95
|
+
elsif args[0] == "!failed"
|
96
|
+
send_message(:run_failed)
|
97
|
+
elsif args[0] == "!timings"
|
98
|
+
send_message(:show_performance, args[1])
|
99
|
+
elsif args[0] == "info"
|
100
|
+
send_message(:run_info)
|
101
|
+
elsif args[0] == "set"
|
102
|
+
send_message(:set, args[1], args[2])
|
103
|
+
elsif @config.file_sets.has_key?(args[0])
|
104
|
+
send_message(:run_file_set, args[0])
|
105
|
+
else
|
106
|
+
send_message(:run_all_tests, args)
|
107
|
+
end
|
108
|
+
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
|
84
112
|
def send_message(message, *args)
|
85
113
|
pipe_server.write({:action => message.to_sym, :args => args})
|
86
114
|
pipe_server.read
|
@@ -215,21 +215,25 @@ module TConsole
|
|
215
215
|
end
|
216
216
|
|
217
217
|
def puke(klass, meth, e)
|
218
|
+
id = results.elements["#{klass}##{meth}"]
|
219
|
+
|
218
220
|
e = case e
|
219
221
|
when MiniTest::Skip then
|
220
222
|
@skips += 1
|
221
223
|
results.skip_count += 1
|
222
|
-
|
223
|
-
["S", COLOR_MAP["S"] + "Skipped:\n#{meth}(#{klass})" + ::Term::ANSIColor.reset + " [#{location e}]:\n#{e.message}\n"]
|
224
|
+
["S", COLOR_MAP["S"] + "Skipped:\n#{klass}##{meth} (#{id})" + ::Term::ANSIColor.reset + " [#{location e}]:\n#{e.message}\n"]
|
224
225
|
when MiniTest::Assertion then
|
225
226
|
@failures += 1
|
226
227
|
results.failure_count += 1
|
227
|
-
["F", COLOR_MAP["F"] + "Failure:\n#{meth}(#{
|
228
|
+
["F", COLOR_MAP["F"] + "Failure:\n#{klass}##{meth} (#{id})" + ::Term::ANSIColor.reset + " [#{location e}]:\n#{e.message}\n"]
|
228
229
|
else
|
229
230
|
@errors += 1
|
230
231
|
results.error_count += 1
|
231
|
-
|
232
|
-
|
232
|
+
|
233
|
+
filtered_backtrace = Util.filter_backtrace(e.backtrace)
|
234
|
+
backtrace_text = MiniTest::filter_backtrace(filtered_backtrace).join "\n "
|
235
|
+
|
236
|
+
["E", COLOR_MAP["E"] + "Error:\n#{klass}##{meth} (#{id}):\n" + ::Term::ANSIColor.reset + "#{e.class}: #{e.message}\n #{backtrace_text}\n"]
|
233
237
|
end
|
234
238
|
@report << e[1]
|
235
239
|
e[0]
|
data/lib/tconsole/util.rb
CHANGED
@@ -17,5 +17,17 @@ module TConsole
|
|
17
17
|
rescue
|
18
18
|
nil
|
19
19
|
end
|
20
|
+
|
21
|
+
# Public: Filters a backtrace to exclude things that happened in TConsole
|
22
|
+
#
|
23
|
+
# backtrace: The backtrace array that we're filtering.
|
24
|
+
#
|
25
|
+
# Returns the updated backtrace.
|
26
|
+
def self.filter_backtrace(backtrace)
|
27
|
+
tconsole_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) + File::SEPARATOR
|
28
|
+
backtrace.select do |item|
|
29
|
+
!item.start_with?(tconsole_path)
|
30
|
+
end
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
data/lib/tconsole/version.rb
CHANGED
data/test/unit/config_test.rb
CHANGED
@@ -4,8 +4,8 @@ module TConsole
|
|
4
4
|
class ConfigTest < MiniTest::Unit::TestCase
|
5
5
|
|
6
6
|
a "Config" do
|
7
|
-
|
8
|
-
@config = TConsole::Config.new
|
7
|
+
before do
|
8
|
+
@config = TConsole::Config.new([])
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have appropriate defaults" do
|
@@ -34,8 +34,28 @@ module TConsole
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
a "Config with command line arguments" do
|
38
|
+
it "should set up tracing correctly" do
|
39
|
+
@config = Config.new(Shellwords.shellwords("--trace"))
|
40
|
+
|
41
|
+
assert @config.trace_execution
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set up only running the passed command and exiting" do
|
45
|
+
@config = Config.new(Shellwords.shellwords("--once all"))
|
46
|
+
|
47
|
+
assert @config.once
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set all remaining unparsed text to be the first command to run" do
|
51
|
+
@config = Config.new(Shellwords.shellwords("--trace set fast on"))
|
52
|
+
|
53
|
+
assert_equal "set fast on", @config.run_command
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
37
57
|
the "Config class" do
|
38
|
-
|
58
|
+
before do
|
39
59
|
TConsole::Config.clear_loaded_configs
|
40
60
|
end
|
41
61
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module TConsole
|
4
|
+
class ConfigTest < MiniTest::Unit::TestCase
|
5
|
+
a "Backtrace" do
|
6
|
+
before do
|
7
|
+
@non_tconsole_path = "/Users/alan/Projects/commondream/tconsole-test/test/functional/posts_controller_test.rb:16:in `block in <class:PostsControllerTest>'"
|
8
|
+
@tconsole_path = "#{File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))}/posts_controller_test.rb:16:in `block in <class:PostsControllerTest>'"
|
9
|
+
|
10
|
+
@backtrace = [
|
11
|
+
@non_tconsole_path,
|
12
|
+
@tconsole_path
|
13
|
+
]
|
14
|
+
|
15
|
+
@filtered_backtrace = Util.filter_backtrace(@backtrace)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should remove the tconsole path" do
|
19
|
+
assert_equal 1, @filtered_backtrace.length
|
20
|
+
assert !@filtered_backtrace.include?(@tconsole_path), "Should filter backtrace item under tconsole"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "shouldn't remove the non-tconsole path" do
|
24
|
+
assert @filtered_backtrace.include?(@non_tconsole_path), "Should not filter backtrace item outside of tconsole"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2pre5
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70325951774240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70325951774240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70325951773400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.11.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70325951773400
|
36
36
|
description: ! " tconsole allows Rails developers to easily and quickly run their
|
37
37
|
tests as a whole or in subsets. It forks the testing processes from\n a preloaded
|
38
38
|
test environment to ensure that developers don't have to reload their entire Rails
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- test/test_helper.rb
|
64
64
|
- test/unit/config_test.rb
|
65
65
|
- test/unit/sample_config
|
66
|
+
- test/unit/util_test.rb
|
66
67
|
homepage: ''
|
67
68
|
licenses: []
|
68
69
|
post_install_message:
|
@@ -91,3 +92,4 @@ test_files:
|
|
91
92
|
- test/test_helper.rb
|
92
93
|
- test/unit/config_test.rb
|
93
94
|
- test/unit/sample_config
|
95
|
+
- test/unit/util_test.rb
|