Class: Funit::TestSuite
- Inherits:
-
File
- Object
- File
- Funit::TestSuite
show all
- Includes:
- Funit
- Defined in:
- lib/funit/testsuite.rb
Overview
Create testsuite wrapper code
Constant Summary
collapse
- KEYWORDS =
Regexp.union(/(end\s+)?(setup|teardown|test)/i,
Assertions::ASSERTION_PATTERN)
/^\s*!/
Constants included
from Funit
MAKEFILE, TEST_RUNNER, VERSION
Constants included
from Assertions
Assertions::ASSERTION_PATTERN
Instance Method Summary
collapse
Methods included from Funit
#check_for_FSFLAG, #clean_genFiles, #compile_tests, #funit_exists?, #parse_command_line, #print_env_flags, #requested_modules, #run_tests, #syntax_error, #warning, #write_test_runner
Methods included from Assertions
#assert_array_equal, #assert_equal, #assert_equal_within, #assert_false, #assert_real_equal, #assert_true, #get_args, #write_assert
Constructor Details
#initialize(suite_name, suite_content, wrap_with_module) ⇒ TestSuite
Returns a new instance of TestSuite.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/funit/testsuite.rb', line 16
def initialize( suite_name, suite_content, wrap_with_module )
@line_number = 'blank'
@suite_name = suite_name
@suite_content = suite_content
return nil unless funit_exists?(suite_name)
File.delete(suite_name+"_fun.f90") if File.exist?(suite_name+"_fun.f90")
super(suite_name+"_fun.f90","w")
@tests, @setup, @teardown = [], [], []
@wrap_with_module = wrap_with_module
module_wrapper if @wrap_with_module
top_wrapper
expand
close
end
|
Instance Method Details
#a_test(test_name, funit_contents) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/funit/testsuite.rb', line 128
def a_test test_name, funit_contents
@test_name = test_name
@tests.push test_name
syntax_error("test name #@test_name not unique",@suite_name) if (@tests.uniq!)
puts " subroutine #{test_name}\n\n"
num_of_asserts = 0
while (line = funit_contents.shift) && line !~ /end\s+test/i
case line
when
puts line
when Assertions::ASSERTION_PATTERN
@line_number = @funit_total_lines - funit_contents.length
num_of_asserts += 1
puts send( $1.downcase, line )
else
puts line
end
end
warning("no asserts in test", @suite_name) if num_of_asserts == 0
puts "\n numTests = numTests + 1\n\n"
puts " end subroutine #{test_name}\n\n"
end
|
#add_to_setup(funit_contents) ⇒ Object
111
112
113
114
115
|
# File 'lib/funit/testsuite.rb', line 111
def add_to_setup funit_contents
while (line = funit_contents.shift) && line !~ /end\s+setup/i
@setup.push line
end
end
|
#add_to_teardown(funit_contents) ⇒ Object
117
118
119
120
121
|
# File 'lib/funit/testsuite.rb', line 117
def add_to_teardown funit_contents
while (line = funit_contents.shift) && line !~ /end\s+teardown/i
@teardown.push line
end
end
|
#close ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/funit/testsuite.rb', line 155
def close
puts "\n subroutine funit_setup"
puts @setup
puts " noAssertFailed = .true."
puts " end subroutine funit_setup\n\n"
puts "\n subroutine funit_teardown"
puts @teardown
puts " end subroutine funit_teardown\n\n"
puts "\n subroutine test_\#{@suite_name}( nTests, nAsserts, nAssertsTested, nFailures )\n\n integer :: nTests\n integer :: nAsserts\n integer :: nAssertsTested\n integer :: nFailures\n\n continue\n NEXTONE\n\n @tests.each do |test_name|\n puts \"\\n call funit_setup\"\n puts \" call \#{test_name}\"\n puts \" call funit_teardown\"\n end\n\n puts <<-LASTONE\n\n nTests = numTests\n nAsserts = numAsserts\n nAssertsTested = numAssertsTested\n nFailures = numFailures\n\n end subroutine test_\#{@suite_name}\n\nend module \#{@suite_name}_fun\n LASTONE\n super\nend\n"
|
#expand ⇒ Object
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
106
107
108
109
|
# File 'lib/funit/testsuite.rb', line 73
def expand
$stderr.print "expanding test suite: #{@suite_name}..."
funit_contents = @suite_content.split("\n")
@funit_total_lines = funit_contents.length
while (line = funit_contents.shift) && line !~ KEYWORDS
puts line
end
funit_contents.unshift line
puts " contains\n\n"
while (line = funit_contents.shift)
case line
when
puts line
when /^setup/i
add_to_setup funit_contents
when /^teardown/i
add_to_teardown funit_contents
when /^Xtest\s+(\w+)/i
ignore_test($1,funit_contents)
when /^test\s+(\w+)/i
a_test($1,funit_contents)
when /^test/i
syntax_error "no name given for test", @suite_name
when /^end\s+(setup|teardown|test)/i
syntax_error "no matching #$1 for an #$&", @suite_name
when Assertions::ASSERTION_PATTERN
syntax_error "#$1 assertion not in a test block", @suite_name
else
puts line
end
end
$stderr.puts "done."
end
|
32
33
34
35
36
37
38
39
|
# File 'lib/funit/testsuite.rb', line 32
def
puts "! \#{@suite_name}_fun.f90 - a unit test suite for \#{@suite_name}.f90\n!\n! \#{File.basename $0} generated this file from \#{@suite_name}.fun\n\n HEADER\nend\n"
|
#ignore_test(test_name, funit_contents) ⇒ Object
123
124
125
126
|
# File 'lib/funit/testsuite.rb', line 123
def ignore_test test_name, funit_contents
warning("Ignoring test: #{test_name}", @suite_name)
line = funit_contents.shift while line !~ /end\s+Test/i
end
|
#module_wrapper ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/funit/testsuite.rb', line 41
def module_wrapper
puts "module \#{@suite_name}_mod\ncontains\n include '\#@suite_name.f90'\nend module \#{@suite_name}_mod\n\n MODULE_WRAPPER\nend\n"
|
#top_wrapper ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/funit/testsuite.rb', line 51
def top_wrapper
puts "module \#{@suite_name}_fun\n\n use \#{ @wrap_with_module ? @suite_name+'_mod' : @suite_name }\n\n implicit none\n\n logical :: noAssertFailed\n\n public :: test_\#@suite_name\n\n private\n\n integer :: numTests = 0\n integer :: numAsserts = 0\n integer :: numAssertsTested = 0\n integer :: numFailures = 0\n\n TOP\nend\n"
|