mighty_test 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83c44a15f432d51e09d5c772fd11bb8e6054eaf98cbcc76e08e8f8050c1e03bd
4
- data.tar.gz: 5908e6428920eb6aedcc993a24ad44587b7e6355f9002b07358c095717f865f6
3
+ metadata.gz: 67f7cd918d844868eef2785d5337b21a23cfb5a77944c6408f01319c948ca0c9
4
+ data.tar.gz: 51e988bb537870235b93ddcc638bb14c8445b1ad04af6bf832b4690de20c623a
5
5
  SHA512:
6
- metadata.gz: 912d2cc77b7b732439f129ce082d140d15216221aa8fd8c4e0a6a9082c3129c238bb29f8841303d12dfe6c43b96f4c37f76090bada21114843b5c4db933ea9b2
7
- data.tar.gz: 4d1468bc39fa04b7445b97bb58e559d798e3978067a29ad841ba82d3fbe2b6c893592231116f5fa41df3d567cbd352aea49b57fd098b0cf04db3d11bfb2f58e5
6
+ metadata.gz: 17228cb3ed005b781296855e61081f0724788913276323cbd70a8591aa02dbf792476b82ade4494e52ff4940e78f106a9666f905855e1173e9ed42d76bb32306
7
+ data.tar.gz: 8a37977044f595aa51530e3d7da4599f62be1bcacadb3e16375168c4815f5550e7e4c9db0dea2997f5bd930c9dfed2c8a0077331d8143d710e0d38a8c6b278db
data/README.md CHANGED
@@ -211,7 +211,7 @@ bin/mt
211
211
  bin/mt --no-rg
212
212
  ```
213
213
 
214
- (image goes here)
214
+ <img alt="Screenshot of bin/mt output" width="618" src="https://raw.githubusercontent.com/mattbrictson/mighty_test/main/screenshot.png">
215
215
 
216
216
  This functionality is provided by the [minitest-rg](https://github.com/minitest/minitest-rg) plugin, which is included with mighty_test.
217
217
 
@@ -16,9 +16,10 @@ module MightyTest
16
16
  end
17
17
 
18
18
  def wait_for_keypress
19
- return stdin.getc unless stdin.respond_to?(:raw) && tty?
20
-
21
- stdin.raw(intr: true) { stdin.getc }
19
+ with_raw_input do
20
+ sleep if stdin.eof?
21
+ stdin.getc
22
+ end
22
23
  end
23
24
 
24
25
  def play_sound(name, wait: false)
@@ -54,5 +55,11 @@ module MightyTest
54
55
  def tty?
55
56
  $stdout.respond_to?(:tty?) && $stdout.tty?
56
57
  end
58
+
59
+ def with_raw_input(&)
60
+ return yield unless stdin.respond_to?(:raw) && tty?
61
+
62
+ stdin.raw(intr: true, &)
63
+ end
57
64
  end
58
65
  end
@@ -1,3 +1,3 @@
1
1
  module MightyTest
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -1,47 +1,58 @@
1
1
  module MightyTest
2
- class Watcher # rubocop:disable Metrics/ClassLength
2
+ class Watcher
3
+ class ListenerTriggered < StandardError
4
+ attr_reader :paths
5
+
6
+ def initialize(paths)
7
+ @paths = paths
8
+ super()
9
+ end
10
+ end
11
+
3
12
  WATCHING_FOR_CHANGES = 'Watching for changes to source and test files. Press "h" for help or "q" to quit.'.freeze
4
13
 
5
14
  def initialize(console: Console.new, extra_args: [], file_system: FileSystem.new, system_proc: method(:system))
6
- @queue = Thread::Queue.new
7
15
  @console = console
8
16
  @extra_args = extra_args
9
17
  @file_system = file_system
10
18
  @system_proc = system_proc
11
19
  end
12
20
 
13
- def run(iterations: :indefinitely) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
14
- start_file_system_listener
15
- start_keypress_listener
16
- puts WATCHING_FOR_CHANGES
21
+ def run(iterations: :indefinitely) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
22
+ started = false
23
+ @foreground_thread = Thread.current
17
24
 
18
25
  loop_for(iterations) do
19
- case await_next_event
20
- in [:file_system_changed, [_, *] => paths]
21
- run_matching_test_files(paths)
22
- in [:keypress, "\r" | "\n"]
26
+ start_file_system_listener && puts(WATCHING_FOR_CHANGES) unless started
27
+ started = true
28
+
29
+ case console.wait_for_keypress
30
+ when "\r", "\n"
23
31
  run_all_tests
24
- in [:keypress, "a"]
32
+ when "a"
25
33
  run_all_tests(flags: ["--all"])
26
- in [:keypress, "d"]
34
+ when "d"
27
35
  run_matching_test_files_from_git_diff
28
- in [:keypress, "h"]
36
+ when "h"
29
37
  show_help
30
- in [:keypress, "q"]
38
+ when "q"
39
+ file_system_listener.stop
31
40
  break
32
- else
33
- nil
34
41
  end
42
+ rescue ListenerTriggered => e
43
+ run_matching_test_files(e.paths)
44
+ file_system_listener.start if file_system_listener.paused?
45
+ rescue Interrupt
46
+ file_system_listener&.stop
47
+ raise
35
48
  end
36
49
  ensure
37
50
  puts "\nExiting."
38
- file_system_listener&.stop
39
- keypress_listener&.kill
40
51
  end
41
52
 
42
53
  private
43
54
 
44
- attr_reader :console, :extra_args, :file_system, :file_system_listener, :keypress_listener, :system_proc
55
+ attr_reader :console, :extra_args, :file_system, :file_system_listener, :system_proc, :foreground_thread
45
56
 
46
57
  def show_help
47
58
  console.clear
@@ -105,36 +116,18 @@ module MightyTest
105
116
  file_system_listener.stop if file_system_listener && !file_system_listener.stopped?
106
117
 
107
118
  @file_system_listener = file_system.listen do |modified, added, _removed|
119
+ paths = [*modified, *added].uniq
120
+ next if paths.empty?
121
+
108
122
  # Pause listener so that subsequent changes are queued up while we are running the tests
109
123
  file_system_listener.pause unless file_system_listener.stopped?
110
- post_event(:file_system_changed, [*modified, *added].uniq)
124
+ foreground_thread.raise ListenerTriggered.new(paths)
111
125
  end
112
126
  end
113
127
  alias restart_file_system_listener start_file_system_listener
114
128
 
115
- def start_keypress_listener
116
- @keypress_listener = Thread.new do
117
- loop do
118
- key = console.wait_for_keypress
119
- break if key.nil?
120
-
121
- post_event(:keypress, key)
122
- end
123
- end
124
- @keypress_listener.abort_on_exception = true
125
- end
126
-
127
129
  def loop_for(iterations, &)
128
130
  iterations == :indefinitely ? loop(&) : iterations.times(&)
129
131
  end
130
-
131
- def await_next_event
132
- file_system_listener.start if file_system_listener.paused?
133
- @queue.pop
134
- end
135
-
136
- def post_event(*event)
137
- @queue << event
138
- end
139
132
  end
140
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mighty_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-29 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.5.5
128
+ rubygems_version: 3.5.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: A modern Minitest runner for TDD, with watch mode and more