Skip to content

Commit

Permalink
Fix source from pipe and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacetown committed Jun 4, 2024
1 parent 4c98e9f commit 5dda5b6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 16 deletions.
15 changes: 9 additions & 6 deletions gcovr/formats/coveralls/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ def _make_source_file(coverage_details: FileCoverage, options) -> Dict[str, Any]
source_file = {}

# Generate md5 hash of file contents
with open(coverage_details.filename, "rb") as file_handle:
contents = file_handle.read()

source_file["source_digest"] = get_md5_hexdigest(contents)
if coverage_details.filename.endswith("<stdin>"):
total_line_count = None
else:
with open(coverage_details.filename, "rb") as file_handle:
contents = file_handle.read()

total_line_count = len(contents.splitlines())
source_file["source_digest"] = get_md5_hexdigest(contents)
total_line_count = len(contents.splitlines())

# Isolate relative file path
relative_file_path = presentable_filename(
Expand Down Expand Up @@ -229,7 +231,8 @@ def _make_source_file(coverage_details: FileCoverage, options) -> Dict[str, Any]
# source_file['coverage'].append(b_hits)

# add trailing empty lines
_extend_with_none(source_file["coverage"], total_line_count)
if total_line_count is not None:
_extend_with_none(source_file["coverage"], total_line_count)

return source_file

Expand Down
12 changes: 7 additions & 5 deletions gcovr/formats/lcov/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ def write_report(covdata: CovData, output_file: str, options: Options) -> None:
# SF:<path to the source file>
fh.write(f"SF:{filename}\n")

# VER:<version ID>
# Generate md5 hash of file contents
with open(filename, "rb") as file_handle:
contents = file_handle.read()
fh.write(f"VER:{get_md5_hexdigest(contents)}\n")
# This filename is generated in the JSON intermediate format
if not filename.endswith("<stdin>"):
# VER:<version ID>
# Generate md5 hash of file contents
with open(filename, "rb") as file_handle:
contents = file_handle.read()
fh.write(f"VER:{get_md5_hexdigest(contents)}\n")

functions = 0
function_hits = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/source_from_pipe/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ run: txt lcov cobertura html sonarqube jacoco coveralls

coverage.json:
./testcase
$(GCOVR) --gcov-keep --verbose --gcov-ignore-errors no_working_dir_found --json-pretty --json coverage.json
$(GCOVR) --gcov-keep --verbose $$(if [ "$${CC_REFERENCE:=$$CC}" != "gcc-14" ] ; then echo "--gcov-ignore-errors no_working_dir_found" ; fi) --json-pretty --json coverage.json

txt: coverage.json
$(GCOVR) -a $< -o coverage.txt
Expand Down
20 changes: 16 additions & 4 deletions tests/source_from_pipe/reference/gcc-14/coverage.lcov
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
TN:GCOVR report
SF:tests/source_from_pipe/<stdin>
FN:3,main
FNDA:1,main
FNF:1
FNH:1
BRF:0
BRH:0
DA:3,1,d41d8cd98f00b204e9800998ecf8427e
DA:5,1,d41d8cd98f00b204e9800998ecf8427e
LH:2
LF:2
end_of_record
SF:tests/source_from_pipe/code.cpp
VER:f6c5b94686e43537860a1364ddf21730
FN:3,foo1(int)
Expand All @@ -7,10 +19,10 @@ FN:12,foo2(int)
FNDA:1,foo2(int)
FNF:2
FNH:2
BRDA:4,2,0,-
BRDA:4,2,1,1
BRDA:13,2,0,1
BRDA:13,2,1,-
BRDA:4,1,0,-
BRDA:4,1,1,1
BRDA:13,1,0,1
BRDA:13,1,1,-
BRF:4
BRH:2
DA:3,1,d202d6f6b151ca991538c418a08707bd
Expand Down
43 changes: 43 additions & 0 deletions tests/source_from_pipe/reference/gcc-14/coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"run_at": "",
"service_job_id": "id",
"service_name": "gcovr-test-suite",
"service_number": "number",
"service_pull_request": "pr",
"source_files": [
{
"coverage": [
null,
null,
1,
null,
1
],
"name": "<stdin>"
},
{
"coverage": [
null,
null,
1,
1,
0,
null,
1,
null,
null,
null,
null,
1,
1,
1,
null,
0,
null,
null
],
"name": "code.cpp",
"source_digest": "f6c5b94686e43537860a1364ddf21730"
}
]
}

0 comments on commit 5dda5b6

Please sign in to comment.