fUnit 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,95 +8,105 @@ require 'fileutils'
8
8
 
9
9
  class TestFortranDeps < Test::Unit::TestCase
10
10
 
11
- def setup
12
- Dir.mkdir 'DependenciesFixture'
13
- Dir.chdir 'DependenciesFixture'
14
- Dir.mkdir 'lib'
15
- Dir.chdir 'lib'
16
- File.open('solution.f90','w') do |f|
17
- f.puts "module solution\nuse area\nend module solution"
11
+ def setup
12
+ Dir.mkdir 'DependenciesFixture'
13
+ Dir.chdir 'DependenciesFixture'
14
+ Dir.mkdir 'lib'
15
+ Dir.chdir 'lib'
16
+ File.open('solution.f90','w') do |f|
17
+ f.puts "module solution\nuse area\nend module solution"
18
+ end
19
+ Dir.chdir '..'
20
+ Dir.mkdir 'src'
21
+ Dir.chdir 'src'
22
+ File.open('main.F90','w') do |f|
23
+ f.puts 'program whizzard'
24
+ f.puts " use grid\n use solution\n use circle"
25
+ f.puts 'end program whizzard'
26
+ end
27
+ File.open('grid.f90','w') do |f|
28
+ f.puts "module grid\nuse area\nend module grid"
29
+ end
30
+ File.open('shapes.f90','w') do |f|
31
+ f.puts "module rectangle_fun3d\nend module rectangle_fun3d"
32
+ f.puts "module circle\n use area\nend module circle"
33
+ end
34
+ File.open('area.f90','w'){ |f| f.puts "module area\nend module area" }
35
+ File.open('externalUse.f90','w') do |f|
36
+ f.puts "program user\nuse cantFindModule\nend program"
37
+ end
38
+ @dep = Funit::Depend.new
18
39
  end
19
- Dir.chdir '..'
20
- Dir.mkdir 'src'
21
- Dir.chdir 'src'
22
- File.open('main.F90','w') do |f|
23
- f.puts 'program whizzard'
24
- f.puts " use grid\n use solution\n use circle"
25
- f.puts 'end program whizzard'
40
+
41
+ def teardown
42
+ Dir.chdir '../..'
43
+ FileUtils.rm_rf 'DependenciesFixture'
44
+ end
45
+
46
+ def test_finds_which_modules_a_source_file_uses
47
+ assert_equal %w[grid solution circle], @dep.modules_used_in( 'main.F90' )
26
48
  end
27
- File.open('grid.f90','w'){ |f| f.puts "module grid\nuse area\nend module grid" }
28
- File.open('shapes.f90','w') do |f|
29
- f.puts "module rectangle_fun3d\nend module rectangle_fun3d"
30
- f.puts "module circle\n use area\nend module circle"
49
+
50
+ def test_finds_modules_defined_in_source_file
51
+ assert_equal %w[rectangle_fun3d circle],
52
+ @dep.modules_defined_in( 'shapes.f90' )
31
53
  end
32
- File.open('area.f90','w'){ |f| f.puts "module area\nend module area" }
33
- File.open('externalUse.f90','w') do |f|
34
- f.puts "program user\nuse cantFindModule\nend program"
54
+
55
+ def test_create_module_definition_hash
56
+ assert_equal %w[circle rectangle_fun3d],
57
+ @dep.build_dictionary_of_modules_in( 'shapes.f90' ).keys.sort
35
58
  end
36
- @dep = Funit::Depend.new
37
- end
38
-
39
- def test_finds_which_modules_a_source_file_uses
40
- assert_equal %w[grid solution circle], @dep.modules_used_in( 'main.F90' )
41
- end
42
-
43
- def test_finds_modules_defined_in_source_file
44
- assert_equal %w[rectangle_fun3d circle], @dep.modules_defined_in( 'shapes.f90' )
45
- end
46
-
47
- def test_create_module_definition_hash
48
- assert_equal %w[circle rectangle_fun3d],
49
- @dep.build_dictionary_of_modules_in( 'shapes.f90' ).keys.sort
50
- end
51
-
52
- def test_locating_all_fortran_files_in_search_path
53
- files = %w[ ../lib/solution.f90 ./area.f90 ./externalUse.f90
54
- ./grid.f90 ./main.F90 ./shapes.f90 ]
55
- @dep.fortran_files_within.each do |file|
56
- assert files.include?(file)
59
+
60
+ def test_locating_all_fortran_files_in_search_path
61
+ files = %w[ ../lib/solution.f90 ./area.f90 ./externalUse.f90
62
+ ./grid.f90 ./main.F90 ./shapes.f90 ]
63
+ @dep.fortran_files_within.each do |file|
64
+ assert files.include?(file)
65
+ end
57
66
  end
58
- end
59
-
60
- def test_build_hash_with_source_files
61
- f90 = %w[./grid.f90 ../lib/solution.f90 ./shapes.f90 ./area.f90]
62
- hash = @dep.build_dictionary_of_modules_in( f90 )
63
- assert_equal \
64
- %w[./shapes.f90 ./shapes.f90 ./area.f90 ../lib/solution.f90 ./grid.f90].sort,
65
- hash.values.sort
66
- assert_equal %w[rectangle_fun3d circle area solution grid].sort, hash.keys.sort
67
- assert_equal hash , @dep.build_hash_of_modules_in_files_within
68
- end
69
-
70
- def test_dependency_generation_elements
71
- directoryHash = @dep.build_hash_of_modules_in_files_within
72
-
73
- sourceFile = "main.F90"
74
- modules = @dep.modules_used_in( sourceFile )
75
- assert_equal %w[grid solution circle], modules
76
-
77
- newSourceFiles = modules.collect{ |mod| directoryHash[mod] }
78
- assert_equal %w[./grid.f90 ../lib/solution.f90 ./shapes.f90], newSourceFiles
79
-
80
- newModules = newSourceFiles.collect do |file|
81
- @dep.modules_used_in( file )
82
- end.flatten.uniq
83
-
84
- assert_equal ["area"], newModules
85
- end
86
-
87
- def test_makefile_dependency_line_generation
88
- sourceFile = "main.F90"
89
- makeGolden=String.new <<-GOLDEN
67
+
68
+ def test_build_hash_with_source_files
69
+ f90 = %w[./grid.f90 ../lib/solution.f90 ./shapes.f90 ./area.f90]
70
+ hash = @dep.build_dictionary_of_modules_in( f90 )
71
+ assert_equal %w[ ./shapes.f90 ./shapes.f90 ./area.f90
72
+ ../lib/solution.f90 ./grid.f90 ].sort,
73
+ hash.values.sort
74
+ assert_equal %w[ rectangle_fun3d circle area solution grid ].sort,
75
+ hash.keys.sort
76
+ assert_equal hash , @dep.build_hash_of_modules_in_files_within
77
+ end
78
+
79
+ def test_dependency_generation_elements
80
+ directoryHash = @dep.build_hash_of_modules_in_files_within
81
+
82
+ sourceFile = "main.F90"
83
+ modules = @dep.modules_used_in( sourceFile )
84
+ assert_equal %w[grid solution circle], modules
85
+
86
+ newSourceFiles = modules.collect{ |mod| directoryHash[mod] }
87
+ assert_equal %w[ ./grid.f90 ../lib/solution.f90 ./shapes.f90],
88
+ newSourceFiles
89
+
90
+ newModules = newSourceFiles.collect do |file|
91
+ @dep.modules_used_in( file )
92
+ end.flatten.uniq
93
+
94
+ assert_equal ["area"], newModules
95
+ end
96
+
97
+ def test_makefile_dependency_line_generation
98
+ sourceFile = "main.F90"
99
+ makeGolden=String.new <<-GOLDEN
90
100
  main.o: main.F90 \\
91
101
  grid.o \\
92
102
  solution.o \\
93
103
  shapes.o
94
- GOLDEN
95
- assert_equal makeGolden, @dep.makefile_dependency_line(sourceFile)
96
- end
104
+ GOLDEN
105
+ assert_equal makeGolden, @dep.makefile_dependency_line(sourceFile)
106
+ end
97
107
 
98
- def test_makefile_dependency_recurses_properly
99
- makeGolden=String.new <<-GOLDEN
108
+ def test_makefile_dependency_recurses_properly
109
+ makeGolden=String.new <<-GOLDEN
100
110
  main.o: main.F90 \\
101
111
  grid.o \\
102
112
  solution.o \\
@@ -110,61 +120,58 @@ solution.o: solution.f90 \\
110
120
  area.o
111
121
  shapes.o: shapes.f90 \\
112
122
  area.o
113
- GOLDEN
123
+ GOLDEN
124
+
125
+ goldSplit = makeGolden.split("\n")
126
+ testSplit = @dep.dependencies('main.F90').split("\n")
127
+
128
+ while (gold = goldSplit.shift) && (test = testSplit.shift)
129
+ assert_equal gold, test
130
+ end
131
+ end
132
+
133
+ def test_source_file_dependency_hash
134
+ @dep.source_file_dependencies('main.F90')
135
+ assert_equal( 5, @dep.file_dependencies.size )
136
+ expected = {
137
+ "./area.f90" => [],
138
+ "./grid.f90" => ["./area.f90"],
139
+ "../lib/solution.f90" => ["./area.f90"],
140
+ "./shapes.f90" => ["./area.f90"],
141
+ "main.F90" => ["./grid.f90", "../lib/solution.f90", "./shapes.f90"]
142
+ }
143
+ assert_equal expected, @dep.file_dependencies
144
+ end
114
145
 
115
- goldSplit = makeGolden.split("\n")
116
- testSplit = @dep.dependencies('main.F90').split("\n")
146
+ def test_finds_required_source_files
147
+ expected = %w[ ./area.f90 ./shapes.f90 ../lib/solution.f90
148
+ ./grid.f90 ./main.F90 ]
149
+ found = @dep.required_source_files('./main.F90')
150
+ assert_equal expected.size, found.size
151
+ assert_equal './main.F90', found.last
152
+ assert_equal './area.f90', found.first
153
+ end
154
+
155
+ def test_finds_required_source_files_unordered
156
+ @dep.dependencies('main.F90')
157
+ sources = @dep.source_files
158
+ expected = %w[ main.F90 grid.f90 area.f90 solution.f90 shapes.f90 ]
159
+ assert_equal expected.size, sources.size
160
+ assert_equal 'shapes.f90', sources.last
161
+ assert_equal 'main.F90', sources.first
162
+ assert_equal expected, sources
163
+ end
164
+
165
+ def test_can_find_required_source_files_twice
166
+ files = %w[ ./main.F90 ./shapes.f90 ./area.f90
167
+ ../lib/solution.f90 ./grid.f90 ]
168
+ @dep.required_source_files('./main.F90')
169
+ assert_equal files.sort, @dep.required_source_files('./main.F90').sort
170
+ end
117
171
 
118
- while (gold = goldSplit.shift) && (test = testSplit.shift)
119
- assert_equal gold, test
172
+ def test_recognizes_external_modules
173
+ file = './externalUse.f90'
174
+ assert_equal [file], @dep.required_source_files(file).sort
120
175
  end
121
- end
122
-
123
- def test_source_file_dependency_hash
124
- @dep.source_file_dependencies('main.F90')
125
- assert_equal( 5, @dep.file_dependencies.size )
126
- expected = {
127
- "./area.f90" => [],
128
- "./grid.f90" => ["./area.f90"],
129
- "../lib/solution.f90" => ["./area.f90"],
130
- "./shapes.f90" => ["./area.f90"],
131
- "main.F90" => ["./grid.f90", "../lib/solution.f90", "./shapes.f90"]
132
- }
133
- assert_equal expected, @dep.file_dependencies
134
- end
135
-
136
- def test_finds_required_source_files
137
- expected = %w[./area.f90 ./shapes.f90 ../lib/solution.f90 ./grid.f90 ./main.F90]
138
- found = @dep.required_source_files('./main.F90')
139
- assert_equal expected.size, found.size
140
- assert_equal './main.F90', found.last
141
- assert_equal './area.f90', found.first
142
- end
143
-
144
- def test_finds_required_source_files_unordered
145
- @dep.dependencies('main.F90')
146
- sources = @dep.source_files
147
- expected = %w[ main.F90 grid.f90 area.f90 solution.f90 shapes.f90 ]
148
- assert_equal expected.size, sources.size
149
- assert_equal 'shapes.f90', sources.last
150
- assert_equal 'main.F90', sources.first
151
- assert_equal expected, sources
152
- end
153
-
154
- def test_can_find_required_source_files_twice
155
- files = %w[./main.F90 ./shapes.f90 ./area.f90 ../lib/solution.f90 ./grid.f90]
156
- @dep.required_source_files('./main.F90')
157
- assert_equal files.sort, @dep.required_source_files('./main.F90').sort
158
- end
159
-
160
- def test_recognizes_external_modules
161
- file = './externalUse.f90'
162
- assert_equal [file], @dep.required_source_files(file).sort
163
- end
164
-
165
- def teardown
166
- Dir.chdir '../..'
167
- FileUtils.rm_rf 'DependenciesFixture'
168
- end
169
176
 
170
177
  end
@@ -8,111 +8,110 @@ require 'ftools'
8
8
 
9
9
  class TestFunit < Test::Unit::TestCase
10
10
 
11
- include Funit
12
- include Funit::Assertions
11
+ include Funit
12
+ include Funit::Assertions
13
13
 
14
- def Xtest_main_driver_compiles
15
- writeTestRunner []
16
- assert File.exists?("TestRunner.f90")
17
- assert system("#{Compiler.new.name} TestRunner.f90")
18
- assert File.exists?("a.out")
19
- end
14
+ def setup
15
+ File.rm_f(*Dir["dummyunit*"])
16
+ File.rm_f(*Dir["unit*"])
17
+ File.rm_f(*Dir["ydsbe*"])
18
+ File.rm_f(*Dir["lmzd*"])
19
+ File.rm_f(*Dir["ldfdl*"])
20
+ File.rm_f(*Dir["ydsbe*"])
21
+ File.rm_f(*Dir["TestRunner*"])
22
+ File.rm_f(*Dir["a.out"])
23
+ end
24
+
25
+ def teardown
26
+ File.rm_f(*Dir["dummyunit*"])
27
+ File.rm_f(*Dir["unit*"])
28
+ File.rm_f(*Dir["ydsbe*"])
29
+ File.rm_f(*Dir["lmzd*"])
30
+ File.rm_f(*Dir["ldfdl*"])
31
+ File.rm_f(*Dir["ydsbe*"])
32
+ File.rm_f(*Dir["TestRunner*"])
33
+ File.rm_f(*Dir["a.out"])
34
+ end
35
+
36
+ def test_main_driver_compiles
37
+ writeTestRunner []
38
+ assert File.exists?("TestRunner.f90")
39
+ assert system("#{Compiler.new.name} TestRunner.f90")
40
+ assert File.exists?("a.out")
41
+ end
20
42
 
21
- def Xtest_is_equal
22
- @suiteName = "dummy"
23
- @testName = "dummy"
24
- @lineNumber = "dummy"
25
- isequal("IsEqual(1.0,m(1,1))")
26
- assert_equal '.not.(1.0==m(1,1))', @condition
27
- end
43
+ def test_is_equal
44
+ @suiteName = "dummy"
45
+ @testName = "dummy"
46
+ @lineNumber = "dummy"
47
+ isequal("IsEqual(1.0,m(1,1))")
48
+ assert_equal '.not.(1.0==m(1,1))', @condition
49
+ end
28
50
 
29
- def Xtest_is_real_equal
30
- @suiteName = "dummy"
31
- @testName = "dummy"
32
- @lineNumber = "dummy"
33
- isrealequal("IsRealEqual(a,b)")
34
- ans = <<EOF
51
+ def test_is_real_equal
52
+ @suiteName = "dummy"
53
+ @testName = "dummy"
54
+ @lineNumber = "dummy"
55
+ isrealequal("IsRealEqual(a,b)")
56
+ ans = <<-EOF
35
57
  .not.(a+2*spacing(real(a)).ge.b &
36
58
  .and.a-2*spacing(real(a)).le.b)
37
- EOF
38
- assert_equal ans.chomp, @condition
39
- assert_equal '"b (",b,") is not",a,"within",2*spacing(real(a))', @message
40
-
41
- isrealequal("IsRealEqual(1.0,m(1,1))")
42
- ans = <<EOF
59
+ EOF
60
+ assert_equal ans.chomp, @condition
61
+ assert_equal '"b (",b,") is not",a,"within",2*spacing(real(a))', @message
62
+ isrealequal("IsRealEqual(1.0,m(1,1))")
63
+ ans = <<-EOF
43
64
  .not.(1.0+2*spacing(real(1.0)).ge.m(1,1) &
44
65
  .and.1.0-2*spacing(real(1.0)).le.m(1,1))
45
- EOF
46
- assert_equal ans.chomp, @condition
47
- end
48
-
49
- def test_handles_dependency
50
- File.open('unit.f90','w') do |f|
51
- f.printf "module unit\n use unita, only : a\nend module unit\n"
52
- end
53
- File.open('unita.f90','w') do |f|
54
- f.printf "module unita\n integer :: a = 5\nend module unita\n"
66
+ EOF
67
+ assert_equal ans.chomp, @condition
55
68
  end
56
- File.open('unit.fun','w') do |f|
57
- f.printf "beginTest a_gets_set\n IsEqual(5, a)\nendTest\n"
58
- end
59
- assert_nothing_raised{run_tests}
60
- end
61
69
 
62
- def test_embedded_dependencies
63
- File.open('unit.f90','w') do |f|
64
- f.printf "module unit\n use unita, only : a\nend module unit\n"
65
- end
66
- File.open('unita.f90','w') do |f|
67
- f.printf "module unita\n use unitb, only : b \n integer :: a = b\nend module unita\n"
68
- end
69
- File.open('unitb.f90','w') do |f|
70
- f.printf "module unitb\n integer,parameter :: b = 5\nend module unitb\n"
70
+ def test_handles_dependency
71
+ File.open('unit.f90','w') do |f|
72
+ f.printf "module unit\n use unita, only : a\nend module unit\n"
73
+ end
74
+ File.open('unita.f90','w') do |f|
75
+ f.printf "module unita\n integer :: a = 5\nend module unita\n"
76
+ end
77
+ File.open('unit.fun','w') do |f|
78
+ f.printf "beginTest a_gets_set\n IsEqual(5, a)\nendTest\n"
79
+ end
80
+ assert_nothing_raised{run_tests}
71
81
  end
72
- File.open('unit.fun','w') do |f|
73
- f.printf "beginTest a_gets_set\n IsEqual(5, a)\nendTest\n"
74
- end
75
- assert_nothing_raised{run_tests}
76
- end
77
-
78
- def test_requested_modules
79
- assert_equal ["asdfga"], requestedModules(["asdfga"])
80
- assert_equal ["asd","fga"], requestedModules(["asd","fga"])
81
- assert requestedModules([]).empty?
82
- modules = %w[ldfdl lmzd]
83
- funits = modules.map{|f| f+'.fun'}.join(' ')
84
- system "touch "+funits
85
- assert_equal modules, requestedModules([])
86
- end
87
82
 
88
- def test_funit_exists_method
89
- moduleName = "ydsbe"
90
- File.rm_f(moduleName+".fun")
91
- assert_equal false, funit_exists?(moduleName)
92
- system "touch "+moduleName+".fun"
93
- assert funit_exists?(moduleName)
83
+ def test_embedded_dependencies
84
+ File.open('unit.f90','w') do |f|
85
+ f.printf "module unit\n use unita, only : a\nend module unit\n"
86
+ end
87
+ File.open('unita.f90','w') do |f|
88
+ f.printf "module unita\n use unitb, only : b \n integer :: a = b\nend module unita\n"
89
+ end
90
+ File.open('unitb.f90','w') do |f|
91
+ f.printf "module unitb\n integer,parameter :: b = 5\nend module unitb\n"
92
+ end
93
+ File.open('unit.fun','w') do |f|
94
+ f.printf "beginTest a_gets_set\n IsEqual(5, a)\nendTest\n"
95
+ end
96
+ assert_nothing_raised{run_tests}
94
97
  end
95
98
 
96
- def setup
97
- File.rm_f(*Dir["dummyunit*"])
98
- File.rm_f(*Dir["unit*"])
99
- File.rm_f(*Dir["ydsbe*"])
100
- File.rm_f(*Dir["lmzd*"])
101
- File.rm_f(*Dir["ldfdl*"])
102
- File.rm_f(*Dir["ydsbe*"])
103
- File.rm_f(*Dir["TestRunner*"])
104
- File.rm_f(*Dir["a.out"])
105
- end
99
+ def test_requested_modules
100
+ assert_equal ["asdfga"], requestedModules(["asdfga"])
101
+ assert_equal ["asd","fga"], requestedModules(["asd","fga"])
102
+ assert requestedModules([]).empty?
103
+ modules = %w[ldfdl lmzd]
104
+ funits = modules.map{|f| f+'.fun'}.join(' ')
105
+ system "touch "+funits
106
+ assert_equal modules, requestedModules([])
107
+ end
106
108
 
107
- def teardown
108
- File.rm_f(*Dir["dummyunit*"])
109
- File.rm_f(*Dir["unit*"])
110
- File.rm_f(*Dir["ydsbe*"])
111
- File.rm_f(*Dir["lmzd*"])
112
- File.rm_f(*Dir["ldfdl*"])
113
- File.rm_f(*Dir["ydsbe*"])
114
- File.rm_f(*Dir["TestRunner*"])
115
- File.rm_f(*Dir["a.out"])
116
- end
109
+ def test_funit_exists_method
110
+ moduleName = "ydsbe"
111
+ File.rm_f(moduleName+".fun")
112
+ assert_equal false, funit_exists?(moduleName)
113
+ system "touch "+moduleName+".fun"
114
+ assert funit_exists?(moduleName)
115
+ end
117
116
 
118
117
  end