Skip to content

Commit

Permalink
Merge pull request #432 from perillo/improve-tests-code-even-more
Browse files Browse the repository at this point in the history
Improve tests code even more
  • Loading branch information
SimonKagstrom authored Apr 1, 2024
2 parents c3b0b2a + 9794dd0 commit bc0a626
Show file tree
Hide file tree
Showing 11 changed files with 697 additions and 910 deletions.
169 changes: 66 additions & 103 deletions tests/tools/accumulate.py
Original file line number Diff line number Diff line change
@@ -1,199 +1,162 @@
import parse_cobertura
import cobertura
import testbase


class accumulate_data(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov "
+ testbase.sources
+ "/tests/python/main"
self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main"
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1
assert parse_cobertura.hitsPerLine(dom, "main", 19) == 0
assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 16) == 1
assert cobertura.hitsPerLine(dom, "main", 19) == 0
assert cobertura.hitsPerLine(dom, "main", 14) == 1

rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov "
+ testbase.sources
+ "/tests/python/main 5"
self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1
assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1
assert parse_cobertura.hitsPerLine(dom, "main", 14) == 2
dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 16) == 1
assert cobertura.hitsPerLine(dom, "main", 19) == 1
assert cobertura.hitsPerLine(dom, "main", 14) == 2


class dont_accumulate_data_with_clean(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov "
+ testbase.sources
+ "/tests/python/main"
self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main"
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1
assert parse_cobertura.hitsPerLine(dom, "main", 19) == 0
assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 16) == 1
assert cobertura.hitsPerLine(dom, "main", 19) == 0
assert cobertura.hitsPerLine(dom, "main", 14) == 1

rv, o = self.do(
testbase.kcov
self.kcov
+ " --clean "
+ testbase.outbase
+ self.outbase
+ "/kcov "
+ testbase.sources
+ self.sources
+ "/tests/python/main 5"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 16) == 0
assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1
assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 16) == 0
assert cobertura.hitsPerLine(dom, "main", 19) == 1
assert cobertura.hitsPerLine(dom, "main", 14) == 1


class merge_basic(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov "
+ testbase.sources
+ "/tests/python/main 5"
self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
)
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov "
+ testbase.sources
+ "/tests/bash/shell-main"
self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main"
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 10) == 1
assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1


class merge_multiple_output_directories(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov/first "
+ testbase.sources
+ "/tests/python/main 5"
self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " "
+ testbase.outbase
+ self.outbase
+ "/kcov/second "
+ testbase.sources
+ self.sources
+ "/tests/bash/shell-main"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " --merge "
+ testbase.outbase
+ self.outbase
+ "/kcov/merged "
+ testbase.outbase
+ self.outbase
+ "/kcov/first "
+ testbase.outbase
+ self.outbase
+ "/kcov/second"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/merged/kcov-merged/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/merged/kcov-merged/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 10) == 1
assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1


class merge_merged_output(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
+ " "
+ testbase.outbase
+ "/kcov/first "
+ testbase.sources
+ "/tests/python/main 5"
self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " "
+ testbase.outbase
+ self.outbase
+ "/kcov/second "
+ testbase.sources
+ self.sources
+ "/tests/bash/shell-main"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " "
+ testbase.outbase
+ self.outbase
+ "/kcov/third "
+ testbase.sources
+ self.sources
+ "/tests/bash/dollar-var-replacements.sh"
)

rv, o = self.do(
testbase.kcov
self.kcov
+ " --merge "
+ testbase.outbase
+ self.outbase
+ "/kcov/merged "
+ testbase.outbase
+ self.outbase
+ "/kcov/first "
+ testbase.outbase
+ self.outbase
+ "/kcov/second"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " --merge "
+ testbase.outbase
+ self.outbase
+ "/kcov/merged2 "
+ testbase.outbase
+ self.outbase
+ "/kcov/merged "
+ testbase.outbase
+ self.outbase
+ "/kcov/third"
)
dom = parse_cobertura.parseFile(
testbase.outbase + "/kcov/merged2/kcov-merged/cobertura.xml"
)
assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1
assert parse_cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1
dom = cobertura.parseFile(self.outbase + "/kcov/merged2/kcov-merged/cobertura.xml")
assert cobertura.hitsPerLine(dom, "main", 10) == 1
assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1
assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1


class merge_coveralls(testbase.KcovTestCase):
def runTest(self):
rv, o = self.do(
testbase.kcov
self.kcov
+ " --coveralls-id=dry-run "
+ testbase.outbase
+ self.outbase
+ "/kcov/ "
+ testbase.sources
+ self.sources
+ "/tests/python/main 5"
)
rv, o = self.do(
testbase.kcov
self.kcov
+ " --coveralls-id=dry-run "
+ testbase.outbase
+ self.outbase
+ "/kcov/ "
+ testbase.sources
+ self.sources
+ "/tests/bash/shell-main"
)

rv, o = self.doShell(f"grep second.py {(testbase.outbase)}/kcov/main/coveralls.out")
rv, o = self.doShell(f"grep second.py {(self.outbase)}/kcov/main/coveralls.out")
assert rv == 0
rv, o = self.doShell(f"grep shell-main {(testbase.outbase)}/kcov/shell-main/coveralls.out")
rv, o = self.doShell(f"grep shell-main {(self.outbase)}/kcov/shell-main/coveralls.out")
assert rv == 0
Loading

0 comments on commit bc0a626

Please sign in to comment.