#!/usr/bin/env ruby ## $Id: run_tests.rb 2267 2008-03-27 14:52:14Z vlad $ ## ## Console Tool for run unit-tests through http:// ## ## USAGE: edit SITE_URL constant and run ## ## Autor: Vladislav Sumskyi ## Company: Totem ## Date: 27.03.2008 require 'open-uri' require 'pp' SITE_URL = 'http://localhost/dashboard/htdocs/unit_test' def get_content(url) open(url).read end class String @@colors = { "off" => 0, "bright" => 1, "underline" => 4, "blink" => 5, "exchange" => 7, "hidetext" => 8, "blacktext" => 30, "redtext" => 31, "greentext" => 32, "yellowtext" => 33, "bluetext" => 34, "magentatext" => 35, "cyantext" => 36, "whitetext" => 37, "defaulttext" => 39, "blackbg" => 40, "redbg" => 41, "greenbg" => 42, "yellowbg" => 43, "bluebg" => 44, "magentabg" => 45, "cyanbg" => 46, "whitebg" => 47, "defaultbg" => 49 } # colorize strings def colorize(color) color_code = if @@colors[color].nil? @@colors["off"] else @@colors[color] end "\e[#{color_code}m#{self}\e[0m" end end if $0 == __FILE__ # content = '' + get_content(SITE_URL) + '' content = get_content(SITE_URL) tables = content.scan(/(.*)<\/table>/m) table = tables[0][0].gsub(/\t|\n/, "") table.gsub!(" ", " ") table.gsub!("'", "'") table.gsub!(">", ">") tests = table.split("
") #puts ("=" * 80) puts "[Test Classes]: #{tests.size}\n".colorize("cyantext") tests_total = 0 tests_passed = 0 tests_failed = 0 tests_error = 0 tests.each do |t| test_class = t.scan(/(.*?)<\/th>/).to_s puts "#{test_class}: ".colorize("yellowtext") curr_test_stats = t.scan(/(.*)<\/th>/).to_s.split(",") curr_test_count = 0 curr_failed = 0 curr_error = 0 curr_test_stats.each do |ct| curr_i = ct.to_s[-1].chr.to_i curr_test_count += curr_i case ct when /Passed:/i tests_passed += curr_i when /Failed:/i tests_failed += curr_i curr_failed += curr_i when /Errors:/i tests_error += curr_i curr_error += curr_i end end methods = t.scan(/(.*?)<\/td>/i) methods_status = t.scan(/(.*?)<\/td>/i) methods.each_index do |i| case methods_status[i][0] when "passed" puts "[#{methods[i]}]: passed".colorize("greentext") when "failed", "error" err = methods_status[i][1].gsub(/(.*?)<\/strong>/, "") err.gsub!(/(|<\/pre>)/, "") puts "[#{methods[i]}]: #{methods_status[i][0]} #{err}".colorize("redtext") end end # prints "Passed: 3 Failed: 2 Errors: 0" curr_test_stats_str = curr_test_stats.join(" ") if (curr_error > 0 or curr_failed > 0): puts curr_test_stats_str.colorize("redtext") else puts curr_test_stats_str.colorize("yellowtext") end tests_total += curr_test_count #puts "=" * 80 puts end puts "[Tests Methods Total]: #{tests_total}".colorize("cyantext") puts puts "[Tests Methods Passed]: #{tests_passed}".colorize("greentext") if tests_failed == 0 puts "[Tests Methods Failed]: #{tests_failed}".colorize("greentext") else puts "[Tests Methods Failed]: #{tests_failed}".colorize("redtext") end if tests_error == 0 puts "[Tests Methods Error]: #{tests_error}".colorize("greentext") else puts "[Tests Methods Error]: #{tests_error}".colorize("redtext") end puts end