From dc6eddd94861dae67cb90badd9e9c3748b87ed8d Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 4 Apr 2012 10:00:35 -0400 Subject: [PATCH] Added test coverage reporting to the rakefile --- rakefile.rb | 37 ++++++++++++++++++++++++++++++++++++- tests/test_dllexer.cpp | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/rakefile.rb b/rakefile.rb index c7d59e2..cb67e43 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -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 diff --git a/tests/test_dllexer.cpp b/tests/test_dllexer.cpp index 1c92c8d..1fcb957 100644 --- a/tests/test_dllexer.cpp +++ b/tests/test_dllexer.cpp @@ -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" -- 2.52.0