Class: ParseTreeGauntlet

Inherits:
Gauntlet
  • Object
show all
Defined in:
lib/gauntlet_parsetree.rb

Instance Method Summary collapse

Constructor Details

#initializeParseTreeGauntlet

Returns a new instance of ParseTreeGauntlet.



15
16
17
18
19
20
21
# File 'lib/gauntlet_parsetree.rb', line 15

def initialize
  super

  self.data = Hash.new { |h,k| h[k] = {} }
  old_data = load_yaml data_file
  self.data.merge! old_data
end

Instance Method Details

#broke(name, file, msg) ⇒ Object



52
53
54
55
56
# File 'lib/gauntlet_parsetree.rb', line 52

def broke name, file, msg
  warn "bad"
  self.data[name][file] = msg
  self.dirty = true
end

#diff_pp(o1, o2) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gauntlet_parsetree.rb', line 35

def diff_pp o1, o2
  require 'pp'

  File.open("/tmp/a.#{$$}", "w") do |f|
    PP.pp o1, f
  end

  File.open("/tmp/b.#{$$}", "w") do |f|
    PP.pp o2, f
  end

  `diff -u /tmp/a.#{$$} /tmp/b.#{$$}`
ensure
  File.unlink "/tmp/a.#{$$}" rescue nil
  File.unlink "/tmp/b.#{$$}" rescue nil
end

#process(path, name) ⇒ Object



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
89
90
91
92
93
94
95
96
97
# File 'lib/gauntlet_parsetree.rb', line 58

def process path, name
  begin
    $stderr.print "  #{path}: "
    rp = RubyParser.new
    pt = ParseTree.new

    old_ruby = File.read(path)

    begin
      pt_sexp = pt.process old_ruby
    rescue SyntaxError => e
      warn "unparsable pt"
      self.data[name][path] = :unparsable_pt
      self.dirty = true
      return
    end

    begin
      rp_sexp = rp.process old_ruby
    rescue Racc::ParseError => e
      broke name, path, e.message
      return
    end

    if rp_sexp != pt_sexp then
      broke name, path, diff_pp(rp_sexp, pt_sexp)
      return
    end

    self.data[name][path] = true
    self.dirty = true

    warn "good"
  rescue Interrupt
    puts "User cancelled"
    exit 1
  rescue Exception => e
    broke name, path, "    UNKNOWN ERROR: #{e}: #{e.message.strip}"
  end
end

#run(name) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gauntlet_parsetree.rb', line 99

def run name
  warn name
  Dir["**/*.rb"].sort.each do |path|
    next if path =~ /gemspec.rb/ # HACK
    result = data[name][path]
    next if result == true || Symbol === result
    process path, name
  end

  if (self.data[name].empty? or
      self.data[name].values.all? { |v| v == true }) then
    warn "  ALL GOOD!"
    self.data[name] = true
    self.dirty = true
  end
end

#should_skip?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gauntlet_parsetree.rb', line 23

def should_skip? name
  if $f then
    if Hash === data[name] then
      ! data[name].empty?
    else
      data[name]
    end
  else
    data[name] == true # yes, == true on purpose
  end
end