test_launcher 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/bin/test_launcher +2 -5
- data/lib/test_launcher/cli/input_parser.rb +37 -12
- data/lib/test_launcher/cli/query.rb +30 -0
- data/lib/test_launcher/cli/request.rb +61 -0
- data/lib/test_launcher/cli.rb +44 -0
- data/lib/test_launcher/frameworks/base.rb +26 -7
- data/lib/test_launcher/frameworks/elixir.rb +84 -0
- data/lib/test_launcher/frameworks/implementation/test_case.rb +4 -7
- data/lib/test_launcher/frameworks/minitest.rb +80 -23
- data/lib/test_launcher/frameworks/rspec.rb +38 -13
- data/lib/test_launcher/queries.rb +346 -0
- data/lib/test_launcher/rubymine/launcher.rb +1 -12
- data/lib/test_launcher/rubymine/request.rb +15 -0
- data/lib/test_launcher/rubymine.rb +20 -13
- data/lib/test_launcher/search/ag.rb +96 -0
- data/lib/test_launcher/search/git.rb +6 -2
- data/lib/test_launcher/search.rb +18 -0
- data/lib/test_launcher/shell/runner.rb +2 -1
- data/lib/test_launcher/version.rb +1 -1
- data/lib/test_launcher.rb +0 -26
- data/test/test_helper.rb +2 -1
- data/test/test_helpers/integration_helper.rb +40 -0
- data/test/test_helpers/mock.rb +59 -0
- data/test/test_helpers/mock_searcher.rb +1 -0
- data/test/test_helpers/mocks/searcher_mock.rb +82 -0
- data/test/test_helpers/mocks.rb +76 -0
- data/test/test_launcher/cli/input_parser_test.rb +72 -0
- data/test/test_launcher/frameworks/minitest/runner_test.rb +72 -0
- data/test/test_launcher/frameworks/minitest/searcher_test.rb +109 -0
- data/test/test_launcher/frameworks/rspec/runner_test.rb +76 -0
- data/test/test_launcher/frameworks/rspec/searcher_test.rb +54 -0
- data/test/test_launcher/minitest_integration_test.rb +31 -40
- data/test/test_launcher/queries/example_name_query_test.rb +217 -0
- data/test/test_launcher/queries/full_regex_query_test.rb +153 -0
- data/test/test_launcher/queries/generic_query_test.rb +23 -0
- data/test/test_launcher/queries/line_number_query_test.rb +107 -0
- data/test/test_launcher/queries/multi_term_query_test.rb +138 -0
- data/test/test_launcher/queries/path_query_test.rb +192 -0
- data/test/test_launcher/queries/search_query_test.rb +54 -0
- data/test/test_launcher/queries/single_term_query_test.rb +36 -0
- data/test/test_launcher/queries/specified_name_query_test.rb +112 -0
- data/test/test_launcher/rspec_integration_test.rb +27 -41
- data/test/test_launcher/search/git_test.rb +2 -0
- metadata +49 -10
- data/lib/test_launcher/frameworks/implementation/collection.rb +0 -36
- data/lib/test_launcher/frameworks/implementation/consolidator.rb +0 -83
- data/lib/test_launcher/frameworks/implementation/locator.rb +0 -118
- data/lib/test_launcher/frameworks.rb +0 -20
- data/lib/test_launcher/request.rb +0 -36
- data/test/test_launcher/frameworks/implementation/locator_test.rb +0 -166
@@ -1,83 +1,74 @@
|
|
1
1
|
require "test_helper"
|
2
|
-
require "
|
2
|
+
require "test_helpers/integration_helper"
|
3
3
|
|
4
4
|
module TestLauncher
|
5
5
|
class MinitestIntegrationTest < TestCase
|
6
|
+
include IntegrationHelper
|
7
|
+
|
6
8
|
def test__single_method
|
7
|
-
launch("file_name_1__method_name_1")
|
8
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} --name
|
9
|
+
launch("file_name_1__method_name_1", framework: "minitest")
|
10
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} --name=file_name_1__method_name_1", shell_mock.recall_exec
|
9
11
|
end
|
10
12
|
|
11
13
|
def test__multiple_methods__same_file
|
12
|
-
launch("file_name_1")
|
13
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} --name=/file_name_1/",
|
14
|
+
launch("file_name_1", framework: "minitest")
|
15
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} --name=/file_name_1/", shell_mock.recall_exec
|
14
16
|
end
|
15
17
|
|
16
18
|
def test__multiple_methods__different_files
|
17
|
-
launch("multiple_files__same_method")
|
18
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")} --name
|
19
|
+
launch("multiple_files__same_method", framework: "minitest")
|
20
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")} --name=multiple_files__same_method", shell_mock.recall_exec
|
19
21
|
end
|
20
22
|
|
21
23
|
def test__single_file
|
22
|
-
launch("class_1_test")
|
23
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}",
|
24
|
+
launch("class_1_test", framework: "minitest")
|
25
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}", shell_mock.recall_exec
|
24
26
|
end
|
25
27
|
|
26
28
|
def test__uses_spring
|
27
|
-
launch("different_roo""t_test") # don't trigger the find in *this* file
|
28
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest/test/different_root")} && bundle exec spring testunit #{system_path("test/test_launcher/fixtures/minitest/test/different_root/test/different_root_test.rb")}",
|
29
|
+
launch("different_roo""t_test", framework: "minitest") # don't trigger the find in *this* file
|
30
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest/test/different_root")} && bundle exec spring testunit #{system_path("test/test_launcher/fixtures/minitest/test/different_root/test/different_root_test.rb")}", shell_mock.recall_exec
|
29
31
|
end
|
30
32
|
|
31
33
|
def test__multiple_files__found
|
32
|
-
launch("Root1""Dum""myTest""Class") # don't trigger the find in *this* file
|
33
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}",
|
34
|
+
launch("Root1""Dum""myTest""Class", framework: "minitest") # don't trigger the find in *this* file
|
35
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}", shell_mock.recall_exec
|
34
36
|
end
|
35
37
|
|
36
38
|
def test__multiple_files__found__all
|
37
|
-
launch("Root1""DummyTest""Class", run_all: true) # don't trigger the find in *this* file
|
38
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}",
|
39
|
+
launch("Root1""DummyTest""Class", run_all: true, framework: "minitest") # don't trigger the find in *this* file
|
40
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}", shell_mock.recall_exec
|
39
41
|
end
|
40
42
|
|
41
43
|
def test__multiple_file_paths
|
42
|
-
launch("class_1_tes""t.rb class_2_test.rb") # don't trigger the find in *this* file
|
43
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}",
|
44
|
+
launch("class_1_tes""t.rb class_2_test.rb", framework: "minitest") # don't trigger the find in *this* file
|
45
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}", shell_mock.recall_exec
|
44
46
|
end
|
45
47
|
|
46
48
|
def test__multiple_files__different_roots__all
|
47
|
-
launch("DummyTest""Class", run_all: true) # don't trigger the find in *this* file
|
49
|
+
launch("DummyTest""Class", run_all: true, framework: "minitest") # don't trigger the find in *this* file
|
48
50
|
expected = "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} #{system_path("test/test_launcher/fixtures/minitest/test/class_2_test.rb")}; cd -;\n\ncd #{system_path("test/test_launcher/fixtures/minitest/test/different_root")} && bundle exec spring testunit #{system_path("test/test_launcher/fixtures/minitest/test/different_root/test/different_root_test.rb")}"
|
49
|
-
assert_equal expected,
|
51
|
+
assert_equal expected, shell_mock.recall_exec
|
50
52
|
end
|
51
53
|
|
52
54
|
def test__regex
|
53
|
-
launch("Root1""DummyTest""Class1""Test") # don't trigger the find in *this* file
|
54
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}",
|
55
|
+
launch("Root1""DummyTest""Class1""Test", framework: "minitest") # don't trigger the find in *this* file
|
56
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}", shell_mock.recall_exec
|
55
57
|
end
|
56
58
|
|
57
59
|
def test__regex__does_not_test_helper__methods
|
58
|
-
launch("helper_meth""od") # don't trigger the find in *this* file
|
59
|
-
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}",
|
60
|
+
launch("helper_meth""od", framework: "minitest") # don't trigger the find in *this* file
|
61
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test -e 'ARGV.each {|f| require(f)}' #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")}", shell_mock.recall_exec
|
60
62
|
end
|
61
63
|
|
62
|
-
def
|
63
|
-
launch("
|
64
|
-
assert_equal
|
64
|
+
def test__specified_name
|
65
|
+
launch("class_1_test.rb", name: "file_name_1__method_name_1", framework: "minitest") # don't trigger the find in *this* file
|
66
|
+
assert_equal "cd #{system_path("test/test_launcher/fixtures/minitest")} && bundle exec ruby -I test #{system_path("test/test_launcher/fixtures/minitest/test/class_1_test.rb")} --name=file_name_1__method_name_1", shell_mock.recall_exec
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
File.join(Dir.pwd, relative_dir)
|
71
|
-
end
|
72
|
-
|
73
|
-
def launch(query, run_all: false)
|
74
|
-
request = Request.new(
|
75
|
-
query: query,
|
76
|
-
run_all: run_all,
|
77
|
-
framework: "minitest"
|
78
|
-
)
|
79
|
-
|
80
|
-
TestLauncher.launch(request)
|
69
|
+
def test__not_found
|
70
|
+
launch("not_found""thing", framework: "minitest")
|
71
|
+
assert_equal nil, shell_mock.recall_exec
|
81
72
|
end
|
82
73
|
|
83
74
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "test_helpers/mocks"
|
3
|
+
require "test_launcher/queries"
|
4
|
+
require "test_launcher/frameworks/minitest"
|
5
|
+
|
6
|
+
module TestLauncher
|
7
|
+
module Queries
|
8
|
+
class ExampleNameQueryTest < TestCase
|
9
|
+
include DefaultMocks
|
10
|
+
|
11
|
+
def raw_searcher
|
12
|
+
@raw_searcher ||= MemorySearcher.new do |searcher|
|
13
|
+
searcher.mock_file do |f|
|
14
|
+
f.path "file_1_test.rb"
|
15
|
+
f.mtime Time.now - 3000
|
16
|
+
f.contents <<-RB
|
17
|
+
class SingleTest
|
18
|
+
def test__one_example
|
19
|
+
matches_single
|
20
|
+
end
|
21
|
+
|
22
|
+
def test__same_file_1
|
23
|
+
end
|
24
|
+
|
25
|
+
def test__same_file_2
|
26
|
+
end
|
27
|
+
|
28
|
+
def test__different_files
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RB
|
32
|
+
end
|
33
|
+
|
34
|
+
searcher.mock_file do |f|
|
35
|
+
f.path "file_2_test.rb"
|
36
|
+
f.mtime Time.now
|
37
|
+
f.contents <<-RB
|
38
|
+
class MultipleMatches1Test
|
39
|
+
def test__different_files
|
40
|
+
end
|
41
|
+
end
|
42
|
+
RB
|
43
|
+
end
|
44
|
+
|
45
|
+
searcher.mock_file do |f|
|
46
|
+
f.path "multiple_matches_2_test.rb"
|
47
|
+
f.mtime Time.now
|
48
|
+
f.contents <<-RB
|
49
|
+
class MultipleMatches2Test
|
50
|
+
def test__1
|
51
|
+
multiple_matches_2
|
52
|
+
end
|
53
|
+
|
54
|
+
def test__2
|
55
|
+
multiple_matches_2
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RB
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def searcher
|
64
|
+
@searcher ||= Frameworks::Minitest::Searcher.new(raw_searcher)
|
65
|
+
end
|
66
|
+
|
67
|
+
def runner
|
68
|
+
@runner ||= MockRunner.new do |m|
|
69
|
+
|
70
|
+
m.impl :single_example do |test_case|
|
71
|
+
"single_example #{test_case.file} #{test_case.example}"
|
72
|
+
end
|
73
|
+
|
74
|
+
m.impl :multiple_examples_same_file do |test_cases|
|
75
|
+
"multiple_examples_same_file #{test_cases.first.file} #{test_cases.first.example}"
|
76
|
+
end
|
77
|
+
|
78
|
+
m.impl :multiple_files do |test_cases|
|
79
|
+
"multiple_files #{test_cases.map(&:file).join(" ")}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_command__example_not_found__returns_nil
|
85
|
+
request = MockRequest.new(
|
86
|
+
search_string: "not_found",
|
87
|
+
searcher: searcher
|
88
|
+
)
|
89
|
+
|
90
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
91
|
+
|
92
|
+
assert_equal nil, command
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_command__one_example_found
|
96
|
+
request = MockRequest.new(
|
97
|
+
search_string: "one_example",
|
98
|
+
searcher: searcher,
|
99
|
+
runner: runner,
|
100
|
+
shell: default_shell
|
101
|
+
)
|
102
|
+
|
103
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
104
|
+
|
105
|
+
assert_equal "single_example file_1_test.rb one_example", command
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_command__one_example_found__notifies
|
109
|
+
request = MockRequest.new(
|
110
|
+
search_string: "one_example",
|
111
|
+
searcher: searcher,
|
112
|
+
runner: runner,
|
113
|
+
shell: default_shell
|
114
|
+
)
|
115
|
+
|
116
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
117
|
+
|
118
|
+
messages = [
|
119
|
+
["Found 1 example in 1 file."],
|
120
|
+
]
|
121
|
+
assert_equal messages, default_shell.recall(:notify)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_command__multiple_examples__one_file
|
125
|
+
request = MockRequest.new(
|
126
|
+
search_string: "same_file",
|
127
|
+
searcher: searcher,
|
128
|
+
runner: runner,
|
129
|
+
shell: default_shell
|
130
|
+
)
|
131
|
+
|
132
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
133
|
+
|
134
|
+
assert_equal "multiple_examples_same_file file_1_test.rb same_file", command
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_command__multiple_examples__one_file__notifies
|
138
|
+
request = MockRequest.new(
|
139
|
+
search_string: "same_file",
|
140
|
+
searcher: searcher,
|
141
|
+
runner: runner,
|
142
|
+
shell: default_shell
|
143
|
+
)
|
144
|
+
|
145
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
146
|
+
|
147
|
+
messages = [
|
148
|
+
["Found 2 examples in 1 file."],
|
149
|
+
]
|
150
|
+
assert_equal messages, default_shell.recall(:notify)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_command__multiple_examples__multiple_files__no_all
|
154
|
+
request = MockRequest.new(
|
155
|
+
search_string: "different_files",
|
156
|
+
searcher: searcher,
|
157
|
+
runner: runner,
|
158
|
+
shell: default_shell,
|
159
|
+
run_all?: false
|
160
|
+
)
|
161
|
+
|
162
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
163
|
+
|
164
|
+
assert_equal "single_example file_2_test.rb different_files", command
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_command__multiple_examples__multiple_files__no_all__notifies
|
168
|
+
request = MockRequest.new(
|
169
|
+
search_string: "different_files",
|
170
|
+
searcher: searcher,
|
171
|
+
runner: runner,
|
172
|
+
shell: default_shell,
|
173
|
+
run_all?: false
|
174
|
+
)
|
175
|
+
|
176
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
177
|
+
|
178
|
+
messages = [
|
179
|
+
["Found 2 examples in 2 files."],
|
180
|
+
["Running most recently edited. Run with '--all' to run all the tests."],
|
181
|
+
]
|
182
|
+
assert_equal messages, default_shell.recall(:notify)
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_command__multiple_examples__multiple_files__all
|
186
|
+
request = MockRequest.new(
|
187
|
+
search_string: "different_files",
|
188
|
+
searcher: searcher,
|
189
|
+
runner: runner,
|
190
|
+
shell: default_shell,
|
191
|
+
run_all?: true
|
192
|
+
)
|
193
|
+
|
194
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
195
|
+
|
196
|
+
assert_equal "multiple_files file_1_test.rb file_2_test.rb", command
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_command__multiple_examples__multiple_files__all__notifies
|
200
|
+
request = MockRequest.new(
|
201
|
+
search_string: "different_files",
|
202
|
+
searcher: searcher,
|
203
|
+
runner: runner,
|
204
|
+
shell: default_shell,
|
205
|
+
run_all?: true
|
206
|
+
)
|
207
|
+
|
208
|
+
command = ExampleNameQuery.new(request, default_command_finder).command
|
209
|
+
|
210
|
+
messages = [
|
211
|
+
["Found 2 examples in 2 files."],
|
212
|
+
]
|
213
|
+
assert_equal messages, default_shell.recall(:notify)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "test_helpers/mocks"
|
3
|
+
require "test_launcher/queries"
|
4
|
+
require "test_launcher/frameworks/minitest"
|
5
|
+
|
6
|
+
module TestLauncher
|
7
|
+
module Queries
|
8
|
+
class FullRegexQueryTest < TestCase
|
9
|
+
include DefaultMocks
|
10
|
+
|
11
|
+
def raw_searcher
|
12
|
+
@raw_searcher ||= MemorySearcher.new do |searcher|
|
13
|
+
searcher.mock_file do |f|
|
14
|
+
f.path "single_test.rb"
|
15
|
+
f.contents <<-RB
|
16
|
+
class SingleTest
|
17
|
+
def test__1
|
18
|
+
matches_single
|
19
|
+
end
|
20
|
+
end
|
21
|
+
RB
|
22
|
+
end
|
23
|
+
|
24
|
+
searcher.mock_file do |f|
|
25
|
+
f.path "multiple_matches_1_test.rb"
|
26
|
+
f.mtime Time.now - 3000
|
27
|
+
f.contents <<-RB
|
28
|
+
class MultipleMatches1Test
|
29
|
+
def test__1
|
30
|
+
multiple_matches_1
|
31
|
+
end
|
32
|
+
|
33
|
+
def test__2
|
34
|
+
multiple_matches_1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
RB
|
38
|
+
end
|
39
|
+
|
40
|
+
searcher.mock_file do |f|
|
41
|
+
f.path "multiple_matches_2_test.rb"
|
42
|
+
f.mtime Time.now
|
43
|
+
f.contents <<-RB
|
44
|
+
class MultipleMatches2Test
|
45
|
+
def test__1
|
46
|
+
multiple_matches_2
|
47
|
+
end
|
48
|
+
|
49
|
+
def test__2
|
50
|
+
multiple_matches_2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RB
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def searcher
|
59
|
+
@searcher ||= Frameworks::Minitest::Searcher.new(raw_searcher)
|
60
|
+
end
|
61
|
+
|
62
|
+
def runner
|
63
|
+
@runner ||= MockRunner.new do |m|
|
64
|
+
m.impl :single_file do |test_case|
|
65
|
+
case test_case.file
|
66
|
+
when "single_test.rb"
|
67
|
+
"single_file single_test.rb"
|
68
|
+
when "multiple_matches_1_test.rb"
|
69
|
+
"single_file multiple_matches_1_test.rb"
|
70
|
+
when "multiple_matches_2_test.rb"
|
71
|
+
"single_file multiple_matches_2_test.rb"
|
72
|
+
else
|
73
|
+
raise "unmocked single_file: #{test_case.file}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
m.impl :multiple_files do |test_cases|
|
78
|
+
case test_cases.map(&:file)
|
79
|
+
when ["multiple_matches_1_test.rb", "multiple_matches_2_test.rb"]
|
80
|
+
"multiple_files multiple_matches_1_test.rb multiple_matches_2_test.rb"
|
81
|
+
else
|
82
|
+
raise "unmocked multiple_files: #{test_cases}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_command__regex_not_found
|
89
|
+
request = MockRequest.new(
|
90
|
+
search_string: "not_found",
|
91
|
+
searcher: searcher
|
92
|
+
)
|
93
|
+
|
94
|
+
command = FullRegexQuery.new(request, default_command_finder).command
|
95
|
+
assert_equal nil, command
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_command__single_match
|
99
|
+
request = MockRequest.new(
|
100
|
+
search_string: "single",
|
101
|
+
searcher: searcher,
|
102
|
+
runner: runner,
|
103
|
+
shell: default_shell
|
104
|
+
)
|
105
|
+
|
106
|
+
command = FullRegexQuery.new(request, default_command_finder).command
|
107
|
+
|
108
|
+
assert_equal "single_file single_test.rb", command
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_command__multiple_matches_same_file
|
112
|
+
request = MockRequest.new(
|
113
|
+
search_string: "multiple_matches_1",
|
114
|
+
searcher: searcher,
|
115
|
+
runner: runner,
|
116
|
+
shell: default_shell
|
117
|
+
)
|
118
|
+
|
119
|
+
command = FullRegexQuery.new(request, default_command_finder).command
|
120
|
+
|
121
|
+
assert_equal "single_file multiple_matches_1_test.rb", command
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_command__multiple_matches_different_files__no_all
|
125
|
+
request = MockRequest.new(
|
126
|
+
search_string: "multiple_matches",
|
127
|
+
searcher: searcher,
|
128
|
+
runner: runner,
|
129
|
+
shell: default_shell,
|
130
|
+
run_all?: false
|
131
|
+
)
|
132
|
+
|
133
|
+
command = FullRegexQuery.new(request, default_command_finder).command
|
134
|
+
|
135
|
+
assert_equal "single_file multiple_matches_2_test.rb", command
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_command__multiple_matches_different_files__all
|
139
|
+
request = MockRequest.new(
|
140
|
+
search_string: "multiple_matches",
|
141
|
+
searcher: searcher,
|
142
|
+
runner: runner,
|
143
|
+
shell: default_shell,
|
144
|
+
run_all?: true
|
145
|
+
)
|
146
|
+
|
147
|
+
command = FullRegexQuery.new(request, default_command_finder).command
|
148
|
+
|
149
|
+
assert_equal "multiple_files multiple_matches_1_test.rb multiple_matches_2_test.rb", command
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "test_helpers/mocks"
|
3
|
+
require "test_launcher/queries"
|
4
|
+
|
5
|
+
module TestLauncher
|
6
|
+
module Queries
|
7
|
+
class GenericQueryTest < TestCase
|
8
|
+
include DefaultMocks
|
9
|
+
|
10
|
+
def test__specified_name
|
11
|
+
command_finder = Mock.new(Queries::CommandFinder, specified_name: :specified_name)
|
12
|
+
|
13
|
+
assert_equal :specified_name, GenericQuery.new(MockRequest.new(example_name: "name_present"), command_finder).command
|
14
|
+
end
|
15
|
+
|
16
|
+
def test__example_name
|
17
|
+
command_finder = Mock.new(Queries::CommandFinder, full_search: :full_search)
|
18
|
+
|
19
|
+
assert_equal :full_search, GenericQuery.new(MockRequest.new(example_name: nil), command_finder).command
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "test_helpers/mocks"
|
3
|
+
require "test_launcher/queries"
|
4
|
+
|
5
|
+
module TestLauncher
|
6
|
+
module Queries
|
7
|
+
class LineNumberQueryTest < TestCase
|
8
|
+
include DefaultMocks
|
9
|
+
|
10
|
+
def searcher
|
11
|
+
@searcher ||= MockSearcher.new do |m|
|
12
|
+
m.impl :by_line do |file, line_number|
|
13
|
+
case [file, line_number]
|
14
|
+
when ["not_found", 1]
|
15
|
+
nil
|
16
|
+
when ["found", 17]
|
17
|
+
{file: "found", example_name: "test_example", line_number: 14}
|
18
|
+
when ["found", 1]
|
19
|
+
{file: "found"}
|
20
|
+
when ["found", 9999]
|
21
|
+
raise "invalid line number"
|
22
|
+
when ["multiple", 1]
|
23
|
+
raise "multiple files matched with line query"
|
24
|
+
else
|
25
|
+
raise "unmocked search_string: #{file}, #{line_number}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_mock_request(**attrs)
|
32
|
+
MockRequest.new(**attrs) do |m|
|
33
|
+
m.impl(:test_case) do |file:, example: nil, request:, line_number: nil|
|
34
|
+
case [file, example]
|
35
|
+
when ["found", nil]
|
36
|
+
whole_file_test_case
|
37
|
+
when ["found", "test_example"]
|
38
|
+
example_name_test_case
|
39
|
+
else
|
40
|
+
raise "unmocked file: #{file}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def whole_file_test_case
|
47
|
+
@whole_file_test_case ||= MockTestCase.new(file: "found")
|
48
|
+
end
|
49
|
+
|
50
|
+
def example_name_test_case
|
51
|
+
@example_name_test_case ||= MockTestCase.new(file: "found", example_name: "test_example")
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_command__file_not_found
|
55
|
+
request = create_mock_request(
|
56
|
+
search_string: "not_found:1",
|
57
|
+
searcher: searcher
|
58
|
+
)
|
59
|
+
|
60
|
+
command = LineNumberQuery.new(request, default_command_finder).command
|
61
|
+
assert_equal nil, command
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_command__search_string_does_not_have_colon
|
65
|
+
request = create_mock_request(
|
66
|
+
search_string: "not_found",
|
67
|
+
searcher: searcher
|
68
|
+
)
|
69
|
+
|
70
|
+
command = LineNumberQuery.new(request, default_command_finder).command
|
71
|
+
|
72
|
+
assert_equal nil, command
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_command__file_found__line_number_not_in_example
|
76
|
+
request = create_mock_request(
|
77
|
+
search_string: "found:1",
|
78
|
+
searcher: searcher,
|
79
|
+
runner: default_runner,
|
80
|
+
shell: default_shell
|
81
|
+
)
|
82
|
+
|
83
|
+
command = LineNumberQuery.new(request, default_command_finder).command
|
84
|
+
|
85
|
+
assert_equal [[whole_file_test_case]], default_runner.recall(:single_file)
|
86
|
+
|
87
|
+
assert_equal "single_file_return", command
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def test_command__file_found__line_number_inside_example
|
92
|
+
request = create_mock_request(
|
93
|
+
search_string: "found:17",
|
94
|
+
searcher: searcher,
|
95
|
+
runner: default_runner,
|
96
|
+
shell: default_shell
|
97
|
+
)
|
98
|
+
|
99
|
+
command = LineNumberQuery.new(request, default_command_finder).command
|
100
|
+
|
101
|
+
assert_equal [[example_name_test_case]], default_runner.recall(:single_example)
|
102
|
+
|
103
|
+
assert_equal "single_example_return", command
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|