tasks/test.rake in webroar-0.3.1 vs tasks/test.rake in webroar-0.4.0
- old
+ new
@@ -22,15 +22,15 @@
require 'spec/rake/spectask'
#TODO: forget underscore and cover tests under namespace
WEBROAR_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
SPEC_DIR = File.join(WEBROAR_ROOT,'test','spec')
-REPORT_DIR = File.join(WEBROAR_ROOT,'report')
TEST_DIR = File.join(WEBROAR_ROOT, 'test')
+
DEBUG_LOG_DIR = File.join(TEST_DIR,'debug_log')
ALL_SPECS = FileList[File.join(SPEC_DIR,'*_spec.rb')].exclude("conditional_spec.rb")
-#ALL_SPECS = FileList[File.join(SPEC_DIR,'access_log_spec.rb')]
+#ALL_SPECS = FileList[File.join(SPEC_DIR,'http_spec.rb')]
#ALL_SPECS = FileList[File.join(SPEC_DIR,'*_spec.rb')].exclude(
#File.join(SPEC_DIR,'host_name_spec.rb'),
#File.join(SPEC_DIR,'connection_keep_alive_spec.rb'),
#File.join(SPEC_DIR,'webroar_command_spec.rb'),
#File.join(SPEC_DIR,'content_encoding_spec.rb'),
@@ -42,96 +42,148 @@
#File.join(SPEC_DIR, 'analytics_spec.rb')
#)
require File.join(SPEC_DIR,'spec_helper.rb')
test_flag = 1
+total = 0
+failed = 0
+file = nil
+desc "Log exceptions."
+task :log_exception, :exception do |t, args|
+ exception_log = File.join(REPORT_DIR,'exception.log')
+
+ File.open(exception_log,"a") do |f|
+ f.puts args.exception
+ f.puts args.exception.backtrace
+ end
+end
+
+desc "Creates required folders for running test cases."
+task :create_test_dirs do
+ begin
+ if(ENV["report_dir"])
+ REPORT_DIR = ENV["report_dir"]
+ else
+ REPORT_DIR = File.join(WEBROAR_ROOT,'report')
+ end
+
+ # make exception.log empty.
+ exception_log = File.join(REPORT_DIR,'exception.log')
+ File.truncate(exception_log,0) if File.exists?(exception_log)
+
+ UNIT_TEST_REPORT = File.join(REPORT_DIR, 'unit_test')
+ SPEC_TEST_REPORT = File.join(REPORT_DIR, 'spec')
+ ADMIN_TEST_REPORT = File.join(REPORT_DIR, 'admin_panel')
+ LOAD_TEST_REPORT = File.join(REPORT_DIR, 'load_test')
+ BUILD_TEST_REPORT = File.join(REPORT_DIR, 'build_test')
+
+ # Create directories.
+ if create_directories([UNIT_TEST_REPORT, SPEC_TEST_REPORT, ADMIN_TEST_REPORT, BUILD_TEST_REPORT, LOAD_TEST_REPORT, LOG_FILES]) == true
+ puts 'Required directories created successfully.'
+ else
+ puts 'Required directories could not be created. Can not continue...'
+ end
+ rescue Exception => e
+ puts e
+ puts e.backtrace
+ end
+
+end
+
+def check_and_copy(src_file, dest_file)
+ FileUtils.copy(src_file, dest_file) if File.exists?(src_file)
+end
+
desc "Build .so file for all the test written in c"
-task :build_tests do
+task :build_unit_test do
create_directories([TEST_OBJ_DIR])
test_files = FileList[File.join(UNIT_TEST_DIR, '*.c'), File.join(HELPER_DIR, '*.c'),
File.join(YAML_DIR, '*.c')]
test_obj = {}
test_files.each do |sfn|
obj = sfn.sub(/\.[^.]*$/, '.o')
obj_file = File.join(TEST_OBJ_DIR , obj[obj.rindex(File::SEPARATOR)+1..obj.length])
test_obj[obj_file]=sfn
end
- unless $webroar_config_called
- webroar_config
- end
-
+ webroar_config unless $webroar_config_called
+
test_obj.each { |obj_file,src_file|
- cmd = "#{COMPILER} #$inc_flags #$CFLAGS #$flags #$debug_flags -c #{src_file} -o #{obj_file}"
+ cmd = "#{CC} #$flags #$debug_flags -c #{src_file} -o #{obj_file}"
sh cmd
}
-
tests_obj_files = FileList[File.join(TEST_OBJ_DIR,"*.o")]
if RUBY_PLATFORM =~ /darwin/
out_file = File.join(UNIT_TEST_DIR, 'test_ext.dylib')
- lib_flags = $libs + $LIBS
- lib_flags += " #{ENV['library_flags']}" if ENV['library_flags']
- cmd = "#{COMPILER} #$libs #{tests_obj_files} -dynamiclib -o #{out_file}"
+ cmd = "#{CC} #$lib_flags #{tests_obj_files} -dynamiclib -o #{out_file}"
else
out_file = File.join(UNIT_TEST_DIR, 'test_ext.so')
- cmd = "#{COMPILER} #$libs #{tests_obj_files} -shared -o #{out_file}"
+ cmd = "#{CC} #$lib_flags #{tests_obj_files} -shared -o #{out_file}"
end
sh cmd
end
desc "Build and executes unit test"
-task :unit_test do
- test_file = File.join(UNIT_TEST_DIR, 'test.log')
- summary_file = File.join(UNIT_TEST_DIR, 'test_summary')
- File.truncate(test_file, 0) if File.exists?(test_file)
- File.truncate(summary_file, 0) if File.exists?(summary_file)
+task :unit_test => [:create_test_dirs] do
+ next unless test_flag == 1
- print "Compiling unit test cases ... "
- system("rake build_tests >#{File.join(UNIT_TEST_DIR,'testcases.log')} 2>>#{File.join(UNIT_TEST_DIR,'testcases.log')}")
- if($?==0)
- puts "Done."
- system("rake clean >>#{File.join(UNIT_TEST_DIR,'testcases.log')} 2>>#{File.join(UNIT_TEST_DIR,'testcases.log')}")
- puts "Running test cases ..."
- puts ""
- $LOAD_PATH.unshift(UNIT_TEST_DIR)
- Dir.chdir(UNIT_TEST_DIR)
+ begin
+ test_file = File.join(UNIT_TEST_DIR, 'test.log')
+ summary_file = File.join(UNIT_TEST_REPORT, 'test-summary')
+ File.truncate(test_file, 0) if File.exists?(test_file)
- if RUBY_PLATFORM =~ /darwin/
- require 'dl'
- dl = DL::dlopen(File.join(UNIT_TEST_DIR,'test_ext.dylib'))
- run_test = dl.sym("run_test",'0')
- run_test.call()
+ print "Compiling unit test cases ... "
+ system("rake build_unit_test >#{File.join(UNIT_TEST_REPORT,'testcases.log')} 2>>#{File.join(UNIT_TEST_REPORT,'testcases.log')}")
+ if($?==0)
+ puts "Done."
+ system("rake clean >>#{File.join(UNIT_TEST_REPORT,'testcases.log')} 2>>#{File.join(UNIT_TEST_REPORT,'testcases.log')}")
+ puts "Running test cases ..."
+ puts ""
+ $LOAD_PATH.unshift(UNIT_TEST_DIR)
+ Dir.chdir(UNIT_TEST_DIR)
+
+ if RUBY_PLATFORM =~ /darwin/
+ require 'dl'
+ dl = DL::dlopen(File.join(UNIT_TEST_DIR,'test_ext.dylib'))
+ run_test = dl.sym("run_test",'0')
+ run_test.call()
+ else
+ require 'test_ext'
+ Test::Test.run
+ end
+
+ puts "\nPlease refer '#{File.join(UNIT_TEST_REPORT, 'test.log')}' for the detailed report."
else
- require 'test_ext'
- Test::Test.run
+ puts "Compilation error. Please refer 'testcases.log' for details."
end
-
- puts "\nPlease refer 'test\\unit\\test.log' for the detailed report."
- else
- puts "Compilation error. Please refer 'testcases.log' for details."
+ Dir.chdir(WEBROAR_ROOT)
+ next unless File.exists?(test_file)
+
+ result = File.read(test_file)
+
+ passed = 0
+ failed = 0
+ p_f = result.scan(/Test\s*passed\s*:\s*(\d+),\s*Test\s*failed\s*:\s*(\d+)/)
+ p_f.each do |e|
+ passed += e[0].to_i
+ failed += e[1].to_i
+ end
+ str = "Unit test summary\nTotal test: #{passed+failed}\nFailed test: #{failed}\n"
+
+ File.open(summary_file, "w") do |f|
+ f.puts str
+ end
+ rescue Exception => e
+ Rake::Task[:log_exception].invoke(e)
end
- Dir.chdir(WEBROAR_ROOT)
- return unless File.exists?(test_file)
-
- result = File.read(test_file)
-
- passed = 0
- failed = 0
- p_f = result.scan(/Test\s*passed\s*:\s*(\d+),\s*Test\s*failed\s*:\s*(\d+)/)
- p_f.each do |e|
- passed += e[0].to_i
- failed += e[1].to_i
- end
- str = "Unit test summary\nTotal test: #{passed+failed}\nFailed test: #{failed}\n"
-
- File.open(summary_file, "w") do |f|
- f.puts str
- end
+
+ check_and_copy(File.join(UNIT_TEST_DIR, 'test.log'), File.join(UNIT_TEST_REPORT, 'test.log'))
+
end
task :test_setup do
if ENV["debug_build"] == "yes"
rv = test_setup(true)
@@ -139,473 +191,362 @@
rv = test_setup()
end
if rv == -1
puts " * Some problem occured in test setup. Exiting. * "
test_flag = 0
- # return -1
exit(-1)
end
end
-desc "Executes functional test"
task :spec => :test_setup
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = ALL_SPECS
t.spec_opts << "--format specdoc"
end
+desc "Run functional test cases."
+task :spec_test => [:create_test_dirs] do
+ next unless test_flag == 1
+
+ puts "Executing functional tests ..."
+ begin
+ ENV["SPEC_OPTS"] = "--format specdoc:#{TEST_RESULT}"
+ Rake::Task[:spec].invoke()
+ rescue Exception => e
+ Rake::Task[:log_exception].invoke(e)
+ ensure
+ if File.exists?(TEST_RESULT)
+ system("tail -2 #{File.join(SPEC_DIR,'test.log')} > #{File.join(SPEC_TEST_REPORT,'test_result')}")
+ result = File.read(File.join(SPEC_TEST_REPORT,'test_result'))
+ total = 0
+ failed = 0
+ if result =~ /(\d+)\s*(example|examples),\s*(\d+)\s*failure/
+ total = $1
+ failed = $3
+ end
+ str = "Functional test summary\nTotal test: #{total}\nFailed test: #{failed}\n"
+ File.open(File.join(SPEC_TEST_REPORT,'test-summary'),"w") do |f|
+ f.puts str
+ end
+ end
+
+ log_file_pattern = File.join(LOG_FILES,'*.log')
+ log_files = Dir.glob(log_file_pattern)
+ for file in log_files
+ FileUtils.cp(file,File.join(SPEC_TEST_REPORT,"#{File.basename(file)}"))
+ end
+
+ cmd = "#{File.join(WEBROAR_ROOT,'bin','webroar')} clear"
+ system(cmd)
+ end
+
+ # copy functional tests related files
+ check_and_copy(File.join(SPEC_DIR, 'test.log'), File.join(SPEC_TEST_REPORT, 'test.log'))
+ check_and_copy(File.join(SPEC_DIR, 'setup.log'), File.join(SPEC_TEST_REPORT, 'test-setup.log'))
+ check_and_copy(File.join(SPEC_DIR, 'test-run.log'), File.join(SPEC_TEST_REPORT, 'test-run.log'))
+
+end
+
desc "Executes Admin-panel test"
-task :admin_panel_test do
- puts "Executing Admin-panel tests ..."
- Dir.chdir(File.join(WEBROAR_ROOT,'src','admin_panel'))
- system("rake test RAILS_ENV=test >test.log 2>error.log")
- result = File.read('test.log')
- p_f = result.scan(/(\d+)\s+tests,\s+\d+\s+assertions,\s+(\d+)\s+failures,\s+(\d+)\s+errors/)
- total = 0
- failed = 0
- error = 0
- p_f.each do |e|
- total += e[0].to_i
- failed += e[1].to_i
- error += e[2].to_i
+task :admin_panel_test => [:create_test_dirs] do
+ next unless test_flag == 1
+
+ begin
+ puts "Executing Admin-panel tests ..."
+ Dir.chdir(File.join(WEBROAR_ROOT,'src','admin_panel'))
+ system("rake test RAILS_ENV=test > #{File.join(ADMIN_TEST_REPORT, 'test.log')} 2>#{File.join(ADMIN_TEST_REPORT, 'error.log')}")
+ result = File.read(File.join(ADMIN_TEST_REPORT, 'test.log'))
+ p_f = result.scan(/(\d+)\s+tests,\s+\d+\s+assertions,\s+(\d+)\s+failures,\s+(\d+)\s+errors/)
+ total = 0
+ failed = 0
+ error = 0
+ p_f.each do |e|
+ total += e[0].to_i
+ failed += e[1].to_i
+ error += e[2].to_i
+ end
+ str = "Admin-panel test summary\nTotal test: #{total}\nFailed test: #{failed}\nError: #{error}\n"
+ File.open(File.join(ADMIN_TEST_REPORT, 'test-summary'),"w") do |f|
+ f.puts str
+ end
+ Dir.chdir(WEBROAR_ROOT)
+ rescue Exception => e
+ Rake::Task[:log_exception].invoke(e)
end
- str = "Admin-panel test summary\nTotal test: #{total}\nFailed test: #{failed}\nError: #{error}\n"
- File.open('test_summary',"w") do |f|
- f.puts str
- end
- Dir.chdir(WEBROAR_ROOT)
+
+ #copy database file
+ check_and_copy(File.join(WEBROAR_ROOT, 'src', 'admin_panel', 'db', 'webroar_test.sqlite3'), ADMIN_TEST_REPORT)
+
end
desc "Load testing by ab tool"
-task :load_test do
+task :load_test => [:create_test_dirs] do
+ next unless test_flag == 1
+
puts "Executing load tests ..."
begin
create_config({},{'baseuri' => '/test_app', 'max_worker' => 6})
move_config
create_messaging_config
move_messaging_config
start_server
sleep(15)
system("ruby #{File.join(TEST_DIR,'load_test.rb')}")
stop_server
+
+ log_file_pattern = File.join(LOG_FILES,'*.log')
+ log_files = Dir.glob(log_file_pattern)
+ for file in log_files
+ FileUtils.cp(file,File.join(LOAD_TEST_REPORT,"#{File.basename(file)}"))
+ end
rescue Exception => e
+ Rake::Task[:log_exception].invoke(e)
ensure
remove_config
remove_messaging_config
end
+
+
+ # copy load tests related files
+ check_and_copy(File.join(TEST_DIR, 'load_test_summary'), File.join(LOAD_TEST_REPORT, 'test-summary'))
+ check_and_copy(File.join(TEST_DIR, 'load_test_result_fix'), File.join(LOAD_TEST_REPORT, 'test-result-fix'))
+ check_and_copy(File.join(TEST_DIR, 'load_test_result_random'), File.join(LOAD_TEST_REPORT, 'test-result-random'))
+
end
-
desc "Build gem"
-task :build do
- cmd = "rm -fr pkg/* 2>> build_test.log >>build_test.log"
- system(cmd)
- t = Rake::Task[:gem]
- t.invoke()
+task :build_gem => [:create_test_dirs] do
+ total += 1
+ begin
+ file.print "Build gem ... " if file
+ cmd = "rm -fr pkg/* 2>> #{File.join(BUILD_TEST_REPORT, 'test.log')} >>#{File.join(BUILD_TEST_REPORT, 'test.log')}"
+ system(cmd)
+ Rake::Task[:gem].invoke
+ file.puts "Pass" if file
+ rescue Exception => e
+ failed += 1
+ file.puts "Failed" if file
+ Rake::Task[:log_exception].invoke(e)
+ end
end
desc "Gem install. It's meant for automated testing, passing predefined values for required inputs"
-task :build_install do
+task :build_install => [:build_gem] do
+ total += 1
gem_file = File.join(WEBROAR_ROOT,'pkg',"webroar-#{Webroar::VERSION::STRING}.gem")
- return -1 unless File.exists?(gem_file)
- print "Installing gem ... "
- cmd = "gem install #{gem_file} 2>> build_test.log >>build_test.log"
- system(cmd)
- if($?==0)
- puts "Done"
- print "Installing WebROaR ... "
- cmd = "webroar install 2>> build_test.log >>build_test.log << **\nadmin\nimpetus\nimpetus\n\n**"
+ unless File.exists?(gem_file)
+ failed += 1
+ next
+ end
+
+ begin
+ file.print "Install gem and server ... " if file
+ print "Installing gem ... "
+ cmd = "gem install #{gem_file} 2>> #{File.join(BUILD_TEST_REPORT, 'test.log')} >>#{File.join(BUILD_TEST_REPORT, 'test.log')}"
system(cmd)
if($?==0)
puts "Done"
+ print "Installing WebROaR ... "
+ cmd = "webroar install 2>> #{File.join(BUILD_TEST_REPORT, 'test.log')} >>#{File.join(BUILD_TEST_REPORT, 'test.log')} << **\nadmin\nimpetus\nimpetus\n\n**"
+ system(cmd)
+ if($?==0)
+ file.puts "Pass" if file
+ puts "Done"
+ else
+ failed += 1
+ puts "Failed"
+ file.puts "Failed" if file
+ end
else
- test_flag = 0
+ failed += 1
puts "Failed"
+ file.puts "Failed" if file
end
- else
- test_flag = 0
+ rescue Exception => e
+ failed += 1
puts "Failed"
+ file.puts "Failed" if file
+ Rake::Task[:log_exception].invoke(e)
end
-
end
desc "Uninstall server and its gem"
-task :build_uninstall do
- print "Uninstalling WebROaR ... "
- cmd = "webroar uninstall 2>> build_test.log >>build_test.log"
- system(cmd)
- if($?==0)
- puts "Done"
- else
+task :build_uninstall => [:create_test_dirs] do
+ total += 1
+ file.print "Uninstall server and gem ... " if file
+ begin
+ print "Uninstalling WebROaR ... "
+ cmd = "webroar uninstall 2>> #{File.join(BUILD_TEST_REPORT, 'test.log')} >>#{File.join(BUILD_TEST_REPORT, 'test.log')}"
+ system(cmd)
+ if($?==0)
+ puts "Done"
+ else
+ puts "Failed"
+ end
+ print "Uninstalling gem ..."
+ cmd = "gem uninstall webroar -v #{Webroar::VERSION::STRING} -x 2>> #{File.join(BUILD_TEST_REPORT, 'test.log')} >>#{File.join(BUILD_TEST_REPORT, 'test.log')} << **\ny\n** "
+ system(cmd)
+ if($?==0)
+ puts "Done"
+ file.puts "Pass" if file
+ else
+ failed += 1
+ puts "Failed"
+ file.puts "Failed" if file
+ end
+ rescue
+ failed += 1
puts "Failed"
+ file.puts "Failed" if file
+ Rake::Task[:log_exception].invoke(e)
end
- #puts "server uninstall $? = #$?"
- print "Uninstalling gem ..."
- cmd = "gem uninstall webroar -v #{Webroar::VERSION::STRING} -x 2>> build_test.log >>build_test.log << **\ny\n** "
- system(cmd)
- if($?==0)
- puts "Done"
- else
- puts "Failed"
- end
-
- # puts "gem uninstall $? = #$?"
end
desc "Build test"
-task :build_test do
- puts "Executing build tests ..."
- build_test = File.join(TEST_DIR,'build_test')
- build_test_summary = File.join(TEST_DIR,'build_test_summary')
- exception_log = File.join(TEST_DIR,'exception.log')
- File.truncate('build_test.log', 0) if File.exists?('build_test.log')
+task :build_test => [:create_test_dirs] do
+ next unless test_flag == 1 or ENV["build_test"] == "yes"
- Dir.chdir(WEBROAR_ROOT)
- File.truncate(build_test,0) if File.exists?(build_test)
- File.truncate(build_test_summary, 0) if File.exists?(build_test_summary)
- total = 0
- failed = 0
- bf = File.open(build_test,'w')
- bf.print "Build gem ... "
- total += 1
- t = Rake::Task[:build]
begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Done"
- end
+ puts "Executing build tests ..."
+ build_test_summary = File.join(BUILD_TEST_REPORT,'test-summary')
+ build_test = File.join(BUILD_TEST_REPORT,'build_test')
+ File.truncate(File.join(BUILD_TEST_REPORT, 'test.log'), 0) if File.exists?(File.join(BUILD_TEST_REPORT, 'test.log'))
+
+ Dir.chdir(WEBROAR_ROOT)
+ File.truncate(build_test_summary, 0) if File.exists?(build_test_summary)
+ File.truncate(build_test, 0) if File.exist?(build_test)
+
+ total = 0
+ failed = 0
+ file = File.open(build_test,'w')
+
+ Rake::Task[:build_install].invoke
+ Rake::Task[:build_uninstall].invoke
+
+ file.puts "#{total} total, #{failed} failed\n"
+ file.close
+
+ file = nil
- bf.print "Install gem and server ... "
- total += 1
- t = Rake::Task[:build_install]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
+ str = "Build test summary\nTotal test: #{total}\nFailed test: #{failed}\n"
+ File.open(build_test_summary,"w") do |f|
+ f.puts str
end
- end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Pass"
- end
-
- bf.print "Uninstall server and gem ... "
- total += 1
- t = Rake::Task[:build_uninstall]
- begin
- t.invoke()
rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
+ Rake::Task[:log_exception].invoke(e)
end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Pass"
- end
-
- bf.puts "#{total} total, #{failed} failed\n"
- bf.close
-
- str = "Build test summary\nTotal test: #{total}\nFailed test: #{failed}\n"
- File.open(build_test_summary,"w") do |f|
- f.puts str
- end
end
-def check_and_copy(src_file, dest_file)
- if File.exists?(src_file)
- FileUtils.copy(src_file, dest_file)
- end
-end
-
def test_cleanup(report_dir)
- unless File.exists?(report_dir)
- FileUtils.mkdir_p(report_dir)
+ unless REPORT_DIR == report_dir
+ FileUtils.cp_r(REPORT_DIR, report_dir)
end
-
- # copy unit tests related files
- check_and_copy(File.join(UNIT_TEST_DIR,'test_summary'), File.join(report_dir, 'unit-test-summary'))
- check_and_copy(File.join(UNIT_TEST_DIR, 'testcases.log'), File.join(report_dir, 'unit-testcase.log'))
- check_and_copy(File.join(UNIT_TEST_DIR, 'test.log'), File.join(report_dir, 'unit-test.log'))
-
- # copy admin-panel tests related files
- check_and_copy(File.join(WEBROAR_ROOT,'src', 'admin_panel', 'test.log'), File.join(report_dir, 'admin-panel-test.log'))
- check_and_copy(File.join(WEBROAR_ROOT,'src', 'admin_panel', 'error.log'), File.join(report_dir, 'admin-panel-error.log'))
- check_and_copy(File.join(WEBROAR_ROOT,'src', 'admin_panel', 'test_summary'), File.join(report_dir, 'admin-panel-test-summary'))
-
- # copy functional tests related files
- check_and_copy(File.join(SPEC_DIR, 'test.log'), File.join(report_dir, 'spec-test.log'))
- check_and_copy(File.join(SPEC_DIR, 'test_summary'), File.join(report_dir, 'spec-test-summary'))
- check_and_copy(File.join(SPEC_DIR, 'setup.log'), File.join(report_dir, 'spec-test-setup.log'))
- check_and_copy(File.join(SPEC_DIR, 'test-run.log'), File.join(report_dir, 'spec-test-run.log'))
-
- # copy load tests related files
- check_and_copy(File.join(TEST_DIR, 'load_test_summary'), File.join(report_dir, 'load-test-summary'))
- check_and_copy(File.join(TEST_DIR, 'load_test_result_fix'), File.join(report_dir, 'load-test-result-fix'))
- check_and_copy(File.join(TEST_DIR, 'load_test_result_random'), File.join(report_dir, 'load-test-result-random'))
-
- # copy exception.log
- check_and_copy(File.join(TEST_DIR, 'exception.log'), File.join(report_dir, 'exception.log.1'))
-
- #copy database file
- check_and_copy(File.join(WEBROAR_ROOT, 'src', 'admin_panel', 'db', 'webroar_test.sqlite3'), report_dir)
-
- # copy debug_log files
- if ENV["debug_build"] == "yes"
- dest_debug_log_dir = File.join(report_dir, 'debug_log')
- unless File.exists?(dest_debug_log_dir)
- FileUtils.mkdir_p(dest_debug_log_dir)
- end
- log_file_pattern = File.join(DEBUG_LOG_DIR,'*')
- log_files = Dir.glob(log_file_pattern)
- for file in log_files
- FileUtils.cp(file,dest_debug_log_dir)
- end
- end
-end
-desc "Integrated testing executes unit tests, admin-panel tests and functional \
- tests. To run load tests give load_test=yes, to run build tests give \
- build_test=yes as an argument. To run test under debug build give \
- debug_build=yes as an argument."
-task :all_test do
-
- if ENV["debug_build"] == "yes"
- # Clear log files.
- system("webroar clear")
- unless File.exists?(LOG_FILES)
- FileUtils.mkdir_p(LOG_FILES)
- end
- end
-
- exception_log = File.join(TEST_DIR,'exception.log')
- File.truncate(exception_log,0) if File.exists?(exception_log)
-
- if(test_flag==1)
- t = Rake::Task[:unit_test]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- end
-
- if(test_flag==1)
- t = Rake::Task[:spec]
- puts "Executing functional tests ..."
- begin
- ENV["SPEC_OPTS"] = "--format specdoc:#{TEST_RESULT}"
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- ensure
- if File.exists?(TEST_RESULT)
- system("tail -2 #{File.join(SPEC_DIR,'test.log')} > #{File.join(SPEC_DIR,'test_summary')}")
- result = File.read(File.join(SPEC_DIR,'test_summary'))
- total = 0
- failed = 0
- if result =~ /(\d+)\s*(example|examples),\s*(\d+)\s*failure/
- total = $1
- failed = $3
- end
- str = "Functional test summary\nTotal test: #{total}\nFailed test: #{failed}\n"
- File.open(File.join(SPEC_DIR,'test_summary'),"w") do |f|
- f.puts str
- end
- end
-
- if ENV["debug_build"] == "yes"
- unless File.exists?(DEBUG_LOG_DIR)
- FileUtils.mkdir_p(DEBUG_LOG_DIR)
- end
- log_file_pattern = File.join(LOG_FILES,'*.log')
- log_files = Dir.glob(log_file_pattern)
- for file in log_files
- FileUtils.cp(file,File.join(DEBUG_LOG_DIR,"#{File.basename(file)}.spec"))
- end
- cmd = "#{File.join(WEBROAR_ROOT,'bin','webroar')} clear"
- system(cmd)
- end
- end
- end
-
- if(test_flag==1)
- t = Rake::Task[:admin_panel_test]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- end
-
- if test_flag==1 and ENV["load_test"] == 'yes'
- t = Rake::Task[:load_test]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- end
-
- if test_flag==1 and ENV["build_test"] == "yes"
- t = Rake::Task[:build_test]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- end
-
- if(ENV["report_dir"])
- test_cleanup(ENV["report_dir"])
- end
-
- unless ENV["no_report"]
- test_report(ENV["report_dir"])
- end
-
end
-#task :all_test => [:unit_test, :admin_panel_test, :spec, :load_test]
-
-def test_report(report_dir)
+def test_report
total = 0
failed = 0
- f = File.open(File.join(report_dir,'test-summary'),"w")
+ f = File.open(File.join(REPORT_DIR,'test-summary'),"w")
f.puts "------------------------------------------------------------------------------"
fmt = "%*s%*s%*s"
str = fmt % [-58,'Type',10,'Total',10,'Failed']
f.puts str
f.puts "-------------------------------------------------------------------------------"
- if File.exists?(File.join(report_dir,'unit-test-summary'))
- result = File.read(File.join(report_dir,'unit-test-summary'))
+ if File.exists?(File.join(UNIT_TEST_REPORT,'test-summary'))
+ result = File.read(File.join(UNIT_TEST_REPORT,'test-summary'))
result =~ /Total\s*test:\s*(\d+)\s*Failed\s*test:\s*(\d+)/m
str = fmt % [-58, 'Unit Tests',10,$1,10,$2]
f.puts str
total += $1.to_i
failed += $2.to_i
end
- if File.exists?(File.join(report_dir,'admin-panel-test-summary'))
- result = File.read(File.join(report_dir,'admin-panel-test-summary'))
+ if File.exists?(File.join(ADMIN_TEST_REPORT,'test-summary'))
+ result = File.read(File.join(ADMIN_TEST_REPORT,'test-summary'))
result =~ /Total\s*test:\s*(\d+)\s*Failed\s*test:\s*(\d+)\s*Error:\s*(\d+)/m
str = fmt % [-58, 'Admin Panel Tests',10,$1,10,$2]
f.puts str
total += $1.to_i
failed += $2.to_i
end
- if File.exists?(File.join(report_dir,'spec-test-summary'))
- result = File.read(File.join(report_dir,'spec-test-summary'))
+ if File.exists?(File.join(SPEC_TEST_REPORT,'test-summary'))
+ result = File.read(File.join(SPEC_TEST_REPORT,'test-summary'))
result =~ /Total\s*test:\s*(\d+)\s*Failed\s*test:\s*(\d+)/m
str = fmt % [-58, 'Functional Tests', 10, $1, 10, $2]
f.puts str
total += $1.to_i
failed += $2.to_i
end
- if File.exists?(File.join(report_dir,'load-test-summary'))
- result = File.read(File.join(report_dir,'load-test-summary'))
+ if File.exists?(File.join(LOAD_TEST_REPORT,'test-summary'))
+ result = File.read(File.join(LOAD_TEST_REPORT,'test-summary'))
res = result.scan(/Total\s*test:\s*(\d+)\s*Failed\s*test:\s*(\d+)\s*/m)
str = fmt % [-58, "Load Test I - Continuous Run", 10, res[0][0], 10, res[0][1]]
f.puts str
str = fmt % [-58, 'Load test II - Random Sleep Intervals', 10, res[1][0], 10, res[1][1]]
f.puts str
total += res[0][0].to_i + res[1][0].to_i
failed += res[0][1].to_i + res[1][1].to_i
end
- if File.exists?(File.join(TEST_DIR,'build_test_summary'))
- result = File.read(File.join(TEST_DIR,'build_test_summary'))
+ if File.exists?(File.join(BUILD_TEST_REPORT,'test-summary'))
+ result = File.read(File.join(BUILD_TEST_REPORT,'test-summary'))
result =~ /Total\s*test:\s*(\d+)\s*Failed\s*test:\s*(\d+)/m
str = fmt % [-58, "Build Tests", 10, $1, 10, $2]
f.puts str
f.puts "\n"
total += $1.to_i
failed += $2.to_i
end
f.close
- f = File.open(File.join(report_dir,'test-report'),"w")
- f.puts File.read(File.join(report_dir,'test-summary')) if File.exists?(File.join(report_dir,'test-summary'))
+ f = File.open(File.join(REPORT_DIR,'test-report'),"w")
+ f.puts File.read(File.join(REPORT_DIR,'test-summary')) if File.exists?(File.join(REPORT_DIR,'test-summary'))
- if File.exists?(File.join(report_dir,'unit-test.log'))
+ if File.exists?(File.join(UNIT_TEST_REPORT,'test.log'))
f.puts "-------------------------------Unit Tests Result--------------------------------"
- f.puts File.read(File.join(report_dir,'unit-test.log'))
+ f.puts File.read(File.join(UNIT_TEST_REPORT,'test.log'))
f.puts "\n"
end
- if File.exists?(File.join(report_dir,'admin-panel-test.log'))
+ if File.exists?(File.join(ADMIN_TEST_REPORT,'test.log'))
f.puts "-----------------------------Admin Panel Tests Result---------------------------"
- f.puts File.read(File.join(report_dir, 'admin-panel-test.log'))
+ f.puts File.read(File.join(ADMIN_TEST_REPORT, 'test.log'))
f.puts "\n"
end
- if File.exists?(File.join(report_dir,'spec-test.log'))
+ if File.exists?(File.join(SPEC_TEST_REPORT,'test.log'))
f.puts "------------------------------Functional Tests Result---------------------------"
- f.puts File.read(File.join(report_dir,'spec-test.log'))
+ f.puts File.read(File.join(SPEC_TEST_REPORT,'test.log'))
f.puts "\n"
end
- if File.exists?(File.join(report_dir,'load-test-result-fix'))
+ if File.exists?(File.join(LOAD_TEST_REPORT,'test-result-fix'))
f.puts "---------------------------Load Test I - Continuous Run-------------------------"
- f.puts File.read(File.join(report_dir,'load-test-result-fix'))
+ f.puts File.read(File.join(LOAD_TEST_REPORT,'test-result-fix'))
f.puts "\n"
end
- if File.exists?(File.join(report_dir,'load-test-result-random'))
+ if File.exists?(File.join(LOAD_TEST_REPORT,'test-result-random'))
f.puts "------------------------Load test II - Random Sleep Intervals-------------------"
- f.puts File.read(File.join(report_dir,'load-test-result-random'))
+ f.puts File.read(File.join(LOAD_TEST_REPORT,'test-result-random'))
f.puts "\n"
end
- if File.exists?(File.join(TEST_DIR,'build_test'))
+ if File.exists?(File.join(BUILD_TEST_REPORT,'build_test'))
f.puts "--------------------------------Build Tests Result------------------------------"
- f.puts File.read(File.join(TEST_DIR,'build_test'))
+ f.puts File.read(File.join(BUILD_TEST_REPORT,'build_test'))
f.puts "\n"
end
f.close
- f = File.open(File.join(report_dir,"test-result"),"w")
+ f = File.open(File.join(REPORT_DIR,"test-result"),"w")
if total == 0 and failed == 0
f.puts "Could not be executed at all"
elsif total == failed
f.puts "All tests failed"
elsif failed != 0
@@ -615,107 +556,42 @@
end
f.close
end
+desc "Integrated testing executes unit tests, admin-panel tests and functional \
+ tests. To run load tests give load_test=yes, to run build tests give \
+ build_test=yes as an argument. To run test under debug build give \
+ debug_build=yes as an argument."
+task :all_test => [:create_test_dirs, :unit_test, :spec_test, :admin_panel_test, :load_test] do
+
+ unless ENV["no_report"]
+ test_report
+ end
+
+ if(ENV["report_dir"])
+ test_cleanup(ENV["report_dir"])
+ end
+
+end
+
desc "Runs integrated test-suit comprises of gem creation, installation, unit \
tests, admin-panel tests, functional tests. To run load tests give \
load_test=yes as an argument. To run under debug build give debug_build=\
yes as an argument."
-task :test do
- exception_log = File.join(TEST_DIR,'exception.log')
- File.truncate(exception_log,0) if File.exists?(exception_log)
+task :test => [:build_test] do
- build_test = File.join(TEST_DIR,'build_test')
- build_test_summary = File.join(TEST_DIR,'build_test_summary')
- exception_log = File.join(TEST_DIR,'exception.log')
-
Dir.chdir(WEBROAR_ROOT)
- File.truncate(build_test,0) if File.exists?(build_test)
- File.truncate(build_test_summary, 0) if File.exists?(build_test_summary)
- total = 0
- failed = 0
- bf = File.open(build_test,'w')
- bf.print "Build gem ... "
- total += 1
- t = Rake::Task[:build]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Pass"
- end
+
+ Rake::Task[:build_install].reenable
+ Rake::Task[:build_install].invoke
- bf.print "Install gem and server ... "
- total += 1
- t = Rake::Task[:build_install]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Pass"
- end
+ str = " "
+ str += "-d " if ENV["debug_build"] == "yes"
+ str += "-l" if ENV["load_test"] == "yes"
- str = "-n "
-
- if ENV["debug_build"] == "yes"
- str += "-d "
- end
-
- if ENV["load_test"] == "yes"
- str += "-l"
- end
-
# Run tests on installed directory. Copy test-report and test-summary to TEST_DIR
cmd = "webroar test -r=#{REPORT_DIR} #{str}"
system(cmd)
-
- bf.print "Uninstall server and gem ... "
- total += 1
- t = Rake::Task[:build_uninstall]
- begin
- t.invoke()
- rescue Exception => e
- File.open(exception_log,"a") do |f|
- f.puts e
- f.puts e.backtrace
- end
- end
- # puts "$? = #$?"
- unless $? == 0
- failed += 1
- bf.puts "Failed"
- else
- bf.puts "Pass"
- end
-
- bf.puts "#{total} total, #{failed} failed\n"
- bf.close
-
- str = "Build test summary\nTotal test: #{total}\nFailed test: #{failed}\n"
- File.open(build_test_summary,"w") do |f|
- f.puts str
- end
-
- test_report(REPORT_DIR)
+ Rake::Task[:build_uninstall].reenable
+ Rake::Task[:build_uninstall].invoke
end
-
-#desc "Integration testing and test-suite summary, report and one line result."
-#task :test => [:all_test, :test_report]