retest 2.0.0.pre2 → 2.0.0.pre3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09eb72dbc99fae984bbd2d445461bc8f6cb16fd68c2f176a510dab1836e2f93a'
4
- data.tar.gz: ff5d41621be25bb672f4167804b5e443924a55b87836baa8a49f603eebab0688
3
+ metadata.gz: 2a4544ea33941c52a493aab49a02f293cf6539e08db2482a858840f49e1ea1e6
4
+ data.tar.gz: fe2125582bec55b07b0e224ec196f37ed9f9c78c7f21dfd91e5e518ccb92c3d4
5
5
  SHA512:
6
- metadata.gz: 403fb9d6050a23b540868ccb1bd2c2f98f2851ff18a0549efccfe1ba78f90e7c3593937dfc4aba0f7df51195c1c3022cf70175b1d593e6a3a63baf3fba440584
7
- data.tar.gz: e75d88c1b43ed89afc25673be7a913c3f4156f6e3259584d470f0f757810c7a73e934d94a0087e56643d246830cdc130f18340a62eb24afcbb75bb10fd028a36
6
+ metadata.gz: 7971f9c3dc66d7e0389d859f8ddb6d817474c000da3314f4fd4a916fd35c4ea34bd0d0663884769e149739384785a7bd702c72df2b0e898f0e963ba9edd4425c
7
+ data.tar.gz: 7c3e6a114f9693c2d47fb9ed59e5c5d8337eeb9b1df02bd0cb1f7519128a63b9618ec5873a66264d712d009532153c4917f9f81e1207e561a0e729e31ab8e082
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (2.0.0.pre2)
4
+ retest (2.0.0.pre3)
5
5
  listen (~> 3.9)
6
6
  observer (~> 0.1)
7
7
  string-similarity (~> 2.1)
data/exe/retest CHANGED
@@ -3,13 +3,11 @@
3
3
  require 'retest'
4
4
 
5
5
  $stdout.sync = true
6
- prompt_rd, prompt_wr = IO.pipe
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
- prompt_rd.close
12
- prompt_wr.close
9
+ listen_rd.close
10
+ listen_wr.close
13
11
  exit
14
12
  end
15
13
 
@@ -25,10 +23,10 @@ if options.version?
25
23
  return
26
24
  end
27
25
 
28
- prompt = Retest::Prompt.new(input: prompt_rd)
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::Runners.runner_for(command.to_s, command_stdin: runner_rd)
29
+ runner = Retest::Runners.runner_for(command.to_s)
32
30
  sounds = Retest::Sounds.for(options)
33
31
 
34
32
  # All test runner
@@ -47,7 +45,7 @@ program = Retest::Program.new(
47
45
  )
48
46
 
49
47
  if options.params[:diff]
50
- program.run_synchronously { program.diff(options.params[:diff]) }
48
+ program.diff(options.params[:diff])
51
49
  return
52
50
  end
53
51
 
@@ -61,46 +59,21 @@ end
61
59
  $stdout.puts launching_message
62
60
  Retest.listen(options) do |modified, added, removed|
63
61
  begin
64
- program.run(modified, added, removed) do
65
- print_interactive_message
66
- end
62
+ repository.sync(added: added, removed: removed)
63
+ runner.sync(added: added, removed: removed)
64
+
65
+ listen_wr.puts "file changed: #{(modified + added).first}"
67
66
  rescue => e
68
67
  $stdout.puts "Something went wrong: #{e.message}"
69
68
  end
70
69
  end
71
70
  $stdout.puts "Ready to refactor! You can make file changes now"
72
71
 
73
- # not blocking
74
-
75
- def print_interactive_message
76
- puts "\nType interactive command and press enter"
77
- print(">\s")
78
- end
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
-
72
+ def run_command(input:, program:, all_test_runner:)
103
73
  case input
74
+ when /^file changed:\s(.*)$/
75
+ puts "File changed: #{$1}"
76
+ program.run($1)
104
77
  when 'p', 'pause'
105
78
  program.pause
106
79
  puts "Program is paused\n"
@@ -111,12 +84,12 @@ loop do
111
84
  Process.kill("INT", 0)
112
85
  when ''
113
86
  puts "Running last command\n"
114
- program.run_synchronously { runner.run(nil, repository: repository) }
87
+ program.run(nil, force_run: true)
115
88
  when 'ra', 'run all'
116
89
  puts "Running all tests\n"
117
90
  all_test_runner.run
118
91
  when /^di?f?f?\s(.*)$/
119
- program.run_synchronously { program.diff($1) }
92
+ program.diff($1)
120
93
  when 'h', 'help'
121
94
  puts <<~HELP
122
95
 
@@ -132,3 +105,16 @@ loop do
132
105
  puts "Unknown interactive command #{input}\n"
133
106
  end
134
107
  end
108
+
109
+ connections = [$stdin, listen_rd]
110
+ loop do
111
+ puts "\nType interactive command and press enter"
112
+ print(">\s")
113
+
114
+ ready = IO.select(connections)
115
+ readable_connections = ready[0]
116
+ readable_connections.each do |conn|
117
+ data = conn.readpartial(4096)
118
+ run_command(input: data.to_s.chomp, program: program, all_test_runner: all_test_runner)
119
+ end
120
+ end
@@ -14,4 +14,8 @@ module Pausable
14
14
  def resume
15
15
  @paused = false
16
16
  end
17
+
18
+ def running_state
19
+ @paused
20
+ end
17
21
  end
@@ -4,56 +4,37 @@ module Retest
4
4
  class Program
5
5
  include Pausable
6
6
 
7
- attr_accessor :runner, :repository, :command
8
- def initialize(runner: nil, repository: nil, command: nil, clear_window: true)
7
+ attr_accessor :runner, :repository, :command, :stdout
8
+ def initialize(runner: nil, repository: nil, command: nil, clear_window: true, stdout: $stdout)
9
9
  @runner = runner
10
10
  @repository = repository
11
11
  @command = command
12
12
  @clear_window = clear_window
13
+ @stdout = stdout
13
14
  initialize_pause(false)
14
15
  end
15
16
 
16
- def run(modified, added, removed)
17
- repository.sync(added: added, removed: removed)
18
- runner.sync(added: added, removed: removed)
19
-
20
- return if paused?
17
+ def run(file, force_run: false)
18
+ if paused? && !force_run
19
+ @stdout.puts "Main program paused. Please resume program first."
20
+ return
21
+ end
21
22
 
22
23
  clear_terminal
23
- runner.run (modified + added).first, repository: repository
24
- yield if block_given?
24
+ runner.run file, repository: repository
25
25
  end
26
26
 
27
27
  def diff(branch)
28
28
  raise "Git not installed" unless VersionControl::Git.installed?
29
29
  test_files = repository.find_tests VersionControl::Git.diff_files(branch)
30
30
 
31
- puts "Tests found:"
32
- test_files.each { |test_file| puts " - #{test_file}" }
31
+ @stdout.puts "Tests found:"
32
+ test_files.each { |test_file| @stdout.puts " - #{test_file}" }
33
33
 
34
- puts "Running tests..."
34
+ @stdout.puts "Running tests..."
35
35
  runner.run_all_tests command.format_batch(*test_files)
36
36
  end
37
37
 
38
- def run_synchronously(runner: @runner, prompt: @repository.prompt)
39
- raise ArgumentError, 'need a block' unless block_given?
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
53
- end
54
-
55
- private
56
-
57
38
  def clear_terminal
58
39
  return unless @clear_window
59
40
 
@@ -3,11 +3,10 @@ module Retest
3
3
  class Runner
4
4
  include Observable
5
5
 
6
- attr_accessor :command, :stdout, :command_stdin
7
- def initialize(command, stdout: $stdout, command_stdin: $stdin)
6
+ attr_accessor :command, :stdout
7
+ def initialize(command, stdout: $stdout)
8
8
  @stdout = stdout
9
9
  @command = command
10
- @command_stdin = command_stdin
11
10
  end
12
11
 
13
12
  def ==(obj)
@@ -33,7 +32,7 @@ module Retest
33
32
 
34
33
  def system_run(command)
35
34
  @running = true
36
- result = system(command, in: @command_stdin) ? :tests_pass : :tests_fail
35
+ result = system(command) ? :tests_pass : :tests_fail
37
36
  changed
38
37
  notify_observers(result)
39
38
  @running = false
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "2.0.0.pre2"
2
+ VERSION = "2.0.0.pre3"
3
3
  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.pre2
4
+ version: 2.0.0.pre3
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-10-20 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity