git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions
@ 2020-11-14 21:18 Javier Spagnoletti via GitGitGadget
  2020-11-14 23:46 ` Johannes Sixt
  2020-11-16 22:21 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Javier Spagnoletti via GitGitGadget @ 2020-11-14 21:18 UTC (permalink / raw)
  To: git; +Cc: Javier Spagnoletti, Javier Spagnoletti

From: Javier Spagnoletti <phansys@gmail.com>

Since the original tests cases were using other detectable keywords (like
"public" or "protected"), they are able to pass even if the keywords
intended to be covered are not present.

Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
---
    userdiff: php: Improved test cases used to catch "abstract" and "final"
    functions
    
    Since the original tests cases were using other detectable keywords
    (like "public" or "protected"), they are able to pass even if the
    keywords intended to be covered are not present. In the case of the test
    for "abstract" keyword, the method's body was removed in the fixture,
    since PHP doesn't allow an abstract method to have a body.
    
    Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1
Pull-Request: https://github.com/git/git/pull/915

 t/t4018/php-abstract-method | 5 ++++-
 t/t4018/php-final-method    | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
index ce215df75a..14d77e6c15 100644
--- a/t/t4018/php-abstract-method
+++ b/t/t4018/php-abstract-method
@@ -1,7 +1,10 @@
 abstract class Klass
 {
-    abstract public function RIGHT(): ?string
+    abstract function RIGHT(): ?string
     {
+        // PHP doesn't allow abstract methods to have a body,
+        // but this is here just for diff ckeck purposes.
+
         return 'ChangeMe';
     }
 }
diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
index 537fb8ad9a..f7dd2dec17 100644
--- a/t/t4018/php-final-method
+++ b/t/t4018/php-final-method
@@ -1,6 +1,6 @@
 class Klass
 {
-    final public function RIGHT(): string
+    final function RIGHT(): string
     {
         return 'ChangeMe';
     }

base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions
  2020-11-14 21:18 [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions Javier Spagnoletti via GitGitGadget
@ 2020-11-14 23:46 ` Johannes Sixt
  2020-11-16 22:21 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Sixt @ 2020-11-14 23:46 UTC (permalink / raw)
  To: Javier Spagnoletti via GitGitGadget, git; +Cc: Javier Spagnoletti

Am 14.11.20 um 22:18 schrieb Javier Spagnoletti via GitGitGadget:
> From: Javier Spagnoletti <phansys@gmail.com>
> 
> Since the original tests cases were using other detectable keywords (like
> "public" or "protected"), they are able to pass even if the keywords
> intended to be covered are not present.

Good find! I had to look at the patch text, though, before I could 
understand what the description wants to say. How about:

We have dedicated tests that "abstract" and "final" declarations
are picked up as hunk context. However, the tests also use the
keywords "public" and "protected" that by themselves denote hunk
context lines. For this reason, the tests would not fail if the
patterns for "abstract" and "final" were to become non-functional.
Remove the distracting keywords from the two tests.

> 
> Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
> ---
>      userdiff: php: Improved test cases used to catch "abstract" and "final"
>      functions
>      
>      Since the original tests cases were using other detectable keywords
>      (like "public" or "protected"), they are able to pass even if the
>      keywords intended to be covered are not present. In the case of the test
>      for "abstract" keyword, the method's body was removed in the fixture,
>      since PHP doesn't allow an abstract method to have a body.
>      
>      Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1
> Pull-Request: https://github.com/git/git/pull/915
> 
>   t/t4018/php-abstract-method | 5 ++++-
>   t/t4018/php-final-method    | 2 +-
>   2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
> index ce215df75a..14d77e6c15 100644
> --- a/t/t4018/php-abstract-method
> +++ b/t/t4018/php-abstract-method
> @@ -1,7 +1,10 @@
>   abstract class Klass
>   {
> -    abstract public function RIGHT(): ?string
> +    abstract function RIGHT(): ?string
>       {
> +        // PHP doesn't allow abstract methods to have a body,
> +        // but this is here just for diff ckeck purposes.
> +
>           return 'ChangeMe';
>       }
>   }
> diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
> index 537fb8ad9a..f7dd2dec17 100644
> --- a/t/t4018/php-final-method
> +++ b/t/t4018/php-final-method
> @@ -1,6 +1,6 @@
>   class Klass
>   {
> -    final public function RIGHT(): string
> +    final function RIGHT(): string
>       {
>           return 'ChangeMe';
>       }
> 
> base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
> 

-- Hannes


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions
  2020-11-14 21:18 [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions Javier Spagnoletti via GitGitGadget
  2020-11-14 23:46 ` Johannes Sixt
@ 2020-11-16 22:21 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2020-11-16 22:21 UTC (permalink / raw)
  To: Javier Spagnoletti via GitGitGadget; +Cc: git, Javier Spagnoletti

"Javier Spagnoletti via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Javier Spagnoletti <phansys@gmail.com>
> Subject: [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions

I'd suggest using this instead:

Subject: [PATCH] userdiff: improve "abstract" and "final" function tests for php

I am not familiar enough with PHP to know if s/function/method/ is
more appropriate for certain, but I suspect that would be the case.

> Since the original tests cases were using other detectable keywords (like
> "public" or "protected"), they are able to pass even if the keywords
> intended to be covered are not present.

I think you meant that other keywords that start functions were on
the same line and that hides if "abstract" alone is recognised
without these other keywords?

The patch changes "abstract public function" to "abstract function";
the assumption is that the presence of "public" alone is enough for
such a line to be recognised to start a function.  

But is that assumption tested elsewhere?

    ... goes and looks ...

    $ ls t/t4018/php-*
    t/t4018/php-abstract-class  t/t4018/php-function   t/t4018/php-trait
    t/t4018/php-class	    t/t4018/php-interface
    t/t4018/php-final-class     t/t4018/php-method

    $ git grep -e public -e protected t/t4018/php-*
    t/t4018/php-interface:    public function foo($ChangeMe);
    t/t4018/php-method:    public static function RIGHT()
    t/t4018/php-trait:    public function foo($ChangeMe)

You bring up "protected" but I do not see it mentioned anywhere in
your patch or in existing tests, by the way.

Taking all of the above together, perhaps

	A few tests try to see if lines with "abstract public
	function RIGHT()" and "final public function RIGHT()" on
	them are recognised as starting a method, but the presense
	of the keyword "public" is enough to get them recognised;
	ensure that these lines are still recognised as the
	beginning of a function without the "public" keyword.

	Note that t4018/php-method already tests a line with 'public
	static function RIGHT()' on it to start a function, so we
	are not losing test coverage for "public" keyword with this
	change

would make it clearer?

>
> Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
> ---
>     userdiff: php: Improved test cases used to catch "abstract" and "final"
>     functions
>     
>     Since the original tests cases were using other detectable keywords
>     (like "public" or "protected"), they are able to pass even if the
>     keywords intended to be covered are not present. In the case of the test
>     for "abstract" keyword, the method's body was removed in the fixture,
>     since PHP doesn't allow an abstract method to have a body.
>     
>     Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1
> Pull-Request: https://github.com/git/git/pull/915
>
>  t/t4018/php-abstract-method | 5 ++++-
>  t/t4018/php-final-method    | 2 +-
>  2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
> index ce215df75a..14d77e6c15 100644
> --- a/t/t4018/php-abstract-method
> +++ b/t/t4018/php-abstract-method
> @@ -1,7 +1,10 @@
>  abstract class Klass
>  {
> -    abstract public function RIGHT(): ?string
> +    abstract function RIGHT(): ?string
>      {
> +        // PHP doesn't allow abstract methods to have a body,
> +        // but this is here just for diff ckeck purposes.
> +
>          return 'ChangeMe';
>      }
>  }
> diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
> index 537fb8ad9a..f7dd2dec17 100644
> --- a/t/t4018/php-final-method
> +++ b/t/t4018/php-final-method
> @@ -1,6 +1,6 @@
>  class Klass
>  {
> -    final public function RIGHT(): string
> +    final function RIGHT(): string
>      {
>          return 'ChangeMe';
>      }
>
> base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-16 22:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14 21:18 [PATCH] userdiff: php: Improved tests catching "abstract" and "final" functions Javier Spagnoletti via GitGitGadget
2020-11-14 23:46 ` Johannes Sixt
2020-11-16 22:21 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).