Module: Funit

Includes:
Assertions
Included in:
TestSuite
Defined in:
lib/funit/functions.rb,
lib/funit.rb,
lib/funit/assertions.rb,
lib/funit/test_suite.rb,
lib/funit/fortran_deps.rb

Overview

Compile and run the requested tests – Copyright 2006 United States Government as represented by NASA Langley Research Center. No copyright is claimed in the United States under Title 17, U.S. Code. All Other Rights Reserved.

This file is governed by the NASA Open Source Agreement. See COPYING for details. ++

Defined Under Namespace

Modules: Assertions Classes: Compiler, Depend, TestSuite

Instance Method Summary collapse

Methods included from Assertions

#isequal, #isequalwithin, #isfalse, #isrealequal, #istrue, #writeAssert

Instance Method Details

#compileTests(testSuites) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/funit/functions.rb', line 115

def compileTests testSuites
  puts "computing dependencies"
  dependencies = Depend.new(['.', '../LibF90', '../PHYSICS_DEPS'])
  puts "locating associated source files and sorting for compilation"
  requiredSources = dependencies.required_source_files('TestRunner.f90')

  puts compile = "#{ENV['FC']} #{ENV['FCFLAGS']} -o TestRunner \\\n  #{requiredSources.join(" \\\n  ")}"

  raise "Compile failed." unless system(compile)
end

#funit_exists?(moduleName) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/funit/functions.rb', line 39

def funit_exists?(moduleName)
  File.exists? moduleName+".fun"
end

#parseCommandLineObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/funit/functions.rb', line 43

def parseCommandLine

  moduleNames = requestedModules(ARGV)

  if moduleNames.empty?
    raise "   *Error: no test suites found in this directory"
  end

  moduleNames.each do |mod|
    unless funit_exists?(mod) 
      errorMessage = <<-FUNITDOESNOTEXIST
 Error: could not find test suite #{mod}.fun
 Test suites available in this directory:
 #{requestedModules([]).join(' ')}

 Usage: #{File.basename $0} [test names (w/o .fun suffix)]
      FUNITDOESNOTEXIST
      raise errorMessage
    end
  end

end

#requestedModules(moduleNames) ⇒ Object

class



32
33
34
35
36
37
# File 'lib/funit/functions.rb', line 32

def requestedModules(moduleNames)
  if (moduleNames.empty?)
    moduleNames = Dir["*.fun"].each{ |mod| mod.chomp! ".fun" }
  end
  moduleNames
end

#run_testsObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/funit.rb', line 18

def run_tests
  Compiler.new# a test for compiler env set (remove this later)
  writeTestRunner(testSuites = parseCommandLine)

  # convert each *.fun file into a Fortran file:
  testSuites.each{ |ts| TestSuite.new(ts) }
 
  compileTests testSuites

  raise "Failed to execute TestRunner" unless system("./TestRunner")
end

#syntaxError(message, testSuite) ⇒ Object



107
108
109
# File 'lib/funit/functions.rb', line 107

def syntaxError( message, testSuite )
  raise "\n   *Error: #{message} [#{testSuite}.fun:#$.]\n\n"
end

#warning(message, testSuite) ⇒ Object



111
112
113
# File 'lib/funit/functions.rb', line 111

def warning( message, testSuite )
  $stderr.puts "\n *Warning: #{message} [#{testSuite}.fun:#$.]"
end

#writeTestRunner(testSuites) ⇒ Object



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
# File 'lib/funit/functions.rb', line 66

def writeTestRunner testSuites

  File.delete("TestRunner.f90") if File.exists?("TestRunner.f90")
  testRunner = File.new "TestRunner.f90", "w"

  testRunner.puts <<-HEADER
! TestRunner.f90 - runs test suites
!
! #{File.basename $0} generated this file on #{Time.now}.

program TestRunner

  HEADER

  testSuites.each { |testSuite| testRunner.puts " use #{testSuite}_fun" }

  testRunner.puts <<-DECLARE

 implicit none

 integer :: numTests, numAsserts, numAssertsTested, numFailures
  DECLARE

  testSuites.each do |testSuite|
    testRunner.puts <<-TRYIT

 print *, ""
 print *, "#{testSuite} test suite:"
 call test_#{testSuite}( numTests, &
      numAsserts, numAssertsTested, numFailures )
 print *, "Passed", numAssertsTested, "of", numAsserts, &
        "possible asserts comprising", &
         numTests-numFailures, "of", numTests, "tests." 
    TRYIT
  end

  testRunner.puts "\n print *, \"\""
  testRunner.puts "\nend program TestRunner"
  testRunner.close
end