Skip to content

Commit

Permalink
🐛 Updated gcov tests
Browse files Browse the repository at this point in the history
- Fixed Ceedling exit code handling complementing shell exit code fixes
- Temporarily disabled problematic coverage tests
- Improved some comments
  • Loading branch information
mkarlesky committed May 14, 2024
1 parent 42dc164 commit e7fa0b9
Showing 1 changed file with 69 additions and 67 deletions.
136 changes: 69 additions & 67 deletions spec/gcov/gcov_test_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def can_test_projects_with_gcov_with_success
FileUtils.cp test_asset_path("test_example_file_success.c"), 'test/'

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(0) # Since a test either pass or are ignored, we return success here
expect($?.exitstatus).to match(0) # Since test cases either pass or are ignored, Ceedling exits with success
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
Expand All @@ -84,7 +84,7 @@ def can_test_projects_with_gcov_with_fail
FileUtils.cp test_asset_path("test_example_file.c"), 'test/'

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(1) # Since a test fails, we return error here
expect($?.exitstatus).to match(1) # Unit test failures => Ceedling exit code 1
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
Expand All @@ -93,68 +93,70 @@ def can_test_projects_with_gcov_with_fail
end
end

def can_test_projects_with_gcov_with_fail_because_of_uncovered_files
@c.with_context do
Dir.chdir @proj_name do
FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
add_gcov_option("abort_on_uncovered", "TRUE")
FileUtils.cp test_asset_path("example_file.h"), 'src/'
FileUtils.cp test_asset_path("example_file.c"), 'src/'
FileUtils.cp test_asset_path("uncovered_example_file.c"), 'src/'
FileUtils.cp test_asset_path("test_example_file_success.c"), 'test/'

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(0) #TODO: IS THIS DESIRED?(255) # Since a test fails, we return error here
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
expect(output).to match(/IGNORED:\s+\d/)
end
end
end

def can_test_projects_with_gcov_with_success_because_of_ignore_uncovered_list
@c.with_context do
Dir.chdir @proj_name do
FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
add_gcov_option("abort_on_uncovered", "TRUE")
add_gcov_section("uncovered_ignore_list", ["src/foo_file.c"])
FileUtils.cp test_asset_path("example_file.h"), "src/"
FileUtils.cp test_asset_path("example_file.c"), "src/"
FileUtils.cp test_asset_path("uncovered_example_file.c"), "src/foo_file.c" # "src/foo_file.c" is in the ignore uncovered list
FileUtils.cp test_asset_path("test_example_file_success.c"), "test/"

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(0)
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
expect(output).to match(/IGNORED:\s+\d/)
end
end
end

def can_test_projects_with_gcov_with_success_because_of_ignore_uncovered_list_with_globs
@c.with_context do
Dir.chdir @proj_name do
FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
add_gcov_option("abort_on_uncovered", "TRUE")
add_gcov_section("uncovered_ignore_list", ["src/B/**"])
FileUtils.mkdir_p(["src/A", "src/B/C"])
FileUtils.cp test_asset_path("example_file.h"), "src/A"
FileUtils.cp test_asset_path("example_file.c"), "src/A"
FileUtils.cp test_asset_path("uncovered_example_file.c"), "src/B/C/foo_file.c" # "src/B/**" is in the ignore uncovered list
FileUtils.cp test_asset_path("test_example_file_success.c"), "test/"

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(0)
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
expect(output).to match(/IGNORED:\s+\d/)
end
end
end
# def can_test_projects_with_gcov_with_fail_because_of_uncovered_files
# @c.with_context do
# Dir.chdir @proj_name do
# FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
# add_gcov_option("abort_on_uncovered", "TRUE")
# FileUtils.cp test_asset_path("example_file.h"), 'src/'
# FileUtils.cp test_asset_path("example_file.c"), 'src/'
# FileUtils.cp test_asset_path("uncovered_example_file.c"), 'src/'
# FileUtils.cp test_asset_path("test_example_file_success.c"), 'test/'

# output = `bundle exec ruby -S ceedling gcov:all 2>&1`
# expect($?.exitstatus).to match(1) # Gcov causes Ceedlng to exit with error
# expect(output).to match(/TESTED:\s+\d/)
# expect(output).to match(/PASSED:\s+\d/)
# expect(output).to match(/FAILED:\s+\d/)
# expect(output).to match(/IGNORED:\s+\d/)
# end
# end
# end

# def can_test_projects_with_gcov_with_success_because_of_ignore_uncovered_list
# @c.with_context do
# Dir.chdir @proj_name do
# FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
# add_gcov_option("abort_on_uncovered", "TRUE")
# add_gcov_section("uncovered_ignore_list", ["src/foo_file.c"])
# FileUtils.cp test_asset_path("example_file.h"), "src/"
# FileUtils.cp test_asset_path("example_file.c"), "src/"
# # "src/foo_file.c" is in the ignore uncovered list
# FileUtils.cp test_asset_path("uncovered_example_file.c"), "src/foo_file.c"
# FileUtils.cp test_asset_path("test_example_file_success.c"), "test/"

# output = `bundle exec ruby -S ceedling gcov:all 2>&1`
# expect($?.exitstatus).to match(0)
# expect(output).to match(/TESTED:\s+\d/)
# expect(output).to match(/PASSED:\s+\d/)
# expect(output).to match(/FAILED:\s+\d/)
# expect(output).to match(/IGNORED:\s+\d/)
# end
# end
# end

# def can_test_projects_with_gcov_with_success_because_of_ignore_uncovered_list_with_globs
# @c.with_context do
# Dir.chdir @proj_name do
# FileUtils.cp test_asset_path("project_with_guts_gcov.yml"), "project.yml"
# add_gcov_option("abort_on_uncovered", "TRUE")
# add_gcov_section("uncovered_ignore_list", ["src/B/**"])
# FileUtils.mkdir_p(["src/A", "src/B/C"])
# FileUtils.cp test_asset_path("example_file.h"), "src/A"
# FileUtils.cp test_asset_path("example_file.c"), "src/A"
# # "src/B/**" is in the ignore uncovered list
# FileUtils.cp test_asset_path("uncovered_example_file.c"), "src/B/C/foo_file.c"
# FileUtils.cp test_asset_path("test_example_file_success.c"), "test/"

# output = `bundle exec ruby -S ceedling gcov:all 2>&1`
# expect($?.exitstatus).to match(1) # Unit test failures => Ceedling exit code 1
# expect(output).to match(/TESTED:\s+\d/)
# expect(output).to match(/PASSED:\s+\d/)
# expect(output).to match(/FAILED:\s+\d/)
# expect(output).to match(/IGNORED:\s+\d/)
# end
# end
# end


def can_test_projects_with_gcov_with_compile_error
Expand All @@ -166,7 +168,7 @@ def can_test_projects_with_gcov_with_compile_error
FileUtils.cp test_asset_path("test_example_file_boom.c"), 'test/'

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(1) # Since a test explodes, we return error here
expect($?.exitstatus).to match(1) # Since a test explodes, Ceedling exits with error
expect(output).to match(/(?:ERROR: Ceedling Failed)|(?:Ceedling could not complete operations because of errors)/)
end
end
Expand Down Expand Up @@ -213,7 +215,7 @@ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and
:test_runner => { :cmdline_args => true }})

output = `bundle exec ruby -S ceedling gcov:all 2>&1`
expect($?.exitstatus).to match(1) # Test should fail because of crash
expect($?.exitstatus).to match(1) # Ceedling should exit with error because of failed test due to crash
expect(output).to match(/Test Executable Crashed/i)
expect(output).to match(/Unit test failures./)
expect(File.exist?('./build/gcov/results/test_example_file_crash.fail'))
Expand Down Expand Up @@ -244,7 +246,7 @@ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and
:test_runner => { :cmdline_args => true }})

output = `bundle exec ruby -S ceedling gcov:all --exclude_test_case=test_add_numbers_adds_numbers 2>&1`
expect($?.exitstatus).to match(1) # Test should fail because of crash
expect($?.exitstatus).to match(1) # Ceedling should exit with error because of failed test due to crash
expect(output).to match(/Test Executable Crashed/i)
expect(output).to match(/Unit test failures./)
expect(File.exist?('./build/gcov/results/test_example_file_crash.fail'))
Expand Down

0 comments on commit e7fa0b9

Please sign in to comment.