~tim/scheme-vm

ref: fd1db0d52ebb2cec81ffa704a927dd715f8dad97 scheme-vm/.watchr -rw-r--r-- 1.4 KiB View raw
fd1db0d5Tim Morgan Focus lib specs also 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def run_tests(files, scm_file = nil)
  if (ft = focused_tests).any?
    puts "Running focused test(s)..."
    files = ft.join(' ')
  end
  if scm_file
    puts scm_file
    env = { 'SCM_FILE' => scm_file }
  else
    puts files
    env = {}
  end
  cmd = IO.popen(env, "rspec --color --tty #{files} 2>&1")
  print cmd.getc until cmd.eof?
end

def compile
  puts
  puts '========================================='
  puts
  cmd = IO.popen('cargo build')
  print cmd.getc until cmd.eof?
end

def focused_tests
  return ['spec/lib_spec.rb'] if focused_lib_spec.any?
  Dir['spec/**/*_spec.rb'].to_a.select do |path|
    !path.end_with?('lib_spec.rb') && \
      File.read(path).match(/focus:|fdescribe|fcontext|fit ['"]/) rescue nil
  end
end

def focused_lib_spec
  Dir['spec/lib/*.scm'].to_a.select do |path|
    File.read(path).match(/;; focus/)
  end
end

watch('^spec/.*_spec\.rb')  { |m| run_tests(m.to_s) }
watch('^spec/.*-spec\.scm') { |m| run_tests('spec/lib_spec.rb', m.to_s) }
watch('^lib')               { |m| run_tests('spec/lib_spec.rb') }
watch('^vm.*')              { |m| run_tests('spec/vm_spec.rb spec/vm/*') }
watch('^compiler.*')        { |m| run_tests('spec/compiler_spec.rb spec/compiler/*') }
watch('^program.*')         { |m| run_tests('spec/program_spec.rb') }
watch('^parser.*')          { |m| run_tests('spec/parser_spec.rb') }
watch('^src/.*')            { compile }

Signal.trap('QUIT') { run_tests('spec') } # Ctrl-\