-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
286 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require_relative "runner/cached_test_file" | ||
|
||
module Retest | ||
class Runner | ||
include Observable | ||
include CachedTestFile | ||
|
||
attr_accessor :command, :stdout | ||
def initialize(command, stdout: $stdout) | ||
@stdout = stdout | ||
@command = command | ||
end | ||
|
||
def ==(obj) | ||
return false unless obj.command | ||
|
||
command.to_s == obj.command.to_s && self.class == obj.class | ||
end | ||
|
||
def run(changed_files: [], test_files: []) | ||
changed_file = changed_files.is_a?(Array) ? changed_files.first : changed_files | ||
test_file = test_files.is_a?(Array) ? test_files.first : test_files | ||
|
||
self.cached_test_file = test_file | ||
|
||
if command.to_s.include?('<changed>') | ||
if changed_file.nil? | ||
print_changed_file_not_found | ||
return | ||
end | ||
log("Changed File Selected: #{changed_file}") | ||
end | ||
|
||
if command.to_s.include?('<test>') | ||
if cached_test_file.nil? | ||
print_test_file_not_found | ||
return | ||
end | ||
log("Test File Selected: #{cached_test_file}") | ||
end | ||
|
||
system_run command.to_s | ||
.gsub('<test>', cached_test_file.to_s) | ||
.gsub('<changed>', changed_file.to_s) | ||
end | ||
|
||
def run_all_tests(tests_string) | ||
log("Test Files Selected: #{tests_string}") | ||
system_run command.to_s.gsub('<test>', tests_string) | ||
end | ||
|
||
def sync(added:, removed:) | ||
purge_test_file(removed) | ||
end | ||
|
||
def running? | ||
@running | ||
end | ||
|
||
private | ||
|
||
def system_run(command) | ||
@running = true | ||
result = system(command) ? :tests_pass : :tests_fail | ||
changed | ||
notify_observers(result) | ||
@running = false | ||
end | ||
|
||
def log(message) | ||
stdout.puts(message) | ||
end | ||
|
||
def print_changed_file_not_found | ||
log(<<~ERROR) | ||
FileNotFound - Retest could not find a changed file to run. | ||
ERROR | ||
end | ||
|
||
def print_test_file_not_found | ||
log(<<~ERROR) | ||
FileNotFound - Retest could not find a matching test file to run. | ||
ERROR | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Retest | ||
module CachedTestFile | ||
def cached_test_file | ||
@cached_test_file | ||
end | ||
|
||
def cached_test_file=(value) | ||
@cached_test_file = value || @cached_test_file | ||
end | ||
|
||
def purge_test_file(purged) | ||
return if purged.empty? | ||
|
||
if purged.is_a?(Array) && purged.include?(cached_test_file) | ||
@cached_test_file = nil | ||
elsif purged.is_a?(String) && purged == cached_test_file | ||
@cached_test_file = nil | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
test/retest/runners/observable_runner.rb → test/retest/runner/observable_runner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/retest/runners/runner_interface.rb → test/retest/runner/runner_interface.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.