vinted-parallel_tests 0.13.3 → 1.7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +86 -47
- data/bin/parallel_cucumber +5 -1
- data/bin/parallel_rspec +5 -1
- data/bin/parallel_spinach +9 -0
- data/bin/parallel_test +5 -1
- data/lib/parallel_tests.rb +15 -2
- data/lib/parallel_tests/cli.rb +115 -35
- data/lib/parallel_tests/cucumber/failures_logger.rb +9 -7
- data/lib/parallel_tests/cucumber/runner.rb +16 -77
- data/lib/parallel_tests/cucumber/scenario_line_logger.rb +52 -0
- data/lib/parallel_tests/cucumber/scenarios.rb +34 -0
- data/lib/parallel_tests/{cucumber → gherkin}/io.rb +1 -1
- data/lib/parallel_tests/{cucumber/gherkin_listener.rb → gherkin/listener.rb} +11 -6
- data/lib/parallel_tests/gherkin/runner.rb +116 -0
- data/lib/parallel_tests/{cucumber → gherkin}/runtime_logger.rb +2 -2
- data/lib/parallel_tests/grouper.rb +34 -17
- data/lib/parallel_tests/rspec/failures_logger.rb +22 -14
- data/lib/parallel_tests/rspec/logger_base.rb +5 -1
- data/lib/parallel_tests/rspec/runner.rb +5 -4
- data/lib/parallel_tests/rspec/runtime_logger.rb +10 -5
- data/lib/parallel_tests/rspec/summary_logger.rb +11 -11
- data/lib/parallel_tests/spinach/runner.rb +19 -0
- data/lib/parallel_tests/tasks.rb +41 -18
- data/lib/parallel_tests/test/runner.rb +80 -28
- data/lib/parallel_tests/test/runtime_logger.rb +86 -55
- data/lib/parallel_tests/version.rb +1 -1
- metadata +18 -35
- data/.gitignore +0 -2
- data/.rspec +0 -2
- data/.travis.yml +0 -6
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -48
- data/Rakefile +0 -6
- data/ReadmeRails2.md +0 -48
- data/parallel_tests.gemspec +0 -14
- data/spec/integration_spec.rb +0 -285
- data/spec/parallel_tests/cli_spec.rb +0 -71
- data/spec/parallel_tests/cucumber/failure_logger_spec.rb +0 -43
- data/spec/parallel_tests/cucumber/gherkin_listener_spec.rb +0 -97
- data/spec/parallel_tests/cucumber/runner_spec.rb +0 -179
- data/spec/parallel_tests/grouper_spec.rb +0 -52
- data/spec/parallel_tests/rspec/failures_logger_spec.rb +0 -82
- data/spec/parallel_tests/rspec/runner_spec.rb +0 -187
- data/spec/parallel_tests/rspec/runtime_logger_spec.rb +0 -126
- data/spec/parallel_tests/rspec/summary_logger_spec.rb +0 -37
- data/spec/parallel_tests/tasks_spec.rb +0 -151
- data/spec/parallel_tests/test/runner_spec.rb +0 -413
- data/spec/parallel_tests/test/runtime_logger_spec.rb +0 -90
- data/spec/parallel_tests_spec.rb +0 -137
- data/spec/spec_helper.rb +0 -157
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ParallelTests::RSpec::RuntimeLogger do
|
4
|
-
before do
|
5
|
-
# pretend we run in parallel or the logger will log nothing
|
6
|
-
ENV['TEST_ENV_NUMBER'] = ''
|
7
|
-
@clean_output = %r{^spec/foo.rb:[-\.e\d]+$}m
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
ENV.delete 'TEST_ENV_NUMBER'
|
12
|
-
end
|
13
|
-
|
14
|
-
def log_for_a_file(options={})
|
15
|
-
Tempfile.open('xxx') do |temp|
|
16
|
-
temp.close
|
17
|
-
f = File.open(temp.path,'w')
|
18
|
-
logger = if block_given?
|
19
|
-
yield(f)
|
20
|
-
else
|
21
|
-
ParallelTests::RSpec::RuntimeLogger.new(f)
|
22
|
-
end
|
23
|
-
|
24
|
-
example = (mock(:file_path => "#{Dir.pwd}/spec/foo.rb"))
|
25
|
-
logger.example_group_started example
|
26
|
-
logger.example_group_finished example
|
27
|
-
logger.start_dump
|
28
|
-
|
29
|
-
#f.close
|
30
|
-
return File.read(f.path)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "logs runtime with relative paths" do
|
35
|
-
log_for_a_file.should =~ @clean_output
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not log if we do not run in parallel" do
|
39
|
-
ENV.delete 'TEST_ENV_NUMBER'
|
40
|
-
log_for_a_file.should == ""
|
41
|
-
end
|
42
|
-
|
43
|
-
it "appends to a given file" do
|
44
|
-
result = log_for_a_file do |f|
|
45
|
-
f.write 'FooBar'
|
46
|
-
ParallelTests::RSpec::RuntimeLogger.new(f)
|
47
|
-
end
|
48
|
-
result.should include('FooBar')
|
49
|
-
result.should include('foo.rb')
|
50
|
-
end
|
51
|
-
|
52
|
-
it "overwrites a given path" do
|
53
|
-
result = log_for_a_file do |f|
|
54
|
-
f.write 'FooBar'
|
55
|
-
ParallelTests::RSpec::RuntimeLogger.new(f.path)
|
56
|
-
end
|
57
|
-
result.should_not include('FooBar')
|
58
|
-
result.should include('foo.rb')
|
59
|
-
end
|
60
|
-
|
61
|
-
context "integration" do
|
62
|
-
around do |example|
|
63
|
-
Dir.mktmpdir do |dir|
|
64
|
-
Dir.chdir(dir, &example)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def write(file, content)
|
69
|
-
FileUtils.mkdir_p(File.dirname(file))
|
70
|
-
File.open(file, 'w') { |f| f.write content }
|
71
|
-
end
|
72
|
-
|
73
|
-
it "logs shared examples into the running files" do
|
74
|
-
write "spec/spec_helper.rb", <<-RUBY
|
75
|
-
shared_examples "foo" do
|
76
|
-
it "is slow" do
|
77
|
-
sleep 0.5
|
78
|
-
end
|
79
|
-
end
|
80
|
-
RUBY
|
81
|
-
|
82
|
-
["a", "b"].each do |letter|
|
83
|
-
write "spec/#{letter}_spec.rb", <<-RUBY
|
84
|
-
require 'spec_helper'
|
85
|
-
describe 'xxx' do
|
86
|
-
it_behaves_like "foo"
|
87
|
-
end
|
88
|
-
RUBY
|
89
|
-
end
|
90
|
-
|
91
|
-
system("TEST_ENV_NUMBER=1 rspec spec -I #{Bundler.root.join("lib")} --format ParallelTests::RSpec::RuntimeLogger --out runtime.log 2>&1") || raise("nope")
|
92
|
-
|
93
|
-
result = File.read("runtime.log")
|
94
|
-
result.should include "a_spec.rb:0.5"
|
95
|
-
result.should include "b_spec.rb:0.5"
|
96
|
-
result.should_not include "spec_helper"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "logs multiple describe blocks" do
|
100
|
-
write "spec/a_spec.rb", <<-RUBY
|
101
|
-
describe "xxx" do
|
102
|
-
it "is slow" do
|
103
|
-
sleep 0.5
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "yyy" do
|
108
|
-
it "is slow" do
|
109
|
-
sleep 0.5
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "yep" do
|
113
|
-
it "is slow" do
|
114
|
-
sleep 0.5
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
RUBY
|
119
|
-
|
120
|
-
system("TEST_ENV_NUMBER=1 rspec spec -I #{Bundler.root.join("lib")} --format ParallelTests::RSpec::RuntimeLogger --out runtime.log 2>&1") || raise("nope")
|
121
|
-
|
122
|
-
result = File.read("runtime.log")
|
123
|
-
result.should include "a_spec.rb:1.5"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ParallelTests::RSpec::SummaryLogger do
|
4
|
-
let(:output){ OutputLogger.new([]) }
|
5
|
-
let(:logger){ ParallelTests::RSpec::SummaryLogger.new(output) }
|
6
|
-
|
7
|
-
def decolorize(string)
|
8
|
-
string.gsub(/\e\[\d+m/,'')
|
9
|
-
end
|
10
|
-
|
11
|
-
# TODO somehow generate a real example with an exception to test this
|
12
|
-
xit "prints failing examples" do
|
13
|
-
logger.example_failed XXX
|
14
|
-
logger.example_failed XXX
|
15
|
-
logger.dump_failures
|
16
|
-
output.output.should == [
|
17
|
-
"bundle exec rspec ./spec/path/to/example.rb:123 # should do stuff",
|
18
|
-
"bundle exec rspec ./spec/path/to/example.rb:125 # should not do stuff"
|
19
|
-
]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "does not print anything for passing examples" do
|
23
|
-
logger.example_passed mock(:location => "/my/spec/foo.rb:123")
|
24
|
-
logger.dump_failures
|
25
|
-
output.output.should == []
|
26
|
-
logger.dump_summary(1,2,3,4)
|
27
|
-
output.output.map{|o| decolorize(o) }.should == ["\nFinished in 1 second\n", "2 examples, 3 failures, 4 pending"]
|
28
|
-
end
|
29
|
-
|
30
|
-
it "does not print anything for pending examples" do
|
31
|
-
logger.example_pending mock(:location => "/my/spec/foo.rb:123")
|
32
|
-
logger.dump_failures
|
33
|
-
output.output.should == []
|
34
|
-
logger.dump_summary(1,2,3,4)
|
35
|
-
output.output.map{|o| decolorize(o) }.should == ["\nFinished in 1 second\n", "2 examples, 3 failures, 4 pending"]
|
36
|
-
end
|
37
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'parallel_tests/tasks'
|
3
|
-
|
4
|
-
describe ParallelTests::Tasks do
|
5
|
-
describe ".parse_args" do
|
6
|
-
it "should return the count" do
|
7
|
-
args = {:count => 2}
|
8
|
-
ParallelTests::Tasks.parse_args(args).should == [2, "", ""]
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should default to the prefix" do
|
12
|
-
args = {:count => "models"}
|
13
|
-
ParallelTests::Tasks.parse_args(args).should == [nil, "models", ""]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the count and pattern" do
|
17
|
-
args = {:count => 2, :pattern => "models"}
|
18
|
-
ParallelTests::Tasks.parse_args(args).should == [2, "models", ""]
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return the count, pattern, and options" do
|
22
|
-
args = {:count => 2, :pattern => "plain", :options => "-p default"}
|
23
|
-
ParallelTests::Tasks.parse_args(args).should == [2, "plain", "-p default"]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ".rails_env" do
|
28
|
-
around do |example|
|
29
|
-
begin
|
30
|
-
old = ENV["RAILS_ENV"]
|
31
|
-
ENV.delete "RAILS_ENV"
|
32
|
-
example.call
|
33
|
-
ensure
|
34
|
-
ENV["RAILS_ENV"] = old
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be test when nothing was set" do
|
39
|
-
ParallelTests::Tasks.rails_env.should == "test"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should be whatever was set" do
|
43
|
-
ENV["RAILS_ENV"] = "foo"
|
44
|
-
ParallelTests::Tasks.rails_env.should == "foo"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe ".run_in_parallel" do
|
49
|
-
let(:full_path){ File.expand_path("../../../bin/parallel_test", __FILE__) }
|
50
|
-
|
51
|
-
it "should have the executable" do
|
52
|
-
File.file?(full_path).should == true
|
53
|
-
File.executable?(full_path).should == true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "runs command in parallel" do
|
57
|
-
ParallelTests::Tasks.should_receive(:system).with("#{full_path} --exec 'echo'").and_return true
|
58
|
-
ParallelTests::Tasks.run_in_parallel("echo")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "runs command with :count option" do
|
62
|
-
ParallelTests::Tasks.should_receive(:system).with("#{full_path} --exec 'echo' -n 123").and_return true
|
63
|
-
ParallelTests::Tasks.run_in_parallel("echo", :count => 123)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "runs command with :non_parallel option" do
|
67
|
-
ParallelTests::Tasks.should_receive(:system).with("#{full_path} --exec 'echo' --non-parallel").and_return true
|
68
|
-
ParallelTests::Tasks.run_in_parallel("echo", :non_parallel => true)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "runs aborts if the command fails" do
|
72
|
-
ParallelTests::Tasks.should_receive(:system).and_return false
|
73
|
-
ParallelTests::Tasks.should_receive(:abort).and_return false
|
74
|
-
ParallelTests::Tasks.run_in_parallel("echo")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe ".suppress_output" do
|
79
|
-
def call(command, grep)
|
80
|
-
result = `#{ParallelTests::Tasks.suppress_output(command, grep)}`
|
81
|
-
[result, $?.success?]
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with pipefail supported" do
|
85
|
-
before :all do
|
86
|
-
if not system("set -o pipefail 2>/dev/null && test 1")
|
87
|
-
pending "pipefail is not supported on your system"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should hide offending lines" do
|
92
|
-
call("echo 123", "123").should == ["", true]
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should not hide other lines" do
|
96
|
-
call("echo 124", "123").should == ["124\n", true]
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should fail if command fails and the pattern matches" do
|
100
|
-
call("echo 123 && test", "123").should == ["", false]
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should fail if command fails and the pattern fails" do
|
104
|
-
call("echo 124 && test", "123").should == ["124\n", false]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "without pipefail supported" do
|
109
|
-
before do
|
110
|
-
ParallelTests::Tasks.should_receive(:system).with("set -o pipefail 2>/dev/null && test 1").and_return false
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should not filter and succeed" do
|
114
|
-
call("echo 123", "123").should == ["123\n", true]
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should not filter and fail" do
|
118
|
-
call("echo 123 && test", "123").should == ["123\n", false]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe ".check_for_pending_migrations" do
|
124
|
-
after do
|
125
|
-
Rake.application.instance_variable_get('@tasks').delete("db:abort_if_pending_migrations")
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should do nothing if pending migrations is no defined" do
|
129
|
-
ParallelTests::Tasks.check_for_pending_migrations
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should run pending migrations is task is defined" do
|
133
|
-
foo = 1
|
134
|
-
Rake::Task.define_task("db:abort_if_pending_migrations") do
|
135
|
-
foo = 2
|
136
|
-
end
|
137
|
-
ParallelTests::Tasks.check_for_pending_migrations
|
138
|
-
foo.should == 2
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should not execute the task twice" do
|
142
|
-
foo = 1
|
143
|
-
Rake::Task.define_task("db:abort_if_pending_migrations") do
|
144
|
-
foo += 1
|
145
|
-
end
|
146
|
-
ParallelTests::Tasks.check_for_pending_migrations
|
147
|
-
ParallelTests::Tasks.check_for_pending_migrations
|
148
|
-
foo.should == 2
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
@@ -1,413 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "parallel_tests/test/runner"
|
3
|
-
|
4
|
-
describe ParallelTests::Test::Runner do
|
5
|
-
test_tests_in_groups(ParallelTests::Test::Runner, 'test', '_test.rb')
|
6
|
-
|
7
|
-
describe ".run_tests" do
|
8
|
-
def call(*args)
|
9
|
-
ParallelTests::Test::Runner.run_tests(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "allows to override runner executable via PARALLEL_TESTS_EXECUTABLE" do
|
13
|
-
begin
|
14
|
-
ENV['PARALLEL_TESTS_EXECUTABLE'] = 'script/custom_rspec'
|
15
|
-
ParallelTests::Test::Runner.should_receive(:execute_command).with{|a,b,c,d| a.include?("script/custom_rspec") }
|
16
|
-
call(['xxx'], 1, 22, {})
|
17
|
-
ensure
|
18
|
-
ENV.delete('PARALLEL_TESTS_EXECUTABLE')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "uses options" do
|
23
|
-
ParallelTests::Test::Runner.should_receive(:execute_command).with{|a,b,c,d| a =~ %r{ruby -Itest .* -- -v}}
|
24
|
-
call(['xxx'], 1, 22, :test_options => '-v')
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns the output" do
|
28
|
-
ParallelTests::Test::Runner.should_receive(:execute_command).and_return({:x => 1})
|
29
|
-
call(['xxx'], 1, 22, {}).should == {:x => 1}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe ".test_in_groups" do
|
34
|
-
def call(*args)
|
35
|
-
ParallelTests::Test::Runner.tests_in_groups(*args)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not sort when passed false do_sort option" do
|
39
|
-
ParallelTests::Test::Runner.should_not_receive(:smallest_first)
|
40
|
-
call([], 1, :group_by => :found)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "does sort when not passed do_sort option" do
|
44
|
-
ParallelTests::Test::Runner.stub!(:tests_with_runtime).and_return([])
|
45
|
-
ParallelTests::Grouper.should_receive(:largest_first).and_return([])
|
46
|
-
call([], 1)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "groups by single_process pattern and then via size" do
|
50
|
-
ParallelTests::Test::Runner.should_receive(:with_runtime_info).
|
51
|
-
and_return([
|
52
|
-
['aaa', 5],
|
53
|
-
['aaa2', 5],
|
54
|
-
['bbb', 2],
|
55
|
-
['ccc', 1],
|
56
|
-
['ddd', 1]
|
57
|
-
])
|
58
|
-
result = call([], 3, :single_process => [/^a.a/])
|
59
|
-
result.should == [["aaa", "aaa2"], ["bbb"], ["ccc", "ddd"]]
|
60
|
-
end
|
61
|
-
|
62
|
-
it "groups by size and adds isolated separately" do
|
63
|
-
pending if RUBY_PLATFORM == "java"
|
64
|
-
ParallelTests::Test::Runner.should_receive(:with_runtime_info).
|
65
|
-
and_return([
|
66
|
-
['aaa', 0],
|
67
|
-
['bbb', 3],
|
68
|
-
['ccc', 1],
|
69
|
-
['ddd', 2],
|
70
|
-
['eee', 1]
|
71
|
-
])
|
72
|
-
|
73
|
-
result = call([], 3, :isolate => true, :single_process => [/^aaa/])
|
74
|
-
result.should == [["aaa"], ["bbb", "eee"], ["ccc", "ddd"]]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe ".find_results" do
|
79
|
-
def call(*args)
|
80
|
-
ParallelTests::Test::Runner.find_results(*args)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "finds multiple results in test output" do
|
84
|
-
output = <<EOF
|
85
|
-
Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
|
86
|
-
Started
|
87
|
-
..............
|
88
|
-
Finished in 0.145069 seconds.
|
89
|
-
|
90
|
-
10 tests, 20 assertions, 0 failures, 0 errors
|
91
|
-
Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
|
92
|
-
Started
|
93
|
-
..............
|
94
|
-
Finished in 0.145069 seconds.
|
95
|
-
|
96
|
-
14 tests, 20 assertions, 0 failures, 0 errors
|
97
|
-
|
98
|
-
EOF
|
99
|
-
|
100
|
-
call(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tests, 20 assertions, 0 failures, 0 errors']
|
101
|
-
end
|
102
|
-
|
103
|
-
it "is robust against scrambled output" do
|
104
|
-
output = <<EOF
|
105
|
-
Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
|
106
|
-
Started
|
107
|
-
..............
|
108
|
-
Finished in 0.145069 seconds.
|
109
|
-
|
110
|
-
10 tests, 20 assertions, 0 failures, 0 errors
|
111
|
-
Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
|
112
|
-
Started
|
113
|
-
..............
|
114
|
-
Finished in 0.145069 seconds.
|
115
|
-
|
116
|
-
14 te.dsts, 20 assertions, 0 failures, 0 errors
|
117
|
-
EOF
|
118
|
-
|
119
|
-
call(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tedsts, 20 assertions, 0 failures, 0 errors']
|
120
|
-
end
|
121
|
-
|
122
|
-
it "ignores color-codes" do
|
123
|
-
output = <<EOF
|
124
|
-
10 tests, 20 assertions, 0 \e[31mfailures, 0 errors
|
125
|
-
EOF
|
126
|
-
call(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors']
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe ".find_tests" do
|
131
|
-
def call(*args)
|
132
|
-
ParallelTests::Test::Runner.send(:find_tests, *args)
|
133
|
-
end
|
134
|
-
|
135
|
-
def with_files(files)
|
136
|
-
begin
|
137
|
-
root = "/tmp/test-find_tests-#{rand(999)}"
|
138
|
-
`mkdir #{root}`
|
139
|
-
files.each do |file|
|
140
|
-
parent = "#{root}/#{File.dirname(file)}"
|
141
|
-
`mkdir -p #{parent}` unless File.exist?(parent)
|
142
|
-
`touch #{root}/#{file}`
|
143
|
-
end
|
144
|
-
yield root
|
145
|
-
ensure
|
146
|
-
`rm -rf #{root}`
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def inside_dir(dir)
|
151
|
-
old = Dir.pwd
|
152
|
-
Dir.chdir dir
|
153
|
-
yield
|
154
|
-
ensure
|
155
|
-
Dir.chdir old
|
156
|
-
end
|
157
|
-
|
158
|
-
it "finds test in folders with appended /" do
|
159
|
-
with_files(['b/a_test.rb']) do |root|
|
160
|
-
call(["#{root}/"]).sort.should == [
|
161
|
-
"#{root}/b/a_test.rb",
|
162
|
-
]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
it "finds test files nested in symlinked folders" do
|
167
|
-
with_files(['a/a_test.rb','b/b_test.rb']) do |root|
|
168
|
-
`ln -s #{root}/a #{root}/b/link`
|
169
|
-
call(["#{root}/b"]).sort.should == [
|
170
|
-
"#{root}/b/b_test.rb",
|
171
|
-
"#{root}/b/link/a_test.rb",
|
172
|
-
]
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it "finds test files but ignores those in symlinked folders" do
|
177
|
-
pending if RUBY_PLATFORM == "java"
|
178
|
-
with_files(['a/a_test.rb','b/b_test.rb']) do |root|
|
179
|
-
`ln -s #{root}/a #{root}/b/link`
|
180
|
-
call(["#{root}/b"], :symlinks => false).sort.should == [
|
181
|
-
"#{root}/b/b_test.rb",
|
182
|
-
]
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
it "finds test files nested in different folders" do
|
187
|
-
with_files(['a/a_test.rb','b/b_test.rb', 'c/c_test.rb']) do |root|
|
188
|
-
call(["#{root}/a", "#{root}/b"]).sort.should == [
|
189
|
-
"#{root}/a/a_test.rb",
|
190
|
-
"#{root}/b/b_test.rb",
|
191
|
-
]
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
it "only finds tests in folders" do
|
196
|
-
with_files(['a/a_test.rb', 'a/test.rb', 'a/test_helper.rb']) do |root|
|
197
|
-
call(["#{root}/a"]).sort.should == [
|
198
|
-
"#{root}/a/a_test.rb"
|
199
|
-
]
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
it "finds tests in nested folders" do
|
204
|
-
with_files(['a/b/c/d/a_test.rb']) do |root|
|
205
|
-
call(["#{root}/a"]).sort.should == [
|
206
|
-
"#{root}/a/b/c/d/a_test.rb"
|
207
|
-
]
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
it "does not expand paths" do
|
212
|
-
with_files(['a/x_test.rb']) do |root|
|
213
|
-
inside_dir root do
|
214
|
-
call(['a']).sort.should == [
|
215
|
-
"a/x_test.rb"
|
216
|
-
]
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
it "finds test files in folders by pattern" do
|
222
|
-
with_files(['a/x_test.rb','a/y_test.rb','a/z_test.rb']) do |root|
|
223
|
-
inside_dir root do
|
224
|
-
call(["a"], :pattern => /^a\/(y|z)_test/).sort.should == [
|
225
|
-
"a/y_test.rb",
|
226
|
-
"a/z_test.rb",
|
227
|
-
]
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
it "finds nothing if I pass nothing" do
|
233
|
-
call(nil).should == []
|
234
|
-
end
|
235
|
-
|
236
|
-
it "finds nothing if I pass nothing (empty array)" do
|
237
|
-
call([]).should == []
|
238
|
-
end
|
239
|
-
|
240
|
-
it "keeps invalid files" do
|
241
|
-
call(['baz']).should == ['baz']
|
242
|
-
end
|
243
|
-
|
244
|
-
it "discards duplicates" do
|
245
|
-
call(['baz','baz']).should == ['baz']
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe ".summarize_results" do
|
250
|
-
def call(*args)
|
251
|
-
ParallelTests::Test::Runner.summarize_results(*args)
|
252
|
-
end
|
253
|
-
|
254
|
-
it "adds results" do
|
255
|
-
call(['1 foo 3 bar','2 foo 5 bar']).should == '8 bars, 3 foos'
|
256
|
-
end
|
257
|
-
|
258
|
-
it "adds results with braces" do
|
259
|
-
call(['1 foo(s) 3 bar(s)','2 foo 5 bar']).should == '8 bars, 3 foos'
|
260
|
-
end
|
261
|
-
|
262
|
-
it "adds same results with plurals" do
|
263
|
-
call(['1 foo 3 bar','2 foos 5 bar']).should == '8 bars, 3 foos'
|
264
|
-
end
|
265
|
-
|
266
|
-
it "adds non-similar results" do
|
267
|
-
call(['1 xxx 2 yyy','1 xxx 2 zzz']).should == '2 xxxs, 2 yyys, 2 zzzs'
|
268
|
-
end
|
269
|
-
|
270
|
-
it "does not pluralize 1" do
|
271
|
-
call(['1 xxx 2 yyy']).should == '1 xxx, 2 yyys'
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
describe ".execute_command" do
|
276
|
-
def call(*args)
|
277
|
-
ParallelTests::Test::Runner.execute_command(*args)
|
278
|
-
end
|
279
|
-
|
280
|
-
def capture_output
|
281
|
-
$stdout, $stderr = StringIO.new, StringIO.new
|
282
|
-
yield
|
283
|
-
[$stdout.string, $stderr.string]
|
284
|
-
ensure
|
285
|
-
$stdout, $stderr = STDOUT, STDERR
|
286
|
-
end
|
287
|
-
|
288
|
-
def run_with_file(content)
|
289
|
-
capture_output do
|
290
|
-
Tempfile.open("xxx") do |f|
|
291
|
-
f.write(content)
|
292
|
-
f.flush
|
293
|
-
yield f.path
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
it "sets process number to 2 for 1" do
|
299
|
-
run_with_file("puts ENV['TEST_ENV_NUMBER']") do |path|
|
300
|
-
result = call("ruby #{path}", 1, 4, {})
|
301
|
-
result.should == {
|
302
|
-
:stdout => "2\n",
|
303
|
-
:exit_status => 0
|
304
|
-
}
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
it "sets process number to '' for 0" do
|
309
|
-
run_with_file("puts ENV['TEST_ENV_NUMBER'].inspect") do |path|
|
310
|
-
result = call("ruby #{path}", 0, 4, {})
|
311
|
-
result.should == {
|
312
|
-
:stdout => "\"\"\n",
|
313
|
-
:exit_status => 0
|
314
|
-
}
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'sets PARALLEL_TEST_GROUPS so child processes know that they are being run under parallel_tests' do
|
319
|
-
run_with_file("puts ENV['PARALLEL_TEST_GROUPS']") do |path|
|
320
|
-
result = call("ruby #{path}", 1, 4, {})
|
321
|
-
result.should == {
|
322
|
-
:stdout => "4\n",
|
323
|
-
:exit_status => 0
|
324
|
-
}
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
it "skips reads from stdin" do
|
329
|
-
pending "hangs on normal ruby, works on jruby" unless RUBY_PLATFORM == "java"
|
330
|
-
run_with_file("$stdin.read; puts 123") do |path|
|
331
|
-
result = call("ruby #{path}", 1, 2, {})
|
332
|
-
result.should == {
|
333
|
-
:stdout => "123\n",
|
334
|
-
:exit_status => 0
|
335
|
-
}
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
it "waits for process to finish" do
|
340
|
-
run_with_file("sleep 0.5; puts 123; sleep 0.5; puts 345") do |path|
|
341
|
-
result = call("ruby #{path}", 1, 4, {})
|
342
|
-
result.should == {
|
343
|
-
:stdout => "123\n345\n",
|
344
|
-
:exit_status => 0
|
345
|
-
}
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
it "prints output while running" do
|
350
|
-
pending "too slow" if RUBY_PLATFORM == " java"
|
351
|
-
run_with_file("$stdout.sync = true; puts 123; sleep 0.1; print 345; sleep 0.1; puts 567") do |path|
|
352
|
-
received = ""
|
353
|
-
$stdout.stub(:print).with{|x| received << x.strip }
|
354
|
-
result = call("ruby #{path}", 1, 4, {})
|
355
|
-
received.should == "123345567"
|
356
|
-
result.should == {
|
357
|
-
:stdout => "123\n345567\n",
|
358
|
-
:exit_status => 0
|
359
|
-
}
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
it "works with synced stdout" do
|
364
|
-
run_with_file("$stdout.sync = true; puts 123; sleep 0.1; puts 345") do |path|
|
365
|
-
result = call("ruby #{path}", 1, 4, {})
|
366
|
-
result.should == {
|
367
|
-
:stdout => "123\n345\n",
|
368
|
-
:exit_status => 0
|
369
|
-
}
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
it "does not print to stdout with :serialize_stdout" do
|
374
|
-
run_with_file("puts 123") do |path|
|
375
|
-
$stdout.should_not_receive(:print)
|
376
|
-
result = call("ruby #{path}", 1, 4, :serialize_stdout => true)
|
377
|
-
result.should == {
|
378
|
-
:stdout => "123\n",
|
379
|
-
:exit_status => 0
|
380
|
-
}
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
it "returns correct exit status" do
|
385
|
-
run_with_file("puts 123; exit 5") do |path|
|
386
|
-
result = call("ruby #{path}", 1, 4, {})
|
387
|
-
result.should == {
|
388
|
-
:stdout => "123\n",
|
389
|
-
:exit_status => 5
|
390
|
-
}
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
it "prints each stream to the correct stream" do
|
395
|
-
pending "open3"
|
396
|
-
out, err = run_with_file("puts 123 ; $stderr.puts 345 ; exit 5") do |path|
|
397
|
-
result = call("ruby #{path}", 1, 4, {})
|
398
|
-
result.should == {
|
399
|
-
:stdout => "123\n",
|
400
|
-
:exit_status => 5
|
401
|
-
}
|
402
|
-
end
|
403
|
-
err.should == "345\n"
|
404
|
-
end
|
405
|
-
|
406
|
-
it "uses a lower priority process when the nice option is used" do
|
407
|
-
priority_cmd = "puts Process.getpriority(Process::PRIO_PROCESS, 0)"
|
408
|
-
priority_without_nice = run_with_file(priority_cmd){ |cmd| call("ruby #{cmd}", 1, 4, {}) }.first.to_i
|
409
|
-
priority_with_nice = run_with_file(priority_cmd){ |cmd| call("ruby #{cmd}", 1, 4, :nice => true) }.first.to_i
|
410
|
-
priority_without_nice.should < priority_with_nice
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|