Class: DevSystem::TestCommand

Inherits:
Command show all
Defined in:
lib/dev_system/commands/test_command.rb

Class Method Summary collapse

Methods inherited from Command

#call, get_command_signatures

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Class Method Details

._call_counting(test_classes) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dev_system/commands/test_command.rb', line 69

def self._call_counting test_classes
  puts
  Liza.log ""
  Liza.log stick :b, " TEST TOTALS ".center(140, "-")
  Liza.log ""
  puts
  totals = Hash.new { 0 }
  last_namespace = nil
  test_classes.each do |test_class|
    namespace = test_class.first_namespace
    puts if last_namespace != namespace
    last_namespace = namespace

    test_class.totals.each do |k, v|
      totals[k] += v.size
    end
    size = 60 - test_class.subject_class.to_s.size
    Liza.log "#{_color_unit test_class.subject_class}#{".totals".ljust size} #{test_class.totals.map { |k, v| [k, v.size] }.to_h}"
  end
  puts
  Liza.log "#{"Total".ljust 60} #{totals}"
  puts
end

._call_silence_base_unitsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/dev_system/commands/test_command.rb', line 32

def self._call_silence_base_units
  [
    Liza::Box,
    Liza::Panel,
    Liza::Controller,
  ].each do |x|
    def x.log(...) end
    def x.puts(...) end
  end
end

._call_sort(test_classes) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dev_system/commands/test_command.rb', line 43

def self._call_sort test_classes
  test_classes.sort_by! &:name

  proc_namespaced = proc { |tc| tc.name.include? "::" }
  proc_liza = proc { |tc| tc.name[0..3] == "Liza" }

  tc_app        = test_classes.reject(&proc_namespaced)
  tc_namespaced = test_classes.select(&proc_namespaced)

  tc_liza   = tc_namespaced.select(&proc_liza)
  tc_system = tc_namespaced.reject(&proc_liza)

  tc_app.sort_by! &:source_location
  tc_liza.sort_by! &:source_location

  [tc_liza, tc_system, tc_app].flatten
end

._call_testing(test_classes) ⇒ Object



61
62
63
64
65
66
# File 'lib/dev_system/commands/test_command.rb', line 61

def self._call_testing test_classes
  i, count = 0, test_classes.count
  for test_class in test_classes
    test_class.call i+=1, count
  end
end

._color_unit(klass) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/dev_system/commands/test_command.rb', line 93

def self._color_unit klass
  return klass.to_s unless klass < Liza::Unit
  return klass.to_s if klass.superclass == Liza::Unit

  ret = ""
  namespace, _sep, classname = klass.name.rpartition('::')
  unless namespace.empty?
    system_color = klass.system.color
    ret << stick(namespace, system_color, :b).to_s
    ret << "::"
  end

  klass = klass.division if klass.is_a? Liza::Controller
  unit_color = nil
  unit_color = klass.system.color

  ret << stick(classname, unit_color).to_s
  ret
end

.call(args) ⇒ Object



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
# File 'lib/dev_system/commands/test_command.rb', line 3

def self.call args
  log "args = #{args.inspect}"

  now = Time.now
  test_classes = Liza::Test.descendants

  if args.any?
    test_classes = test_classes.select { |tc| args.any? { tc.source_location_radical.snakecase.include? _1.snakecase } }
  end

  _call_silence_base_units
  
  if Lizarb::IS_APP_DIR
    test_classes = test_classes.select { |tc| tc.source_location[0].include? Lizarb::APP_DIR }
  end

  test_classes = _call_sort test_classes

  log "Testing #{test_classes}"
  _call_testing test_classes
  log "Done Testing (#{now.diff}s)"

  puts

  log "Counting #{test_classes.count} Test Classes"
  _call_counting test_classes
  log "Done Counting (#{now.diff}s)"
end