| Module | Funit |
| In: |
lib/funit/assertions.rb
lib/funit/compiler.rb lib/funit/functions.rb lib/funit/testsuite.rb lib/funit.rb |
| TEST_RUNNER | = | ERB.new( %q{ ! TestRunner.f90 - runs fUnit test suites ! ! <%= File.basename $0 %> generated this file on <%= Time.now %>. program TestRunner <% test_suites.each do |test_suite| -%> use <%= test_suite %>_fun <% end -%> implicit none integer, dimension(<%=test_suites.size%>) :: numTests, numAsserts, numAssertsTested, numFailures <% test_suites.each_with_index do |test_suite,i| -%> write(*,*) write(*,*) "<%= test_suite %> test suite:" call test_<%= test_suite %> & ( numTests(<%= i+1 %>), numAsserts(<%= i+1 %>), numAssertsTested(<%= i+1 %>), numFailures(<%= i+1 %>) ) write(*,1) numAssertsTested(<%= i+1 %>), numAsserts(<%= i+1 %>), & numTests(<%= i+1 %>)-numFailures(<%= i+1 %>), numTests(<%= i+1 %>) 1 format('Passed ',i0,' of ',i0,' possible asserts comprising ',i0,' of ',i0,' tests.') <% end -%> write(*,*) write(*,'(a)') "==========[ SUMMARY ]==========" <% max_length = test_suites.empty? ? 0 : test_suites.max.length -%> <% test_suites.each_with_index do |test_suite,i| -%> write(*,'(a<%=max_length+2%>)',advance="no") " <%= test_suite %>:" if ( numFailures(<%= i+1 %>) == 0 ) then write(*,*) " passed" else write(*,*) " failed <<<<<" end if <% end -%> write(*,*) if ( sum(numFailures) /= 0 ) stop 1 end program TestRunner }.gsub(/^ /,''), nil, '-' ) |
| MAKEFILE | = | ERB.new( %q{ # makefile to compile TestRunner.f90 # # <%= File.basename $0 %> generated this file on <%= Time.now %>. OBJ=<%= required_objects.join(' ') %> all:testrunner testrunner: $(OBJ) <%= "\t#{ENV['FC']} #{ENV['FCFLAGS']} #{ENV['LDFLAGS']}" %> -o TestRunner $(OBJ) <% file_dependencies.each do |source,dep| -%> <%= "#{source.sub(/\.f90/i,'.o')}: #{source} #{dep.map{ |d| d.sub(/\.f90/i,'.o') }.join(' ')}" %> <%= "\t(cd #{File.dirname(source)}; #{ENV['FC']} #{ENV['FCFLAGS']} #{sourceflag} -c #{File.basename(source)})" %> <% end -%> }.gsub(/^ /,''), nil, '-' ) |
| VERSION | = | '0.11.1' |
remove files generated by fUnit
# File lib/funit.rb, line 48 def clean_genFiles module_names = Dir["**/*.fun"].map{|mn| mn.chomp(".fun")} tbCancelled = module_names.map{|mn| mn+"_fun."} + ["TestRunner."] tbCancelled = tbCancelled.map{|tbc| [tbc+"f90",tbc+"o",tbc+"MOD"]}.flatten tbCancelled += Dir["**/TestRunner"] tbCancelled += Dir["**/makeTestRunner"] tbCancelled = (tbCancelled+tbCancelled.map{|tbc| tbc.downcase}).uniq FileUtils.rm_f(tbCancelled) end
# File lib/funit/functions.rb, line 115 def compile_tests(test_suites,prog_source_dirs=['.']) puts "computing dependencies" sourceflag = '' if ENV['FSFLAG'] then sourceflag = prog_source_dirs.map{|pd| ENV['FSFLAG']+pd }.join(' ') end dependencies = Fortran::Dependencies.new(:search_paths=>prog_source_dirs) puts "locating associated source files and sorting for compilation" dependencies.source_file_dependencies('TestRunner.f90') file_dependencies = dependencies.file_dependencies required_objects = file_dependencies.values.flatten.uniq.map{|s|s.sub(/\.f90/i,'.o')} required_objects << 'TestRunner.o' File.open("makeTestRunner", "w") {|file| file.puts MAKEFILE.result(binding)} compile = "make -f makeTestRunner" raise "Compile failed." unless system compile end
# File lib/funit/functions.rb, line 73 def funit_exists?(module_name) File.exists? "#{module_name}.fun" end
# File lib/funit/functions.rb, line 77 def parse_command_line module_names = requested_modules(ARGV) if module_names.empty? raise " *Error: no test suites found in this directory" end module_names.each do |mod| unless funit_exists?(mod) error_message = "Error: could not find test suite \#{mod}.fun\nTest suites available in this directory:\n\#{requested_modules([]).join(' ')}\n\nUsage: \#{File.basename $0} [test names (w/o .fun suffix)]\n" raise error_message end end end
prints a usage help for the user
# File lib/funit.rb, line 61 def print_help puts "To use fUnit, type:\nfunit [-options] [test_file_name(s)]\nThe argument(s) is optional. If no argument is given, then all the .fun files inside the working directory will be used.\n\nThe options are:\n--clean => To remove the files generated by fUnit\n-h, --help => Prints this help\n-s <dir>, --source <dir> => To specify a directory for the non-test source\n" end
# File lib/funit/functions.rb, line 66 def requested_modules(module_names) if module_names.empty? module_names = Dir["*.fun"].each{ |mod| mod.chomp! ".fun" } end module_names end
run all tests
# File lib/funit.rb, line 22 def run_tests(prog_source_dirs=['.']) Compiler.new# a test for compiler env set (FIXME: remove this later) write_test_runner( test_files = parse_command_line ) test_suites = [] test_files.each{ |test_file| tf_content = IO.read(test_file+'.fun') tf_content.scan(/test_suite\s+(\w+)(.*?)end\s+test_suite/m).each{|ts| ts_name = $1 ts_content = $2 if((!File.exist?(ts_name+"_fun.f90")) || File.mtime(ts_name+"_fun.f90") < File.mtime(test_file+".fun")) then if ( File.read(ts_name+'.f90').match(/\s*module\s+#{ts_name}/i) ) then TestSuite.new(ts_name, ts_content, false) else TestSuite.new(ts_name, ts_content, true) end end test_suites.push(ts_name) } } compile_tests(test_suites,prog_source_dirs) exit 1 unless system "env PATH='.' TestRunner" end
# File lib/funit/functions.rb, line 107 def syntax_error( message, test_suite ) raise "\n *Error: #{message} [#{test_suite}.fun:#$.]\n\n" end
# File lib/funit/functions.rb, line 111 def warning( message, test_suite ) $stderr.puts "\n *Warning: #{message} [#{test_suite}.fun:#$.]" end