From 5093b79c57c7282e6e5ee9958ad1261d48b0f0b5 Mon Sep 17 00:00:00 2001 From: Giliola Sartori Date: Thu, 6 Oct 2022 11:04:51 +0200 Subject: [PATCH 1/2] not covered changed lines --- src/PatchCoverage.php | 4 ++++ src/cli/PatchCoverageCommand.php | 3 ++- ...s-with-only-not-covered-changed-lines.phpt | 20 ++++++++++++++++++ .../example2/coverage/testGreetsWorld2.cov | Bin 0 -> 4495 bytes tests/fixture/example2/patch2 | 13 ++++++++++++ tests/fixture/example2/phpunit.xml | 18 ++++++++++++++++ tests/fixture/example2/src/Greeter2.php | 13 ++++++++++++ tests/fixture/example2/src/autoload.php | 4 ++++ tests/fixture/example2/tests/Greeter2Test.php | 17 +++++++++++++++ 9 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt create mode 100644 tests/fixture/example2/coverage/testGreetsWorld2.cov create mode 100644 tests/fixture/example2/patch2 create mode 100644 tests/fixture/example2/phpunit.xml create mode 100644 tests/fixture/example2/src/Greeter2.php create mode 100644 tests/fixture/example2/src/autoload.php create mode 100644 tests/fixture/example2/tests/Greeter2Test.php diff --git a/src/PatchCoverage.php b/src/PatchCoverage.php index 43181c5..a10be0c 100644 --- a/src/PatchCoverage.php +++ b/src/PatchCoverage.php @@ -25,6 +25,7 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre $result = [ 'numChangedLinesThatAreExecutable' => 0, 'numChangedLinesThatWereExecuted' => 0, + 'numChangedLinesNotCovered' => 0, 'changedLinesThatWereNotExecuted' => [], ]; @@ -77,6 +78,9 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre $result['numChangedLinesThatWereExecuted']++; } } + if (!isset($coverage[$key][$line])) { + $result['numChangedLinesNotCovered']++; + } } } diff --git a/src/cli/PatchCoverageCommand.php b/src/cli/PatchCoverageCommand.php index 5fcaf8e..e016289 100644 --- a/src/cli/PatchCoverageCommand.php +++ b/src/cli/PatchCoverageCommand.php @@ -44,7 +44,8 @@ public function run(Arguments $arguments): int ); if ($patchCoverage['numChangedLinesThatWereExecuted'] === 0 && - $patchCoverage['numChangedLinesThatAreExecutable'] === 0) { + $patchCoverage['numChangedLinesThatAreExecutable'] === 0 && + $patchCoverage['numChangedLinesNotCovered'] === 0) { print 'Unable to detect executable lines that were changed.' . PHP_EOL; if ($pathPrefix === '') { diff --git a/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt new file mode 100644 index 0000000..6e430cc --- /dev/null +++ b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt @@ -0,0 +1,20 @@ +--TEST-- +phpcov patch-coverage --path-prefix /path/prefix ../../fixture/example2/coverage/testGreetsWorld2.cov ../../fixture/example2/patch2 +--INI-- +xdebug.overload_var_dump=0 +--FILE-- +run($_SERVER['argv'])); +--EXPECTF-- +phpcov %s by Sebastian Bergmann. + +0 / 0 changed executable lines covered () +int(0) diff --git a/tests/fixture/example2/coverage/testGreetsWorld2.cov b/tests/fixture/example2/coverage/testGreetsWorld2.cov new file mode 100644 index 0000000000000000000000000000000000000000..67ebef427a9a1353a50f48980072a067f1126a59 GIT binary patch literal 4495 zcmcIo(M}sV6wNbVQO!%+mxf6~00(K6CeV$_5(IQvts)`EV}h57C$c>hTJi6Du4g8Y zC9|1C=|cr^?Bjc{&pG$fqu*wCvmGN{YV^BNs;xAN$LfdtaCCI^{`jnaGd#KJ4gWm8 z=zclAxjeoYbWaC=cdrJ+v-dkg)@rigQjWQGitEqPOr~7xQ7?&PFL{uLPvpXffQ2pg z)3Uvg1+_KK)gq$+7j%aH=!%nlzj^dmB**EbnSBaagD&20t-d%vp8cqaB#xzUpAFaI zuB)SS?(T}*g3g%jb}Vb}u8SH;2hhIc5!H%t!p`#sb-7is%j(kHU-=Rz+2*VgtqPUM z4%Bdov_Xew2it8H)ZKJO|2|3iH9Y+Ny7|XHb?`_e4|ON4v-Ml`2u8`eeB{$vEE{!e zME#4ANZT|%VQZE$O1Ci@PhAoxJbFQ+0#ct#CJZo|^rBj8+zUeD#RE{9fH#AzhIX(&J%8400*1B&HamT%jm$G|)@A;fcuewQ}&gWKMLF%O# zwOHwSi`u&Uy_+Z&hMBJ@-z4@LEXZwfRM_IkyXB}bk1Kd5W3=X1>~&&dRQj2$q)O*1 zPxm$#P*Gh}O%U%s|m-N!2 z>klbAI_JjXvB~1HH2|@Ls>9W4u$p*j9b0Y6d5>?Pyl-@f@no(-dW<&Z0}g3E^&C22 zK_OBi5vExGm7Q@RqqBTd1!T)`JAwL>1l53zEenUf!(MRJxKo%F(RB}NV6)Uwu@W}3 zrKxmxN#xt3uUQDx35{F1h2$C0a<;XI`M(>pOVKkR5#v**0AHX!d}QyeBenZF;JXK9 z)mX*KJ<$r}HA}~_63gO0d>elQOW>~%5GNdyyw00a1x{C>k~3Vnm#S=QynFG^3WGw0 zFbjA7m63wMt4yLoq|`R;@HTV$Ef3APbB8e9g=;_yVtI%RL^7SiV2S_*duIi7W%cmDT3RCYdg{srP~JYE0* literal 0 HcmV?d00001 diff --git a/tests/fixture/example2/patch2 b/tests/fixture/example2/patch2 new file mode 100644 index 0000000..97d73c2 --- /dev/null +++ b/tests/fixture/example2/patch2 @@ -0,0 +1,13 @@ +diff --git a/tests/fixture/example2/src/Greeter2.php b/tests/fixture/example2/src/Greeter2.php +index 36e0a2e..ab7b878 100644 +--- a/tests/fixture/example2/src/Greeter2.php ++++ b/tests/fixture/example2/src/Greeter2.php +@@ -4,7 +4,7 @@ + + final class Greeter2 + { +- public const GREETING='Hello world!'; ++ public const GREETING='Hello wonderful world!'; + + public function greetWorld(): string + { diff --git a/tests/fixture/example2/phpunit.xml b/tests/fixture/example2/phpunit.xml new file mode 100644 index 0000000..c1f86c8 --- /dev/null +++ b/tests/fixture/example2/phpunit.xml @@ -0,0 +1,18 @@ + + + + + tests + + + + + + src + + + diff --git a/tests/fixture/example2/src/Greeter2.php b/tests/fixture/example2/src/Greeter2.php new file mode 100644 index 0000000..36e0a2e --- /dev/null +++ b/tests/fixture/example2/src/Greeter2.php @@ -0,0 +1,13 @@ +assertSame(Greeter2::GREETING, (new Greeter2())->greetWorld()); + } +} From b21ff095731236c0589ab5b5b159f2f120f1fbc5 Mon Sep 17 00:00:00 2001 From: Giliola Sartori Date: Wed, 12 Oct 2022 09:40:50 +0200 Subject: [PATCH 2/2] fix --- src/PatchCoverage.php | 2 +- .../no-errors-with-only-not-covered-changed-lines.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PatchCoverage.php b/src/PatchCoverage.php index a10be0c..8789c33 100644 --- a/src/PatchCoverage.php +++ b/src/PatchCoverage.php @@ -78,7 +78,7 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre $result['numChangedLinesThatWereExecuted']++; } } - if (!isset($coverage[$key][$line])) { + if (isset($coverage[$key]) && !isset($coverage[$key][$line])) { $result['numChangedLinesNotCovered']++; } } diff --git a/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt index 6e430cc..9a75c72 100644 --- a/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt +++ b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt @@ -8,7 +8,7 @@ require __DIR__ . '/../../../vendor/autoload.php'; $_SERVER['argv'][1] = 'patch-coverage'; $_SERVER['argv'][2] = '--path-prefix'; -$_SERVER['argv'][3] = '../../phpcov'; +$_SERVER['argv'][3] = '/tmp/tmp.eeK19HW3Mj/phpcov/'; $_SERVER['argv'][4] = __DIR__ . '/../../fixture/example2/coverage/testGreetsWorld2.cov'; $_SERVER['argv'][5] = __DIR__ . '/../../fixture/example2/patch2';