]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Added test coverage reporting to the rakefile
authorMike D. Lowis <mike@mdlowis.com>
Wed, 4 Apr 2012 14:00:35 +0000 (10:00 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Wed, 4 Apr 2012 14:00:35 +0000 (10:00 -0400)
rakefile.rb
tests/test_dllexer.cpp

index c7d59e21e5b6e020d74bf4499f9283690092d220..cb67e439f84c5908c5800310213b544ddeceb656 100644 (file)
@@ -13,6 +13,7 @@ CLOBBER.include('./deps/parse-utils/build/static')
 CLOBBER.include('./deps/parse-utils/build/shared')
 CLOBBER.include('./tools/UnitTest++/*UnitTest++*')
 CLOBBER.include('./tools/UnitTest++/src/**/*.o')
+CLOBBER.include('./tests/gcov')
 
 #------------------------------------------------------------------------------
 # Configuration Objects
@@ -58,7 +59,12 @@ DLangDebug.setup_default_rake_tasks()
 DLangTests = Binary.new({
     :name => 'test_runner',
     :output_dir => 'build/test',
-    :compiler_options => [ '-c', '-Wall', '-Werror', '-o' ],
+    :linker_options => [ '-fprofile-arcs', '-o' ],
+    :compiler_options => [
+        '-c', '-Wall', '-Werror',
+        '-fprofile-arcs', '-ftest-coverage',
+        '-O0', '-o'
+    ],
     :static_libs => [
         'tools/UnitTest++/libUnitTest++.a',
         './deps/parse-utils/build/static/bin/libparse-utils.a'
@@ -114,3 +120,32 @@ task :unit_test_pp do
     sh 'make all'
     Dir.chdir(PROJECT_ROOT)
 end
+
+desc 'Generate and display the test coverage statistics for each test file'
+task :coverage do #=> [ :test ] do
+    out_dir = 'build/test/gcov'
+    tests = FileList['tests/**/test_*.cpp']
+
+    # Create the output directory if it doesnt already exist
+    if not File.exist?( out_dir ) then
+        Dir.mkdir( out_dir )
+    end
+
+    # For each test file
+    tests.each { |test|
+        # Find the source file basename, object file location, and gcov output
+        source = File.basename( test ).gsub( 'test_', '' )
+        obj = 'build/obj/' + source.ext('o')
+        gcov = source + '.gcov'
+
+        # Generate the coverage info and display only the summary for our
+        # source file
+        sh "gcov -o build/test/obj #{obj} | grep -A1 #{source}"
+
+        # Move the coverage to our output folder
+        FileUtils.mv( gcov, out_dir )
+
+        # Delete the unwanted coverage files
+        FileList['*.gcov'].each { |f| File.delete(f) }
+    }
+end
index 1c92c8dd4ed7f9a1473ea97af06f1c1045be7dca..1fcb957b669253dba742ad2c796a40c968ea9dfe 100644 (file)
@@ -131,7 +131,7 @@ namespace {
     TEST(Recognize_Valid_Symbols)
     {
         std::string input(
-            // Make Sure we recognize all valid characters for an ID
+            // Make Sure we recognize all valid characters for a symbol
             "$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\n"
             "$ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_\n"
             "$a_123\n"