Class: Tryouts::CLI::Run

Inherits:
Drydock::Command
  • Object
show all
Defined in:
lib/tryouts/cli/run.rb,
lib/tryouts/cli/run.rb

Overview

Run

The logic bin/tryouts uses for running tryouts.

Constant Summary collapse

DEV =
%q{
        ^^             @@@@@@@@@
   ^^       ^^      @@@@@@@@@@@@@@@
                  @@@@@@@@@@@@@@@@@@              ^^
                 @@@@@@@@@@@@@@@@@@@@
 ~~~ ~~~~~~~~ ~~ &&&&&&&&&&&&&&&&&&&& ~~~~~~~ ~~~~~~~~~~~ ~~
 ~~   ~  ~       ~~~~~~~~~~~~~~~~~~~~ ~       ~~     ~~ ~
 ~      ~~ ~~ ~~  ~~~~~~~~~~~~~ ~~~~  ~     ~~~    ~ ~~~  ~
   ~         ~      ~~~~~~  ~~ ~~~       ~~ ~ ~~  ~~ ~
  ~ ~      ~           ~~ ~~~~~~  ~      ~~  ~           ~~~
           ~        ~      ~      ~~   ~             ~
}
BUG =
%q{
     ,--.____                                     ____.--.
    /  .'.'"``--...----------.___.----------...--''"`.`.  \
    | .'.'         .                       .         `.`. |
    `. .'|     . ' - . _    `-----'    _ . - ' .     |`. .'
     `.' `|   .'   _     "-._     _.-"     _   `.   |' `.'
          |  |        " -.           .- "        |  |
           \|        ;;..  "|i. .i|"  ..;;        |/
           `|      ,---.``.   ' '   .'',---.      |'        
            |    <'(__.'>.'---` '---`.<`.__)`>    | 
            |   `. `~  .'  ,-------.  `.  ~'.'    |
            |  |=_"`=.'  . `-.___.-' .  `.='"_=|  |
            |  |  ==/  : ` :   i   : ' :  \==  |  |
            |  | ==/      /\___|___/\      \== |  |
             `.| =Y      .' """_""" `.      Y= |.'
               L ||      ;  .=="==.  ;      || J 
                \ ;     .' '       ` `.     ; /
                 `.     ;             ;     .'
                  ;    ;'\           /`;    ;
                  `;  .'.'/.       ,\`.`.  ;' 
                   `-=;_-'  `-----'  `-_;=-'        -bodom-
}
PUG =
%q{
              __,-----._                       ,-. 
            ,'   ,-.    \`---.          ,-----<._/ 
           (,.-. o:.`    )),"\\\-._    ,'         `. 
          ('"-` .\       \`:_ )\  `-;'-._          \ 
         ,,-.    \` ;  :  \( `-'     ) -._     :   `: 
        (    \ `._\\\ ` ;             ;    `    :    ) 
         \`.  `-.    __   ,         /  \        ;, ( 
          `.`-.___--'  `-          /    ;     | :   | 
            `-' `-.`--._          '           ;     | 
                  (`--._`.                ;   /\    | 
                   \     '                \  ,  )   : 
                   |  `--::----            \'   ;  ;| 
                   \    .__,-      (        )   :  :| 
                    \    : `------; \      |    |   ; 
                     \   :       / , )     |    |  ( 
                      \   \      `-^-|     |   / , ,\ 
                       )  )          | -^- ;   `-^-^' 
                    _,' _ ;          |    | 
                   / , , ,'         /---. : 
                   `-^-^'          (  :  :,'    
                                    `-^--'          -hrr- 
}

Instance Method Summary collapse

Instance Method Details

#dreamsObject

$ sergeant dreams [path/2/tryouts] Display the dreams from all known tryouts



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tryouts/cli/run.rb', line 15

def dreams
  load_available_tryouts_files
  if Tryouts.verbose > 0
    puts Tryouts.dreams.to_yaml
  else
    Tryouts.dreams.each_pair do |n,dreams|
      puts n
      dreams.each_pair do |n, dream|
        puts "  " << n
        dream.each_pair do |n, drill|
          puts "    " << n
        end
      end
    end
  end
end

#initObject



9
10
11
# File 'lib/tryouts/cli/run.rb', line 9

def init
  @tryouts_globs = [GYMNASIUM_GLOB, File.join(Dir.pwd, '*_tryouts.rb')]
end

#listObject

$ sergeant list Displays all known tryouts from the current working directory



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/tryouts/cli/run.rb', line 128

def list
  load_available_tryouts_files
  Tryouts.instances.each_pair do |n,tryouts_inst|
    puts n
    if Tryouts.verbose > 0
      puts "  #{tryouts_inst.paths.join("\n  ")}"
    end
    tryouts_inst.tryouts.each_pair do |t2,tryout|
      puts "  " << tryout.name
      tryout.drills.each do |drill|
        puts "    " << drill.name
      end
    end
  end
end

#runObject

$ sergeant run [path/2/tryouts] Executes all tryouts that can be found from the current working directory.



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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/tryouts/cli/run.rb', line 34

def run
  start = Time.now
  
  Tryouts.enable_debug if Drydock.debug?
  Tryouts.verbose = @global.quiet ? -1 : @global.verbose

  if Tryouts.verbose > 0
    print "Tryouts #{Tryouts::VERSION} -- "
    print "#{Tryouts.sysinfo.to_s}@#{RUBY_VERSION} -- "
    puts "#{start.strftime("%Y-%m-%d %H:%M:%S")}"
    puts
  end
  
  load_available_tryouts_files
  
  passed, failed = 0, 0
  Tryouts.instances.each_pair do |group,tryouts_inst|
    puts unless group == Tryouts.instances.keys.first
    puts ' %-79s'.att(:reverse) % group  unless Tryouts.verbose < 0
    puts "  #{tryouts_inst.paths.join("\n  ")}" if Tryouts.verbose > 0
    tryouts_inst.tryouts.each_pair do |name,to|
      begin
        to.run
        to.report
      rescue SyntaxError, LoadError, Exception, TypeError,
             RuntimeError, NoMethodError, NameError => ex
        tryouts_inst.errors << ex
      end
      STDOUT.flush
      passed += to.passed
      failed += to.failed
    end

    unless tryouts_inst.errors.empty?
      title = '%-78s' % " RUNTIME ERRORS !?"
      puts $/, ' ' << title.color(:red).att(:reverse).bright
      tryouts_inst.errors.each do |ex|
        
        puts '%4s%s: %s' % ['', ex.class, ex.message.to_s.split($/).join($/ + ' '*16)]
        puts
        
        if [SyntaxError].member? ex.class
          # don't print anymore. 
        else
          unless ex.backtrace.nil?
            trace = Tryouts.verbose > 1 ? ex.backtrace : [ex.backtrace.first]
            puts '%14s  %s' % ["", trace.join($/ + ' '*16)]
            puts 
          end
        end
      end
    end
  end
  
  if Tryouts.verbose < 0
    if (passed == 0 && failed == 0)
      exit -1
    elsif failed == 0 && !Tryouts.failed?
      puts "PASS"
      exit 0
    else
      puts "FAIL"
      exit 1
    end
  else
    if Tryouts.verbose > 0
      elapsed = Time.now - start
      puts $/, "  Elapsed: %.3f seconds" % elapsed.to_f #if elapsed > 0.01
    end
    if (passed == 0 && failed == 0)
      puts DEV if Tryouts.verbose > 4
      msg = " You didn't even try to acheive your dreams :[ "
      puts $/, msg.att(:reverse)
      exit -1
    elsif failed == 0 && !Tryouts.failed?
      puts PUG if Tryouts.verbose > 4
      msg = passed > 1 ? "All %s dreams" : "Your only dream"
      msg = (" #{msg} came true " % [passed+failed]).color(:green)
      puts $/, msg.att(:reverse)
      exit 0
    else
      puts BUG if Tryouts.verbose > 4
      score = (passed.to_f / (passed.to_f+failed.to_f)) * 100
      msg = " %s of %s dreams came true (%d%%) ".color(:red)
      msg = msg % [passed, passed+failed, score.to_i]
      puts $/, msg.att(:reverse)
      exit 1
    end
    
  end
end