Skip to content

Commit

Permalink
added example input file
Browse files Browse the repository at this point in the history
added implementation to generate output files for example input
  • Loading branch information
friedemannsommer committed Sep 10, 2023
1 parent 6155d49 commit 8fb425a
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 4 deletions.
5 changes: 3 additions & 2 deletions example/lcov.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TN:
TN:example
# source: https://github.com/linux-test-project/lcov/blob/07a1127c2b4390abf4a516e9763fb28a956a9ce4/tests/lcov/merge/a.info#L1-L38
SF:a.cpp
DA:1,1
#common line: my count is zero and yours is nonzero
Expand Down Expand Up @@ -35,4 +36,4 @@ BRDA:11,0,1,0

BRF:5
BRH:4
end_of_record
end_of_record
335 changes: 335 additions & 0 deletions example/nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
[
{
"done": false,
"incomplete": false,
"value": [
"example"
],
"variant": 14
},
{
"done": false,
"incomplete": false,
"value": [
" source: https://github.com/linux-test-project/lcov/blob/07a1127c2b4390abf4a516e9763fb28a956a9ce4/tests/lcov/merge/a.info#L1-L38"
],
"variant": 4
},
{
"done": false,
"incomplete": false,
"value": [
"a.cpp"
],
"variant": 6
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"1"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"common line: my count is zero and yours is nonzero"
],
"variant": 4
},
{
"done": false,
"incomplete": false,
"value": [
"2",
"0"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"3",
"0"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"4",
"1"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"10",
"0"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"11",
"0"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"12",
"0"
],
"variant": 13
},
{
"done": false,
"incomplete": false,
"value": [
"7"
],
"variant": 12
},
{
"done": false,
"incomplete": false,
"value": [
"2"
],
"variant": 11
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"2",
"fcn"
],
"variant": 10
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"2",
"alias"
],
"variant": 10
},
{
"done": false,
"incomplete": false,
"value": [
"3",
"3",
"noCommonAlias"
],
"variant": 10
},
{
"done": false,
"incomplete": false,
"value": [
"11",
"11",
"onlyA"
],
"variant": 10
},
{
"done": false,
"incomplete": false,
"value": [
"4"
],
"variant": 9
},
{
"done": false,
"incomplete": false,
"value": [
"3"
],
"variant": 8
},
{
"done": false,
"incomplete": false,
"value": [
" my count is zero yours is nonzero"
],
"variant": 4
},
{
"done": false,
"incomplete": false,
"value": [
"0",
"fcn"
],
"variant": 7
},
{
"done": false,
"incomplete": false,
"value": [
"2",
"alias"
],
"variant": 7
},
{
"done": false,
"incomplete": false,
"value": [
"0",
"onlyA"
],
"variant": 7
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"noCommonAlias"
],
"variant": 7
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"1",
"0",
"1"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"1",
"1",
"1"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"1",
"2",
"-"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"2",
"0",
"1"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
" common branch expr count zero in my",
" nonzero in you"
],
"variant": 4
},
{
"done": false,
"incomplete": false,
"value": [
"1",
"2",
"1",
"0"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
" branch in A only"
],
"variant": 4
},
{
"done": false,
"incomplete": false,
"value": [
"11",
"0",
"0",
"0"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
"11",
"0",
"1",
"0"
],
"variant": 3
},
{
"done": false,
"incomplete": false,
"value": [
"5"
],
"variant": 2
},
{
"done": false,
"incomplete": false,
"value": [
"4"
],
"variant": 1
},
{
"done": false,
"incomplete": false,
"value": null,
"variant": 5
},
{
"done": true,
"incomplete": false,
"value": null,
"variant": 0
}
]
2 changes: 1 addition & 1 deletion example/parsed.json → example/sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"hit": 2,
"instrumented": 7
},
"name": "",
"name": "example",
"path": "a.cpp"
}
]
2 changes: 1 addition & 1 deletion src/promise/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function transformSynchronous(results: ParseResult[]): SectionSummary[] {
const entry = transformResult(parseResult)

if (entry.variant !== Variant.None) {
sectionIndex = updateResults(sectionIndex, transformResult(parseResult), functionMap, result)
sectionIndex = updateResults(sectionIndex, entry, functionMap, result)
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/tests/example/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync, writeFileSync } from 'node:fs'

import { defaultFieldNames } from '../../constants.js'
import { LcovParser } from '../../parser.js'
import lcovParser from '../../promise/index.js'

const exampleDirectory = new URL('../../../example/', import.meta.url)
const lcovBuffer = readFileSync(new URL('./lcov.info', exampleDirectory))
const sections = await lcovParser({ from: lcovBuffer })
const parser = new LcovParser(defaultFieldNames)

parser.write(lcovBuffer)

const parsedNodes = parser.flush()

writeFileSync(new URL('./sections.json', exampleDirectory), JSON.stringify(sections, undefined, 2))
writeFileSync(new URL('./nodes.json', exampleDirectory), JSON.stringify(parsedNodes, undefined, 2))

0 comments on commit 8fb425a

Please sign in to comment.