Class: ASAutotest::CompilationRunner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/asautotest/compilation-runner.rb

Defined Under Namespace

Classes: CompilationFailure

Constant Summary

Constants included from Logging

Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#barf, #end_saying, #end_whisper, #hint, #new_logging_section, #say, #say_with_block, #say_without_block, #shout, #start_saying, #start_whisper, verbose=, verbose?, #verbose?, #whisper, #whisper_with_block, #whisper_without_block

Constructor Details

#initialize(shell, options) ⇒ CompilationRunner

Returns a new instance of CompilationRunner.



30
31
32
33
34
# File 'lib/asautotest/compilation-runner.rb', line 30

def initialize(shell, options)
  @shell = shell
  @typing = options[:typing]
  @result = CompilationResult.new
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



28
29
30
# File 'lib/asautotest/compilation-runner.rb', line 28

def result
  @result
end

Instance Method Details

#compilation_timeObject



114
115
116
# File 'lib/asautotest/compilation-runner.rb', line 114

def compilation_time
  "~#{@stopwatch.to_s(1)} seconds"
end

#compileObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/asautotest/compilation-runner.rb', line 50

def compile
  say("Compiling") do |status|
    @shell.run_compilations(@result)

    if @result.failed?
      status << "failed"
    elsif @result.did_anything?
      files = if @result.bootstrap?
                "everything"
              else
                n_x(@result.n_recompiled_files, "file")
              end
      status << "recompiled #{files} in #{compilation_time}"
    else
      status << "nothing changed"
    end

    if @result.successful?
      for summary in @result.summaries
        title = File.basename(summary[:request].source_file_name)
        if summary[:successful?] and summary[:n_recompiled_files] != 0
          files = if summary[:n_recompiled_files]
                    n_x(summary[:n_recompiled_files], "file")
                  else
                    "everything"
                  end
          time = "#{summary[:compilation_time].to_s(1)}s"
          growl_success title, "Compiled #{files} in #{time}."
        end
      end
    else
      summary = @result.summaries.find { |x| not x[:successful?] }
      file_name = summary[:first_problem].file.basename
      line_number = summary[:first_problem].line_number
      message = summary[:first_problem].plain_message
      growl_error "#{file_name}, line #{line_number}", message
    end
  end
end

#growl_error(title, message) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/asautotest/compilation-runner.rb', line 105

def growl_error(title, message)
  if ASAutotest::growl_enabled
    Growl.notify_error message,
      :title => title, :sticky => true,
      :identifier => GROWL_ERROR_TOKEN
    ASAutotest::displaying_growl_error = true
  end
end

#growl_success(title, message) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/asautotest/compilation-runner.rb', line 94

def growl_success(title, message)
  if ASAutotest::growl_enabled
    options = { :title => title, :icon => "as" }
    if ASAutotest::displaying_growl_error
      options[:identifier] = GROWL_ERROR_TOKEN
      ASAutotest::displaying_growl_error = false
    end
    Growl.notify(message, options)
  end
end

#n_x(n, x) ⇒ Object



90
91
92
# File 'lib/asautotest/compilation-runner.rb', line 90

def n_x(n, x)
  "#{n} #{x}#{n == 1 ? "" : "s"}"
end


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/asautotest/compilation-runner.rb', line 118

def print_report
  for line in @result.unrecognized_lines
    barf line
  end

  for name, file in @result.problematic_files
    file.print_report
  end

  puts unless @result.problematic_files.empty?

  if @typing == nil and @result.any_type_warnings?
    hint "Use --dynamic-typing to disable type declaration warnings,"
    hint "or --static-typing to disable this hint."
  end
end

#runObject



36
37
38
39
40
41
42
# File 'lib/asautotest/compilation-runner.rb', line 36

def run
  @stopwatch = Stopwatch.new
  whisper_commands
  compile
  @stopwatch.stop
  print_report
end

#whisper_commandsObject



44
45
46
47
48
# File 'lib/asautotest/compilation-runner.rb', line 44

def whisper_commands
  for command in @shell.compilation_commands
    whisper "$ #{command}"
  end
end