-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "../../spec_helper" | ||
|
||
Spectator.describe CoverageReporter::GcovParser do | ||
subject { described_class.new(base_path) } | ||
|
||
let(base_path) { nil } | ||
|
||
describe "#parse" do | ||
let(filename) { "spec/fixtures/gcov/main.c.gcov" } | ||
|
||
it "parses gcov" do | ||
result = subject.parse(filename) | ||
|
||
expect(result[0].to_h).to eq({ | ||
:name => "main.c", | ||
:coverage => [nil, nil, 2, nil, 2, 1, 1, 1, nil, 0, nil, 2, nil, nil, 1, nil, 1, 1, 1, nil], | ||
}) | ||
end | ||
|
||
context "with base_path" do | ||
let(base_path) { "spec/fixtures/gcov" } | ||
|
||
it "parses gcov with source digest" do | ||
result = subject.parse(filename) | ||
|
||
expect(result[0].to_h).to eq({ | ||
:name => "spec/fixtures/gcov/main.c", | ||
:coverage => [nil, nil, 2, nil, 2, 1, 1, 1, nil, 0, nil, 2, nil, nil, 1, nil, 1, 1, 1, nil], | ||
:source_digest => "da803fdb1b06abe64c3b806d861a5baa", | ||
}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
main | ||
main.o | ||
main.gcda | ||
main.gcno |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
coverage: | ||
gcc -fPIC -fprofile-arcs -ftest-coverage -c -Wall -Werror main.c | ||
gcc -fPIC -fprofile-arcs -ftest-coverage -o main main.o | ||
./main | ||
gcov main.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <stdio.h> | ||
|
||
void numbers(int num) | ||
{ | ||
if (num == 1) { | ||
printf("Number is 1\n"); | ||
} else if (num == 2){ | ||
printf("Number is 2\n"); | ||
} else { | ||
printf("Number is %d\n", num); | ||
} | ||
} | ||
|
||
|
||
int main(void) | ||
{ | ||
numbers(1); | ||
numbers(2); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-: 0:Source:main.c | ||
-: 0:Graph:main.gcno | ||
-: 0:Data:main.gcda | ||
-: 0:Runs:1 | ||
-: 1:#include <stdio.h> | ||
-: 2: | ||
2: 3:void numbers(int num) | ||
-: 4:{ | ||
2: 5: if (num == 1) { | ||
1: 6: printf("Number is 1\n"); | ||
1: 7: } else if (num == 2){ | ||
1: 8: printf("Number is 2\n"); | ||
-: 9: } else { | ||
#####: 10: printf("Number is %d\n", num); | ||
-: 11: } | ||
2: 12:} | ||
-: 13: | ||
-: 14: | ||
1: 15:int main(void) | ||
-: 16:{ | ||
1: 17: numbers(1); | ||
1: 18: numbers(2); | ||
1: 19: return 0; | ||
-: 20:} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require "./base_parser" | ||
require "digest" | ||
|
||
module CoverageReporter | ||
class GcovParser < BaseParser | ||
# Use *base_path* to join with paths found in reports. | ||
def initialize(@base_path : String?) | ||
end | ||
|
||
def globs : Array(String) | ||
[ | ||
"*.gcov", | ||
"**/*/*.gcov", | ||
] | ||
end | ||
|
||
def matches?(filename : String) : Bool | ||
filename.ends_with?(".gcov") | ||
end | ||
|
||
def parse(filename : String) : Array(FileReport) | ||
base_path = @base_path | ||
coverage = {} of Int64 => Int64? | ||
name : String? = nil | ||
source_digest : String? = nil | ||
File.each_line(filename, chomp: true) do |line| | ||
match = /^\s*([0-9]+|-|#####):\s*([0-9]+):(.*)/.match(line).try(&.to_a) | ||
next if !match || !match.try(&.size) == 4 | ||
|
||
count, number, text = match[1..3] | ||
next unless number && text && count | ||
|
||
number = number.to_i64 | ||
|
||
if number == 0 | ||
match = /([^:]+):(.*)$/.match(text).try(&.to_a) | ||
next if !match || match.try(&.size) < 2 | ||
|
||
key, val = match[1..2] | ||
if key == "Source" && val | ||
val = base_path ? File.join(base_path, val) : val | ||
name = val.sub(Dir.current, "") | ||
source_digest = BaseParser.file_digest(val) | ||
end | ||
else | ||
coverage[number - 1] = case count.strip | ||
when "-" | ||
nil | ||
when "#####" | ||
if text.strip == "}" | ||
nil | ||
else | ||
0.to_i64 | ||
end | ||
else | ||
count.to_i64 | ||
end | ||
end | ||
end | ||
|
||
return [] of FileReport unless name | ||
|
||
[ | ||
FileReport.new( | ||
name: name, | ||
coverage: coverage.keys.sort!.map { |i| coverage[i]? }, | ||
source_digest: source_digest, | ||
), | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters