retest 2.0.0.pre2 → 2.0.0.pre4
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/.github/workflows/ci.yml +6 -6
- data/Gemfile.lock +16 -2
- data/exe/retest +54 -59
- data/lib/retest/command/base.rb +53 -0
- data/lib/retest/command/hardcoded.rb +5 -0
- data/lib/retest/command/rails.rb +11 -13
- data/lib/retest/command/rake.rb +12 -14
- data/lib/retest/command/rspec.rb +11 -13
- data/lib/retest/command/ruby.rb +5 -12
- data/lib/retest/command.rb +9 -1
- data/lib/retest/program/forced_selection.rb +19 -0
- data/lib/retest/program/pausable.rb +4 -0
- data/lib/retest/program.rb +38 -32
- data/lib/retest/repository.rb +4 -0
- data/lib/retest/runner/cached_test_file.rb +19 -0
- data/lib/retest/runner.rb +98 -0
- data/lib/retest/version.rb +1 -1
- data/lib/retest.rb +2 -1
- data/retest.gemspec +1 -0
- metadata +22 -9
- data/lib/retest/runners/cached_test_file.rb +0 -23
- data/lib/retest/runners/change_runner.rb +0 -21
- data/lib/retest/runners/runner.rb +0 -47
- data/lib/retest/runners/test_runner.rb +0 -36
- data/lib/retest/runners/variable_runner.rb +0 -39
- data/lib/retest/runners.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ba870b22885e9928d0224cef1147fb2caced390abf7d86777dfc500ac83777c
|
4
|
+
data.tar.gz: 6aafc91c49b9243590d590a6a0debc3faedd797926a4a34f54b03bf28d4dc74a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61b46cf027a29b0c8478ce27d848ebc7086cb2db1b2d7992032d9ebc6bf04e00d7c662c1b1cf73851c6c99404f168c6359d1f6d0bb952afa4655fe93cfd4ed8f
|
7
|
+
data.tar.gz: 517f06d9b1c65288ae74e6cc459692d9458ae62e03089f7c18e642137bba5180945f210ba7cb5bf458feda0c0fe19887dd91ef6ca864c0306518f5e60d7cfaa1
|
data/.github/workflows/ci.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (2.0.0.
|
4
|
+
retest (2.0.0.pre4)
|
5
5
|
listen (~> 3.9)
|
6
6
|
observer (~> 0.1)
|
7
7
|
string-similarity (~> 2.1)
|
8
8
|
tty-option (~> 0.1)
|
9
|
+
tty-prompt (~> 0.1)
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
@@ -17,12 +18,25 @@ GEM
|
|
17
18
|
rb-inotify (~> 0.9, >= 0.9.10)
|
18
19
|
minitest (5.15.0)
|
19
20
|
observer (0.1.2)
|
21
|
+
pastel (0.8.0)
|
22
|
+
tty-color (~> 0.5)
|
20
23
|
rake (13.0.6)
|
21
24
|
rb-fsevent (0.11.2)
|
22
25
|
rb-inotify (0.11.1)
|
23
26
|
ffi (~> 1.0)
|
24
27
|
string-similarity (2.1.0)
|
28
|
+
tty-color (0.6.0)
|
29
|
+
tty-cursor (0.7.1)
|
25
30
|
tty-option (0.3.0)
|
31
|
+
tty-prompt (0.23.1)
|
32
|
+
pastel (~> 0.8)
|
33
|
+
tty-reader (~> 0.8)
|
34
|
+
tty-reader (0.9.0)
|
35
|
+
tty-cursor (~> 0.7)
|
36
|
+
tty-screen (~> 0.8)
|
37
|
+
wisper (~> 2.0)
|
38
|
+
tty-screen (0.8.2)
|
39
|
+
wisper (2.0.1)
|
26
40
|
|
27
41
|
PLATFORMS
|
28
42
|
ruby
|
@@ -34,4 +48,4 @@ DEPENDENCIES
|
|
34
48
|
retest!
|
35
49
|
|
36
50
|
BUNDLED WITH
|
37
|
-
2.
|
51
|
+
2.4.21
|
data/exe/retest
CHANGED
@@ -3,13 +3,11 @@
|
|
3
3
|
require 'retest'
|
4
4
|
|
5
5
|
$stdout.sync = true
|
6
|
-
|
7
|
-
runner_rd, runner_wr = IO.pipe
|
8
|
-
|
6
|
+
listen_rd, listen_wr = IO.pipe
|
9
7
|
Signal.trap(:INT) do
|
10
8
|
$stdout.puts "Goodbye"
|
11
|
-
|
12
|
-
|
9
|
+
listen_rd.close
|
10
|
+
listen_wr.close
|
13
11
|
exit
|
14
12
|
end
|
15
13
|
|
@@ -25,29 +23,23 @@ if options.version?
|
|
25
23
|
return
|
26
24
|
end
|
27
25
|
|
28
|
-
prompt = Retest::Prompt.new
|
26
|
+
prompt = Retest::Prompt.new
|
29
27
|
repository = Retest::Repository.new(files: Retest::VersionControl.files, prompt: prompt)
|
30
28
|
command = Retest::Command.for_options(options)
|
31
|
-
runner = Retest::
|
29
|
+
runner = Retest::Runner.new(command)
|
32
30
|
sounds = Retest::Sounds.for(options)
|
33
31
|
|
34
|
-
# All test runner
|
35
|
-
all_test_command = Retest::Command.for_options(options.merge(%w[--all]), stdout: nil)
|
36
|
-
all_test_runner = Retest::Runners.runner_for(all_test_command.to_s)
|
37
|
-
all_test_runner.add_observer(sounds)
|
38
|
-
|
39
32
|
sounds.play(:start)
|
40
33
|
runner.add_observer(sounds)
|
41
34
|
prompt.add_observer(sounds)
|
42
35
|
|
43
36
|
program = Retest::Program.new(
|
44
37
|
repository: repository,
|
45
|
-
command: command,
|
46
38
|
runner: runner
|
47
39
|
)
|
48
40
|
|
49
41
|
if options.params[:diff]
|
50
|
-
program.
|
42
|
+
program.diff(options.params[:diff])
|
51
43
|
return
|
52
44
|
end
|
53
45
|
|
@@ -61,46 +53,22 @@ end
|
|
61
53
|
$stdout.puts launching_message
|
62
54
|
Retest.listen(options) do |modified, added, removed|
|
63
55
|
begin
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
repository.sync(added: added, removed: removed)
|
57
|
+
runner.sync(added: added, removed: removed)
|
58
|
+
|
59
|
+
listen_wr.puts "file changed: #{(modified + added).first}"
|
67
60
|
rescue => e
|
68
61
|
$stdout.puts "Something went wrong: #{e.message}"
|
69
62
|
end
|
70
63
|
end
|
71
64
|
$stdout.puts "Ready to refactor! You can make file changes now"
|
72
65
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
loop do
|
81
|
-
print_interactive_message
|
82
|
-
|
83
|
-
puts "waiting for input"
|
84
|
-
input = $stdin.gets.to_s.chomp
|
85
|
-
|
86
|
-
puts "input is: #{input.inspect}"
|
87
|
-
|
88
|
-
if prompt.question_asked?
|
89
|
-
prompt_wr.puts input
|
90
|
-
next
|
91
|
-
end
|
92
|
-
|
93
|
-
if all_test_runner.running?
|
94
|
-
$stdin.puts input
|
95
|
-
next
|
96
|
-
end
|
97
|
-
|
98
|
-
if runner.running?
|
99
|
-
runner_wr.puts input
|
100
|
-
next
|
101
|
-
end
|
102
|
-
|
103
|
-
case input
|
66
|
+
def run_command(input:, program:)
|
67
|
+
program.clear_terminal
|
68
|
+
case input.strip
|
69
|
+
when /^file changed:\s(.*)$/
|
70
|
+
puts "File changed: #{$1}"
|
71
|
+
program.run($1)
|
104
72
|
when 'p', 'pause'
|
105
73
|
program.pause
|
106
74
|
puts "Program is paused\n"
|
@@ -109,26 +77,53 @@ loop do
|
|
109
77
|
puts "Program has been resumed\n"
|
110
78
|
when 'e', 'exit'
|
111
79
|
Process.kill("INT", 0)
|
80
|
+
when 'r', 'reset'
|
81
|
+
program.reset_selection
|
82
|
+
puts "command reset to '#{program.runner.command.to_s}'"
|
83
|
+
when 'f', 'force'
|
84
|
+
require 'tty-prompt'
|
85
|
+
prompt = TTY::Prompt.new
|
86
|
+
program.force_selection prompt.multi_select(
|
87
|
+
"What test files do you want to run when saving a file?",
|
88
|
+
program.repository.test_files,
|
89
|
+
filter: true, min: 1
|
90
|
+
)
|
91
|
+
program.run(nil, force_run: true)
|
112
92
|
when ''
|
113
|
-
puts "Running last command\n"
|
114
|
-
program.
|
93
|
+
puts "Running last command: '#{program.last_command}'\n"
|
94
|
+
program.run_last_command
|
115
95
|
when 'ra', 'run all'
|
116
96
|
puts "Running all tests\n"
|
117
|
-
|
97
|
+
program.run_all
|
118
98
|
when /^di?f?f?\s(.*)$/
|
119
|
-
program.
|
99
|
+
program.diff($1)
|
120
100
|
when 'h', 'help'
|
121
101
|
puts <<~HELP
|
122
102
|
|
123
|
-
* 'h', 'help' # Prints help
|
124
|
-
* 'p', 'pause' # Pauses Retest. Tests aren't run until unpaused.
|
125
|
-
* 'u', 'unpause' # Unpauses Retest
|
126
|
-
* <ENTER> # Runs last changed triggered command
|
127
|
-
* 'ra, 'run all' # Runs all tests
|
128
|
-
* '
|
129
|
-
* '
|
103
|
+
* 'h', 'help' # Prints help.
|
104
|
+
* 'p', 'pause' # Pauses Retest. Tests aren't run on file change events until unpaused.
|
105
|
+
* 'u', 'unpause' # Unpauses Retest.
|
106
|
+
* <ENTER> # Runs last changed triggered command.
|
107
|
+
* 'ra, 'run all' # Runs all tests.
|
108
|
+
* 'f', 'force' # Forces a selection of test to run on every file change.
|
109
|
+
* 'r', 'reset' # Disables forced selection.
|
110
|
+
* 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch.
|
111
|
+
* 'e', 'exit' # Exits Retest.
|
130
112
|
HELP
|
131
113
|
else
|
132
114
|
puts "Unknown interactive command #{input}\n"
|
133
115
|
end
|
134
116
|
end
|
117
|
+
|
118
|
+
connections = [$stdin, listen_rd]
|
119
|
+
loop do
|
120
|
+
puts "\nType interactive command and press enter. Enter 'h' for help."
|
121
|
+
print(">\s")
|
122
|
+
|
123
|
+
ready = IO.select(connections)
|
124
|
+
readable_connections = ready[0]
|
125
|
+
readable_connections.each do |conn|
|
126
|
+
data = conn.readpartial(4096)
|
127
|
+
run_command(input: data.to_s.chomp, program: program)
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Retest
|
2
|
+
class Command
|
3
|
+
class MultipleTestsNotSupported < StandardError; end
|
4
|
+
|
5
|
+
class Base
|
6
|
+
def initialize(all: false, file_system: FileSystem, command: nil)
|
7
|
+
@file_system = file_system
|
8
|
+
@all = all
|
9
|
+
@command = command
|
10
|
+
end
|
11
|
+
|
12
|
+
def clone(params = {})
|
13
|
+
self.class.new(**{ all: all, file_system: file_system, command: command }.merge(params))
|
14
|
+
end
|
15
|
+
|
16
|
+
def has_changed?
|
17
|
+
to_s.include?('<changed>')
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_test?
|
21
|
+
to_s.include?('<test>')
|
22
|
+
end
|
23
|
+
|
24
|
+
def changed_type?
|
25
|
+
!has_test? && has_changed?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_type?
|
29
|
+
has_test? && !has_changed?
|
30
|
+
end
|
31
|
+
|
32
|
+
def variable_type?
|
33
|
+
has_test? && has_changed?
|
34
|
+
end
|
35
|
+
|
36
|
+
def hardcoded_type?
|
37
|
+
!has_test? && !has_changed?
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
@command
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_batch(*files)
|
45
|
+
raise MultipleTestsNotSupported, "Multiple test files run not supported for '#{to_s}'"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :all, :file_system, :command
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/retest/command/rails.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
class Rails
|
4
|
-
attr_reader :all, :file_system
|
5
|
-
|
6
|
-
def initialize(all:, file_system: FileSystem)
|
7
|
-
@file_system = file_system
|
8
|
-
@all = all
|
9
|
-
end
|
10
|
-
|
3
|
+
class Rails < Base
|
11
4
|
def to_s
|
12
|
-
|
13
|
-
|
5
|
+
if all
|
6
|
+
root_command
|
7
|
+
else
|
8
|
+
"#{root_command} <test>"
|
9
|
+
end
|
14
10
|
end
|
15
11
|
|
16
12
|
def format_batch(*files)
|
@@ -20,9 +16,11 @@ module Retest
|
|
20
16
|
private
|
21
17
|
|
22
18
|
def root_command
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
if file_system.exist? 'bin/rails'
|
20
|
+
'bin/rails test'
|
21
|
+
else
|
22
|
+
'bundle exec rails test'
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
data/lib/retest/command/rake.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
class Rake
|
4
|
-
attr_reader :all, :file_system
|
5
|
-
|
6
|
-
def initialize(all:, file_system: FileSystem)
|
7
|
-
@file_system = file_system
|
8
|
-
@all = all
|
9
|
-
end
|
10
|
-
|
3
|
+
class Rake < Base
|
11
4
|
def to_s
|
12
|
-
|
13
|
-
|
5
|
+
if all
|
6
|
+
root_command
|
7
|
+
else
|
8
|
+
"#{root_command} TEST=<test>"
|
9
|
+
end
|
14
10
|
end
|
15
11
|
|
16
12
|
def format_batch(*files)
|
17
|
-
files.size > 1 ? "
|
13
|
+
files.size > 1 ? %Q{"{#{files.join(',')}}"} : files.first
|
18
14
|
end
|
19
15
|
|
20
16
|
private
|
21
17
|
|
22
18
|
def root_command
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
if file_system.exist? 'bin/rake'
|
20
|
+
'bin/rake test'
|
21
|
+
else
|
22
|
+
'bundle exec rake test'
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
data/lib/retest/command/rspec.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
class Rspec
|
4
|
-
attr_reader :all, :file_system
|
5
|
-
|
6
|
-
def initialize(all:, file_system: FileSystem)
|
7
|
-
@file_system = file_system
|
8
|
-
@all = all
|
9
|
-
end
|
10
|
-
|
3
|
+
class Rspec < Base
|
11
4
|
def to_s
|
12
|
-
|
13
|
-
|
5
|
+
if all
|
6
|
+
root_command
|
7
|
+
else
|
8
|
+
"#{root_command} <test>"
|
9
|
+
end
|
14
10
|
end
|
15
11
|
|
16
12
|
def format_batch(*files)
|
@@ -20,9 +16,11 @@ module Retest
|
|
20
16
|
private
|
21
17
|
|
22
18
|
def root_command
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
if file_system.exist? 'bin/rspec'
|
20
|
+
'bin/rspec'
|
21
|
+
else
|
22
|
+
'bundle exec rspec'
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
data/lib/retest/command/ruby.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
class Ruby
|
4
|
-
attr_reader :all, :file_system
|
5
|
-
|
6
|
-
def initialize(all:, file_system: FileSystem)
|
7
|
-
@file_system = file_system
|
8
|
-
@all = all
|
9
|
-
end
|
10
|
-
|
11
|
-
def format_batch(*files)
|
12
|
-
%Q{-e "#{files.map { |file| "require './#{file}';" }.join}"}
|
13
|
-
end
|
14
|
-
|
3
|
+
class Ruby < Base
|
15
4
|
def to_s
|
16
5
|
if file_system.exist? 'Gemfile.lock'
|
17
6
|
'bundle exec ruby <test>'
|
@@ -19,6 +8,10 @@ module Retest
|
|
19
8
|
'ruby <test>'
|
20
9
|
end
|
21
10
|
end
|
11
|
+
|
12
|
+
def format_batch(*files)
|
13
|
+
files.size > 1 ? %Q{-e "#{files.map { |file| "require './#{file}';" }.join}"} : files.first
|
14
|
+
end
|
22
15
|
end
|
23
16
|
end
|
24
17
|
end
|
data/lib/retest/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'command/base'
|
2
|
+
require_relative 'command/hardcoded'
|
1
3
|
require_relative 'command/rails'
|
2
4
|
require_relative 'command/rake'
|
3
5
|
require_relative 'command/rspec'
|
@@ -26,7 +28,9 @@ module Retest
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def options_command
|
29
|
-
|
31
|
+
if params[:command]
|
32
|
+
return hardcoded_command(params[:command])
|
33
|
+
end
|
30
34
|
|
31
35
|
if params[:rspec] then rspec_command
|
32
36
|
elsif params[:rails] then rails_command
|
@@ -57,6 +61,10 @@ module Retest
|
|
57
61
|
@stdout&.puts(message)
|
58
62
|
end
|
59
63
|
|
64
|
+
def hardcoded_command(command)
|
65
|
+
Hardcoded.new(command: command)
|
66
|
+
end
|
67
|
+
|
60
68
|
def rspec_command
|
61
69
|
Rspec.new(all: full_suite?)
|
62
70
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForcedSelection
|
2
|
+
attr_reader :selected_test_files
|
3
|
+
|
4
|
+
def initialize_forced_selection(value = [])
|
5
|
+
@selected_test_files = value
|
6
|
+
end
|
7
|
+
|
8
|
+
def forced_selection?
|
9
|
+
!@selected_test_files.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset_selection
|
13
|
+
@selected_test_files = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def force_selection(test_files)
|
17
|
+
@selected_test_files = Array(test_files)
|
18
|
+
end
|
19
|
+
end
|
data/lib/retest/program.rb
CHANGED
@@ -1,58 +1,64 @@
|
|
1
1
|
require_relative 'program/pausable'
|
2
|
+
require_relative 'program/forced_selection'
|
2
3
|
|
3
4
|
module Retest
|
4
5
|
class Program
|
6
|
+
extend Forwardable
|
5
7
|
include Pausable
|
8
|
+
include ForcedSelection
|
6
9
|
|
7
|
-
attr_accessor :runner, :repository, :
|
8
|
-
|
10
|
+
attr_accessor :runner, :repository, :stdout
|
11
|
+
|
12
|
+
def_delegators :runner,
|
13
|
+
:run_last_command, :last_command
|
14
|
+
|
15
|
+
def initialize(runner: nil, repository: nil, clear_window: true, stdout: $stdout)
|
9
16
|
@runner = runner
|
10
17
|
@repository = repository
|
11
|
-
@command = command
|
12
18
|
@clear_window = clear_window
|
19
|
+
@stdout = stdout
|
13
20
|
initialize_pause(false)
|
21
|
+
initialize_forced_selection([])
|
14
22
|
end
|
15
23
|
|
16
|
-
def run(
|
17
|
-
|
18
|
-
|
24
|
+
def run(file, force_run: false)
|
25
|
+
if paused? && !force_run
|
26
|
+
@stdout.puts "Main program paused. Please resume program first."
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
if forced_selection?
|
31
|
+
@stdout.puts <<~HINT
|
32
|
+
Forced selection enabled.
|
33
|
+
Reset to default settings by typing 'r' in the interactive console.
|
19
34
|
|
20
|
-
|
35
|
+
HINT
|
21
36
|
|
22
|
-
|
23
|
-
|
24
|
-
|
37
|
+
runner.run(test_files: selected_test_files)
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
test_file = if runner.has_test?
|
42
|
+
repository.find_test(file)
|
43
|
+
end
|
44
|
+
|
45
|
+
runner.run changed_files: [file], test_files: [test_file]
|
25
46
|
end
|
26
47
|
|
27
48
|
def diff(branch)
|
28
49
|
raise "Git not installed" unless VersionControl::Git.installed?
|
29
|
-
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
30
|
-
|
31
|
-
puts "Tests found:"
|
32
|
-
test_files.each { |test_file| puts " - #{test_file}" }
|
33
50
|
|
34
|
-
|
35
|
-
|
51
|
+
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
52
|
+
run_selected(test_files)
|
36
53
|
end
|
37
54
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
begin
|
42
|
-
pause
|
43
|
-
old_command_stdin = runner.command_stdin
|
44
|
-
old_prompt_stdin = prompt.input
|
45
|
-
prompt.input = $stdin
|
46
|
-
runner.command_stdin = $stdin
|
47
|
-
yield
|
48
|
-
ensure
|
49
|
-
resume
|
50
|
-
runner.command_stdin = old_command_stdin
|
51
|
-
prompt.input = old_prompt_stdin
|
52
|
-
end
|
55
|
+
def run_all
|
56
|
+
runner.run_all
|
53
57
|
end
|
54
58
|
|
55
|
-
|
59
|
+
def run_selected(test_files)
|
60
|
+
runner.run(test_files: test_files)
|
61
|
+
end
|
56
62
|
|
57
63
|
def clear_terminal
|
58
64
|
return unless @clear_window
|
data/lib/retest/repository.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Retest
|
2
|
+
module CachedTestFile
|
3
|
+
attr_reader :cached_test_file
|
4
|
+
|
5
|
+
def cached_test_file=(value)
|
6
|
+
@cached_test_file = value || cached_test_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def purge_test_file(purged)
|
10
|
+
return if purged.empty?
|
11
|
+
|
12
|
+
if purged.is_a?(Array) && purged.include?(cached_test_file)
|
13
|
+
@cached_test_file = nil
|
14
|
+
elsif purged.is_a?(String) && purged == cached_test_file
|
15
|
+
@cached_test_file = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative "runner/cached_test_file"
|
2
|
+
|
3
|
+
module Retest
|
4
|
+
class Runner
|
5
|
+
extend Forwardable
|
6
|
+
include Observable
|
7
|
+
include CachedTestFile
|
8
|
+
|
9
|
+
def_delegators :command,
|
10
|
+
:has_changed?, :has_test?,
|
11
|
+
:changed_type?, :test_type?, :variable_type?, :harcoded_type?
|
12
|
+
|
13
|
+
attr_accessor :command, :stdout, :last_command
|
14
|
+
def initialize(command, stdout: $stdout)
|
15
|
+
@stdout = stdout
|
16
|
+
@command = command
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_last_command
|
20
|
+
system_run last_command
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(changed_files: [], test_files: [])
|
24
|
+
self.last_command = format_instruction(changed_files: changed_files, test_files: test_files)
|
25
|
+
system_run last_command
|
26
|
+
rescue FileNotFound => e
|
27
|
+
log("FileNotFound - #{e.message}")
|
28
|
+
rescue Command::MultipleTestsNotSupported => e
|
29
|
+
log("Command::MultipleTestsNotSupported - #{e.message}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_all
|
33
|
+
system_run command.clone(all: true).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def format_instruction(changed_files: [], test_files: [])
|
37
|
+
if changed_files.empty? && test_files.size >= 1
|
38
|
+
instruction = command.clone(all: false).to_s
|
39
|
+
tests_string = command.format_batch(*test_files)
|
40
|
+
log("Tests selected:")
|
41
|
+
test_files.each { |test_file| log(" - #{test_file}") }
|
42
|
+
return instruction.gsub('<test>', tests_string)
|
43
|
+
end
|
44
|
+
|
45
|
+
instruction = command.to_s
|
46
|
+
instruction = format_changed_files(instruction: instruction, files: changed_files)
|
47
|
+
instruction = format_test_files(instruction: instruction, files: test_files)
|
48
|
+
end
|
49
|
+
|
50
|
+
def format_test_files(instruction:, files:)
|
51
|
+
return instruction unless has_test?
|
52
|
+
|
53
|
+
self.cached_test_file = files.first
|
54
|
+
|
55
|
+
if cached_test_file.nil?
|
56
|
+
raise FileNotFound, "Retest could not find a matching test file to run."
|
57
|
+
end
|
58
|
+
|
59
|
+
log("Test file: #{cached_test_file}")
|
60
|
+
instruction.gsub('<test>', cached_test_file)
|
61
|
+
end
|
62
|
+
|
63
|
+
def format_changed_files(instruction:, files:)
|
64
|
+
return instruction unless has_changed?
|
65
|
+
changed_file = files.first
|
66
|
+
|
67
|
+
if changed_file.nil?
|
68
|
+
raise FileNotFound, "Retest could not find a changed file to run."
|
69
|
+
end
|
70
|
+
|
71
|
+
log("Changed file: #{changed_file}")
|
72
|
+
instruction.gsub('<changed>', changed_file)
|
73
|
+
end
|
74
|
+
|
75
|
+
def sync(added:, removed:)
|
76
|
+
purge_test_file(removed)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def print_test_file_not_found
|
82
|
+
log(<<~ERROR)
|
83
|
+
FileNotFound - Retest could not find a matching test file to run.
|
84
|
+
ERROR
|
85
|
+
end
|
86
|
+
|
87
|
+
def system_run(command)
|
88
|
+
log("\n")
|
89
|
+
result = system(command) ? :tests_pass : :tests_fail
|
90
|
+
changed
|
91
|
+
notify_observers(result)
|
92
|
+
end
|
93
|
+
|
94
|
+
def log(message)
|
95
|
+
stdout.puts(message)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/retest/version.rb
CHANGED
data/lib/retest.rb
CHANGED
@@ -4,7 +4,7 @@ require 'string/similarity'
|
|
4
4
|
require 'observer'
|
5
5
|
|
6
6
|
require "retest/version"
|
7
|
-
require "retest/
|
7
|
+
require "retest/runner"
|
8
8
|
require "retest/repository"
|
9
9
|
require "retest/matching_options"
|
10
10
|
require "retest/options"
|
@@ -20,6 +20,7 @@ Listen.adapter_warn_behavior = :log
|
|
20
20
|
|
21
21
|
module Retest
|
22
22
|
class Error < StandardError; end
|
23
|
+
class FileNotFound < StandardError; end
|
23
24
|
|
24
25
|
def self.listen(options, listener: Listen)
|
25
26
|
listener.to('.', only: options.extension, relative: true, force_polling: options.force_polling?) do |modified, added, removed|
|
data/retest.gemspec
CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
|
29
29
|
spec.add_runtime_dependency "listen", ["~> 3.9"]
|
30
30
|
spec.add_runtime_dependency "tty-option", ["~> 0.1"]
|
31
|
+
spec.add_runtime_dependency "tty-prompt", ["~> 0.1"]
|
31
32
|
spec.add_runtime_dependency "observer", ["~> 0.1"]
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.pre4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Barret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-prompt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: observer
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +112,8 @@ files:
|
|
98
112
|
- exe/retest
|
99
113
|
- lib/retest.rb
|
100
114
|
- lib/retest/command.rb
|
115
|
+
- lib/retest/command/base.rb
|
116
|
+
- lib/retest/command/hardcoded.rb
|
101
117
|
- lib/retest/command/rails.rb
|
102
118
|
- lib/retest/command/rake.rb
|
103
119
|
- lib/retest/command/rspec.rb
|
@@ -107,15 +123,12 @@ files:
|
|
107
123
|
- lib/retest/matching_options/path.rb
|
108
124
|
- lib/retest/options.rb
|
109
125
|
- lib/retest/program.rb
|
126
|
+
- lib/retest/program/forced_selection.rb
|
110
127
|
- lib/retest/program/pausable.rb
|
111
128
|
- lib/retest/prompt.rb
|
112
129
|
- lib/retest/repository.rb
|
113
|
-
- lib/retest/
|
114
|
-
- lib/retest/
|
115
|
-
- lib/retest/runners/change_runner.rb
|
116
|
-
- lib/retest/runners/runner.rb
|
117
|
-
- lib/retest/runners/test_runner.rb
|
118
|
-
- lib/retest/runners/variable_runner.rb
|
130
|
+
- lib/retest/runner.rb
|
131
|
+
- lib/retest/runner/cached_test_file.rb
|
119
132
|
- lib/retest/setup.rb
|
120
133
|
- lib/retest/sounds.rb
|
121
134
|
- lib/retest/version.rb
|
@@ -144,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
157
|
- !ruby/object:Gem::Version
|
145
158
|
version: 1.3.1
|
146
159
|
requirements: []
|
147
|
-
rubygems_version: 3.1
|
160
|
+
rubygems_version: 3.0.3.1
|
148
161
|
signing_key:
|
149
162
|
specification_version: 4
|
150
163
|
summary: A simple command line tool to watch file change and run its matching spec.
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Retest
|
2
|
-
module Runners
|
3
|
-
module CachedTestFile
|
4
|
-
def cached_test_file
|
5
|
-
@cached_test_file
|
6
|
-
end
|
7
|
-
|
8
|
-
def cached_test_file=(value)
|
9
|
-
@cached_test_file = value || @cached_test_file
|
10
|
-
end
|
11
|
-
|
12
|
-
def purge_test_file(purged)
|
13
|
-
return if purged.empty?
|
14
|
-
|
15
|
-
if purged.is_a?(Array) && purged.include?(cached_test_file)
|
16
|
-
@cached_test_file = nil
|
17
|
-
elsif purged.is_a?(String) && purged == cached_test_file
|
18
|
-
@cached_test_file = nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Retest
|
2
|
-
module Runners
|
3
|
-
class ChangeRunner < Runner
|
4
|
-
def run(changed_file = nil, repository: nil)
|
5
|
-
return print_file_not_found unless changed_file
|
6
|
-
|
7
|
-
log("Changed File Selected: #{changed_file}")
|
8
|
-
system_run command.gsub('<changed>', changed_file)
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def print_file_not_found
|
14
|
-
log(<<~ERROR)
|
15
|
-
404 - File Not Found
|
16
|
-
Retest could not find a changed file to run.
|
17
|
-
ERROR
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Retest
|
2
|
-
module Runners
|
3
|
-
class Runner
|
4
|
-
include Observable
|
5
|
-
|
6
|
-
attr_accessor :command, :stdout, :command_stdin
|
7
|
-
def initialize(command, stdout: $stdout, command_stdin: $stdin)
|
8
|
-
@stdout = stdout
|
9
|
-
@command = command
|
10
|
-
@command_stdin = command_stdin
|
11
|
-
end
|
12
|
-
|
13
|
-
def ==(obj)
|
14
|
-
command == obj.command && obj.class == self.class
|
15
|
-
end
|
16
|
-
|
17
|
-
def run(changed_file = nil, repository: nil)
|
18
|
-
system_run command
|
19
|
-
end
|
20
|
-
|
21
|
-
def run_all_tests(tests_string)
|
22
|
-
raise NotSupportedError, 'cannot run multiple test files against this command'
|
23
|
-
end
|
24
|
-
|
25
|
-
def sync(added:, removed:)
|
26
|
-
end
|
27
|
-
|
28
|
-
def running?
|
29
|
-
@running
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def system_run(command)
|
35
|
-
@running = true
|
36
|
-
result = system(command, in: @command_stdin) ? :tests_pass : :tests_fail
|
37
|
-
changed
|
38
|
-
notify_observers(result)
|
39
|
-
@running = false
|
40
|
-
end
|
41
|
-
|
42
|
-
def log(message)
|
43
|
-
stdout.puts(message)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative "cached_test_file"
|
2
|
-
|
3
|
-
module Retest
|
4
|
-
module Runners
|
5
|
-
class TestRunner < Runner
|
6
|
-
include CachedTestFile
|
7
|
-
|
8
|
-
def run(changed_file, repository:)
|
9
|
-
self.cached_test_file = repository.find_test(changed_file)
|
10
|
-
|
11
|
-
return print_file_not_found unless cached_test_file
|
12
|
-
|
13
|
-
log("Test File Selected: #{cached_test_file}")
|
14
|
-
system_run command.gsub('<test>', cached_test_file)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run_all_tests(tests_string)
|
18
|
-
log("Test File Selected: #{tests_string}")
|
19
|
-
system_run command.gsub('<test>', tests_string)
|
20
|
-
end
|
21
|
-
|
22
|
-
def sync(added:, removed:)
|
23
|
-
purge_test_file(removed)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def print_file_not_found
|
29
|
-
log(<<~ERROR)
|
30
|
-
404 - Test File Not Found
|
31
|
-
Retest could not find a matching test file to run.
|
32
|
-
ERROR
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative "cached_test_file"
|
2
|
-
|
3
|
-
module Retest
|
4
|
-
module Runners
|
5
|
-
class VariableRunner < Runner
|
6
|
-
include CachedTestFile
|
7
|
-
|
8
|
-
def run(changed_file, repository:)
|
9
|
-
self.cached_test_file = repository.find_test(changed_file)
|
10
|
-
|
11
|
-
return print_file_not_found unless cached_test_file
|
12
|
-
|
13
|
-
log(<<~FILES)
|
14
|
-
Files Selected:
|
15
|
-
- changed: #{changed_file}
|
16
|
-
- test: #{cached_test_file}
|
17
|
-
|
18
|
-
FILES
|
19
|
-
|
20
|
-
system_run command
|
21
|
-
.gsub('<test>', cached_test_file)
|
22
|
-
.gsub('<changed>', changed_file)
|
23
|
-
end
|
24
|
-
|
25
|
-
def sync(added:, removed:)
|
26
|
-
purge_test_file(removed)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def print_file_not_found
|
32
|
-
log(<<~ERROR)
|
33
|
-
404 - Test File Not Found
|
34
|
-
Retest could not find a matching test file to run.
|
35
|
-
ERROR
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/retest/runners.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'runners/runner'
|
2
|
-
require_relative 'runners/test_runner'
|
3
|
-
require_relative 'runners/change_runner'
|
4
|
-
require_relative 'runners/variable_runner'
|
5
|
-
|
6
|
-
module Retest
|
7
|
-
module Runners
|
8
|
-
class NotSupportedError < StandardError; end
|
9
|
-
|
10
|
-
module_function
|
11
|
-
|
12
|
-
def runner_for(command, **opts)
|
13
|
-
for_test = command.include?('<test>')
|
14
|
-
for_change = command.include?('<changed>')
|
15
|
-
|
16
|
-
if for_test && for_change then VariableRunner
|
17
|
-
elsif for_test then TestRunner
|
18
|
-
elsif for_change then ChangeRunner
|
19
|
-
else Runner
|
20
|
-
end.new command, **opts
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|