Class: AutotestGit

Inherits:
Autotest
  • Object
show all
Defined in:
lib/autotest-git.rb

Instance Method Summary collapse

Instance Method Details

#git_update?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/autotest-git.rb', line 8

def git_update?
  git = Git.open(".")
  sha = git.object("HEAD").sha
  return false if sha == @sha
  @sha = sha
  true
end

#run_testsObject



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
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/autotest-git.rb', line 16

def run_tests
  hook :run_command
  new_mtime = self.find_files_to_test
  return unless new_mtime
  self.last_mtime = new_mtime

  cmd = self.make_test_cmd self.files_to_test
  return if cmd.empty?

  # check if commited
  return unless git_update? 

  puts cmd unless options[:quiet]

  old_sync = $stdout.sync
  $stdout.sync = true
  self.results = []
  line = []
  begin
    open "| #{cmd}", "r" do |f|
      until f.eof? do
        c = f.getc or break
        if RUBY19 then
          print c
        else
          putc c
        end
        line << c
        if c == ?\n then
          self.results << if RUBY19 then
                            line.join
                          else
                            line.pack "c*"
                          end
          line.clear
        end
      end
    end
  ensure
    $stdout.sync = old_sync
  end
  hook :ran_command
  self.results = self.results.join

  handle_results self.results
end