tconsole 1.1.0pre10 → 1.1.0pre11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tconsole/console.rb +22 -17
- data/lib/tconsole/minitest_handler.rb +18 -1
- data/lib/tconsole/server.rb +65 -34
- data/lib/tconsole/version.rb +1 -1
- data/lib/tconsole.rb +3 -1
- metadata +3 -3
data/lib/tconsole/console.rb
CHANGED
@@ -2,6 +2,8 @@ module TConsole
|
|
2
2
|
class Console
|
3
3
|
KNOWN_COMMANDS = ["exit", "reload", "help", "info", "!failed", "!timings", "set"]
|
4
4
|
|
5
|
+
attr_accessor :pipe_server
|
6
|
+
|
5
7
|
def initialize(config)
|
6
8
|
@config = config
|
7
9
|
read_history
|
@@ -15,22 +17,24 @@ module TConsole
|
|
15
17
|
# Proc for helping us figure out autocompletes
|
16
18
|
Readline.completion_proc = Proc.new do |str|
|
17
19
|
known_commands = KNOWN_COMMANDS.grep(/^#{Regexp.escape(str)}/)
|
20
|
+
known_commands.concat(@config.file_sets.keys.grep(/^#{Regexp.escape(str)}/))
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
filename + File::SEPARATOR
|
23
|
-
else
|
24
|
-
filename
|
25
|
-
end
|
22
|
+
known_elements = []
|
23
|
+
unless pipe_server.nil?
|
24
|
+
known_elements = send_message_to_server({:action => "autocomplete", :text => str})
|
26
25
|
end
|
27
26
|
|
28
|
-
known_commands.concat(
|
27
|
+
known_commands.concat(known_elements)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
# Returns true if the app should keep running, false otherwise
|
33
|
-
def read_and_execute
|
32
|
+
def read_and_execute
|
33
|
+
if pipe_server.nil?
|
34
|
+
puts "No connection to test environment. Exiting."
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
34
38
|
while line = Readline.readline("tconsole> ", false)
|
35
39
|
line.strip!
|
36
40
|
args = Shellwords.shellwords(line)
|
@@ -43,32 +47,33 @@ module TConsole
|
|
43
47
|
if line == ""
|
44
48
|
# do nothing
|
45
49
|
elsif args[0] == "exit"
|
46
|
-
send_message_to_server({:action => "exit"}
|
50
|
+
send_message_to_server({:action => "exit"})
|
51
|
+
self.pipe_server = nil
|
47
52
|
return false
|
48
53
|
elsif args[0] == "reload"
|
49
|
-
send_message_to_server({:action => "exit"}
|
54
|
+
send_message_to_server({:action => "exit"})
|
50
55
|
return true
|
51
56
|
elsif args[0] == "help"
|
52
57
|
print_help
|
53
58
|
elsif args[0] == "!failed"
|
54
|
-
send_message_to_server({:action => "run_failed"}
|
59
|
+
send_message_to_server({:action => "run_failed"})
|
55
60
|
elsif args[0] == "!timings"
|
56
|
-
send_message_to_server({:action => "show_performance", :limit => args[1]}
|
61
|
+
send_message_to_server({:action => "show_performance", :limit => args[1]})
|
57
62
|
elsif args[0] == "info"
|
58
63
|
send_message_to_server({:action => "run_info"}, pipe_server)
|
59
64
|
elsif args[0] == "set"
|
60
|
-
send_message_to_server({:action => "set", :var => args[1], :value => args[2]}
|
65
|
+
send_message_to_server({:action => "set", :var => args[1], :value => args[2]})
|
61
66
|
elsif @config.file_sets.has_key?(args[0])
|
62
|
-
send_message_to_server({:action => "run_file_set", :set => args[0]}
|
67
|
+
send_message_to_server({:action => "run_file_set", :set => args[0]})
|
63
68
|
else
|
64
|
-
send_message_to_server({:action => "run_all_tests", :args => args}
|
69
|
+
send_message_to_server({:action => "run_all_tests", :args => args})
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
68
73
|
true
|
69
74
|
end
|
70
75
|
|
71
|
-
def send_message_to_server(message
|
76
|
+
def send_message_to_server(message)
|
72
77
|
pipe_server.write(message)
|
73
78
|
pipe_server.read
|
74
79
|
end
|
@@ -18,6 +18,23 @@ module TConsole
|
|
18
18
|
runner.results
|
19
19
|
end
|
20
20
|
|
21
|
+
# Preloads our element cache for autocompletion. Assumes tests are already loaded
|
22
|
+
def self.preload_elements
|
23
|
+
patch_minitest
|
24
|
+
|
25
|
+
results = TConsole::TestResult.new
|
26
|
+
|
27
|
+
suites = ::MiniTest::Unit::TestCase.test_suites
|
28
|
+
suites.each do |suite|
|
29
|
+
suite.test_methods.map do |method|
|
30
|
+
id = results.add_element(suite, method)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
results
|
35
|
+
end
|
36
|
+
|
37
|
+
|
21
38
|
# We're basically breaking MiniTest autorun here, since we want to manually run our
|
22
39
|
# tests and Rails relies on autorun
|
23
40
|
#
|
@@ -147,7 +164,7 @@ module TConsole
|
|
147
164
|
|
148
165
|
output = "#{result} #{method}"
|
149
166
|
|
150
|
-
print COLOR_MAP[result], " #{output}", ::Term::ANSIColor.reset, " #{time}s ",
|
167
|
+
print COLOR_MAP[result], " #{output}", ::Term::ANSIColor.reset, " #{"%0.6f" % time }s ",
|
151
168
|
::Term::ANSIColor.magenta, "#{id}", ::Term::ANSIColor.reset, "\n"
|
152
169
|
|
153
170
|
if @failed_fast
|
data/lib/tconsole/server.rb
CHANGED
@@ -24,6 +24,8 @@ module TConsole
|
|
24
24
|
run_file_set(message[:set])
|
25
25
|
elsif action == "run_all_tests"
|
26
26
|
run_all_tests(message[:args])
|
27
|
+
elsif action == "autocomplete"
|
28
|
+
autocomplete(message[:text])
|
27
29
|
elsif action == "exit"
|
28
30
|
exit(0)
|
29
31
|
end
|
@@ -61,24 +63,55 @@ module TConsole
|
|
61
63
|
|
62
64
|
return false
|
63
65
|
end
|
66
|
+
|
67
|
+
preload_test_ids
|
64
68
|
end
|
65
69
|
|
66
|
-
puts "Environment loaded in #{time}s."
|
70
|
+
puts "Environment loaded in #{"%0.6f" % time}s."
|
67
71
|
puts
|
68
72
|
|
69
73
|
result
|
70
74
|
end
|
71
75
|
|
76
|
+
# Returns an array of possible completions based on the available element data
|
77
|
+
def autocomplete(text)
|
78
|
+
config.cached_elements.keys.grep(/^#{Regexp.escape(text)}/)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Runs the given code in a block and returns the result of the code in the block.
|
82
|
+
# The block's result needs to be marshallable. Otherwise, nil is returned.
|
83
|
+
def run_in_fork(&block)
|
84
|
+
# Pipe for communicating with child so we can get its results back
|
85
|
+
read, write = IO.pipe
|
86
|
+
|
87
|
+
pid = fork do
|
88
|
+
read.close
|
89
|
+
|
90
|
+
result = block.call
|
91
|
+
|
92
|
+
write.puts([Marshal.dump(result)].pack("m0"))
|
93
|
+
end
|
94
|
+
|
95
|
+
write.close
|
96
|
+
response = read.read
|
97
|
+
read.close
|
98
|
+
Process.wait(pid)
|
99
|
+
|
100
|
+
begin
|
101
|
+
config.trace("Reading result from fork.")
|
102
|
+
Marshal.load(response.unpack("m")[0])
|
103
|
+
rescue => e
|
104
|
+
config.trace("Problem reading result from fork. Returning nil.")
|
105
|
+
config.trace(e.message)
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
72
110
|
# Loads the files that match globs and then executes tests against them. Limit tests
|
73
111
|
# with class names, method names, and test ids using match_patterns.
|
74
112
|
def run_tests(globs, match_patterns, message = "Running tests...")
|
75
113
|
time = Benchmark.realtime do
|
76
|
-
|
77
|
-
read, write = IO.pipe
|
78
|
-
|
79
|
-
fork do
|
80
|
-
read.close
|
81
|
-
|
114
|
+
self.last_result = run_in_fork do
|
82
115
|
puts message
|
83
116
|
puts
|
84
117
|
|
@@ -96,6 +129,7 @@ module TConsole
|
|
96
129
|
config.before_test_run!
|
97
130
|
config.trace("Completed before_test_run callback")
|
98
131
|
|
132
|
+
result = nil
|
99
133
|
if defined?(::MiniTest)
|
100
134
|
config.trace("Detected minitest.")
|
101
135
|
require File.join(File.dirname(__FILE__), "minitest_handler")
|
@@ -103,50 +137,47 @@ module TConsole
|
|
103
137
|
config.trace("Running tests.")
|
104
138
|
result = MiniTestHandler.run(match_patterns, config)
|
105
139
|
config.trace("Finished running tests.")
|
106
|
-
|
107
|
-
config.trace("Writing test results back to server.")
|
108
|
-
write.puts([Marshal.dump(result)].pack("m"))
|
109
|
-
config.trace("Finished writing test results to server.")
|
110
|
-
|
111
140
|
elsif defined?(::Test::Unit)
|
112
141
|
puts "Sorry, but tconsole doesn't support Test::Unit yet"
|
113
|
-
return
|
114
142
|
elsif defined?(::RSpec)
|
115
143
|
puts "Sorry, but tconsole doesn't support RSpec yet"
|
116
|
-
return
|
117
144
|
end
|
118
|
-
end
|
119
145
|
|
120
|
-
|
121
|
-
|
122
|
-
begin
|
123
|
-
config.trace("Reading test results from console.")
|
124
|
-
self.last_result = Marshal.load(response.unpack("m")[0])
|
125
|
-
config.cache_test_ids(self.last_result)
|
126
|
-
config.trace("Finished reading test results from console.")
|
127
|
-
rescue => e
|
128
|
-
config.trace("Exception: #{e.message}")
|
129
|
-
config.trace("==== Backtrace ====")
|
130
|
-
config.trace(e.backtrace.join("\n"))
|
131
|
-
config.trace("==== End Backtrace ====")
|
132
|
-
|
133
|
-
puts "ERROR: Unable to process test results."
|
134
|
-
puts
|
146
|
+
result
|
147
|
+
end
|
135
148
|
|
149
|
+
if self.last_result == nil
|
136
150
|
# Just in case anything crazy goes down with marshalling
|
137
151
|
self.last_result = TConsole::TestResult.new
|
138
152
|
end
|
139
153
|
|
140
|
-
|
154
|
+
config.cache_test_ids(self.last_result)
|
141
155
|
|
142
|
-
|
156
|
+
true
|
143
157
|
end
|
144
158
|
|
145
159
|
puts
|
146
|
-
puts "Test time (including load): #{time}s"
|
160
|
+
puts "Test time (including load): #{"%0.6f" % time}s"
|
147
161
|
puts
|
148
162
|
end
|
149
163
|
|
164
|
+
# Preloads our autocomplete cache
|
165
|
+
def preload_test_ids
|
166
|
+
result = run_in_fork do
|
167
|
+
paths = []
|
168
|
+
config.file_sets["all"].each do |glob|
|
169
|
+
paths.concat(Dir.glob(glob))
|
170
|
+
end
|
171
|
+
|
172
|
+
paths.each { |path| require File.expand_path(path) }
|
173
|
+
|
174
|
+
require File.join(File.dirname(__FILE__), "minitest_handler")
|
175
|
+
MiniTestHandler.preload_elements
|
176
|
+
end
|
177
|
+
|
178
|
+
config.cache_test_ids(result) unless result.nil?
|
179
|
+
end
|
180
|
+
|
150
181
|
# Runs all tests against the match patterns given
|
151
182
|
def run_all_tests(match_patterns = nil)
|
152
183
|
run_tests(config.file_sets["all"], match_patterns)
|
@@ -188,7 +219,7 @@ module TConsole
|
|
188
219
|
puts "No timing data available. Be sure you've run some tests."
|
189
220
|
else
|
190
221
|
sorted_timings.reverse[0, limit].each do |timing|
|
191
|
-
puts "#{timing[:time]}s #{timing[:suite]}##{timing[:method]}"
|
222
|
+
puts "#{"%0.6f" % timing[:time]}s #{timing[:suite]}##{timing[:method]}"
|
192
223
|
end
|
193
224
|
end
|
194
225
|
|
data/lib/tconsole/version.rb
CHANGED
data/lib/tconsole.rb
CHANGED
@@ -70,7 +70,9 @@ module TConsole
|
|
70
70
|
end
|
71
71
|
config.trace("Environment loaded successfully.")
|
72
72
|
|
73
|
-
|
73
|
+
console.pipe_server = pipe_server
|
74
|
+
running = console.read_and_execute
|
75
|
+
console.pipe_server = nil
|
74
76
|
|
75
77
|
Process.waitall
|
76
78
|
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.0pre11
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70281579497440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.0.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70281579497440
|
25
25
|
description: ! " tconsole allows Rails developers to easily and quickly run their
|
26
26
|
tests as a whole or in subsets. It forks the testing processes from\n a preloaded
|
27
27
|
test environment to ensure that developers don't have to reload their entire Rails
|