paolodona / scripts
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
Paolo Dona (author)
Fri Aug 01 01:49:10 -0700 2008
scripts / colorize
| 4a0ca57f » | Paolo Dona | 2008-07-04 | 1 | #!/usr/bin/env ruby | |
| 2 | # colorize the output of rspec stories | ||||
| 3 | # eg: stakeout "stories/all.rb | ./colorize.rb" stories/* stories/**/* | ||||
| 555b02da » | Paolo Dona | 2008-07-07 | 4 | ||
| 4a0ca57f » | Paolo Dona | 2008-07-04 | 5 | module Color | |
| 6 | COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } | ||||
| 7 | def self.method_missing(color_name, *args) | ||||
| 8 | color(color_name) + args.first + color(:clear) | ||||
| 9 | end | ||||
| 10 | def self.color(color) | ||||
| 11 | "\e[#{COLORS[color.to_sym]}m" | ||||
| 12 | end | ||||
| 13 | end | ||||
| 14 | |||||
| 555b02da » | Paolo Dona | 2008-07-07 | 15 | # Growl stuff --------- | |
| 16 | AUTOTEST_IMAGE_ROOT = "~/.autotest_images" | ||||
| 0c6d3d2e » | Paolo Dona | 2008-07-07 | 17 | USE_GROWL = system 'which growlnotify' | |
| 555b02da » | Paolo Dona | 2008-07-07 | 18 | def self.growl(title, msg, img, pri=0, sticky="") | |
| 19 | system "growlnotify -n autotest --image #{img} -p #{pri} -m '#{title}: #{msg.strip}' #{sticky}" if USE_GROWL | ||||
| 20 | true | ||||
| 21 | end | ||||
| 22 | def growl_success(msg); growl("PASS", msg, "#{AUTOTEST_IMAGE_ROOT}/pass.png", 2); end | ||||
| 23 | def growl_fail(msg); growl("FAIL", msg, "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2); end | ||||
| 24 | def growl_pending(msg); growl("PENDING", msg, "#{AUTOTEST_IMAGE_ROOT}/pending.png", 2); end | ||||
| 0a198563 » | Paolo Dona | 2008-07-07 | 25 | ||
| 555b02da » | Paolo Dona | 2008-07-07 | 26 | # Summary ------------- | |
| 27 | # 14 scenarios: 13 succeeded, 0 failed, 1 pending | ||||
| 28 | RESULTS_LINE = /(\d+)\s+scenarios:\s*(\d+)\s+succeeded?,\s*(\d+)\s+failed?(,\s*(\d+)\s+pending)?.*/ | ||||
| 29 | # colorize the summary | ||||
| 0a198563 » | Paolo Dona | 2008-07-07 | 30 | def colorize_summary(summary) | |
| 31 | output = summary.slice(RESULTS_LINE) | ||||
| 32 | succeeded, failed, pending = $~[2].to_i, $~[3].to_i, $~[5].to_i | ||||
| 555b02da » | Paolo Dona | 2008-07-07 | 33 | growl_fail(summary) and return Color.red(summary) if failed > 0 | |
| 34 | growl_pending(summary) and return Color.yellow(summary) if pending > 0 | ||||
| 35 | growl_success(summary) and return Color.green(summary) | ||||
| 0a198563 » | Paolo Dona | 2008-07-07 | 36 | end | |
| 37 | |||||
| 4a0ca57f » | Paolo Dona | 2008-07-04 | 38 | STDIN.each_line do |line| | |
| 39 | colored_line = case line | ||||
| 40 | when /FAILED/ then Color.red(line) | ||||
| 41 | when /PENDING/ then Color.yellow(line) | ||||
| 0a198563 » | Paolo Dona | 2008-07-07 | 42 | when RESULTS_LINE then colorize_summary(line) | |
| 4a0ca57f » | Paolo Dona | 2008-07-04 | 43 | else line | |
| 44 | end | ||||
| 45 | puts colored_line | ||||
| 0c6d3d2e » | Paolo Dona | 2008-07-07 | 46 | end | |
