git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [OUTREACHY][PATCH v2] t7006: Use test_path_is_* functions in test script

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 26, 2020, 20:50 UTC
Message-ID
<20201026205028.GC2645313@google.com>
In-Reply-To
<KHJW7elqEfVsIp1V0WKPRVAB5xqCDJjjqLv8flthlDiSsSWjND-VVGG2zL-xOYMstk-q0JR3OiSggcMlFgzkIKm2podjzAyamb0pW-wx1ZY=@protonmail.com>
Hi,
Joey S wrote:
Show 8 quoted lines
> Modernize the test by replacing `test -e` instances with
> `test_path_is_file` helper functions, and `! test -e` with
> `test_path_is_missing`, for better readability and diagnostic messages.
>
> Signed-off-by: Joey Salazar <jgsal@protonmail.com>
> ---
>  t/t7006-pager.sh | 84 ++++++++++++++++++++++++------------------------
>  1 file changed, 42 insertions(+), 42 deletions(-)

Grepping for 'test -' in the file after applying this patch, I find no more instances.

[...]
> -	test -e paginated.out
> +	test_path_is_file paginated.out

This kind of change ensures that if the file exists but as a directory, the test will diagnose it, which is a nice thing.

Overall (as someone who's worked a bit with this test script before), looks good to me. Thanks for your work.

> -		${if_local_config}test -e core.pager_used
> +		${if_local_config}test_path_is_file core.pager_used

This bit is a little subtle: ${if_local_config} is either '' or '! ', and in the latter case the benefit of test_path_is_file printing a message if and only if the result is false goes away.

Would the following, squashed in, make sense?

Thanks, Jonathan

diff --git i/t/t7006-pager.sh w/t/t7006-pager.sh
index fdb450e446a..11327944741 100755
--- i/t/t7006-pager.sh
+++ w/t/t7006-pager.sh
@@ -411,13 +411,13 @@ test_PAGER_overrides() {
 }
 
 test_core_pager_overrides() {
-	if_local_config=
+	pager_wanted=true
 	used_if_wanted='overrides PAGER'
 	test_core_pager "$@"
 }
 
 test_local_config_ignored() {
-	if_local_config='! '
+	pager_wanted=
 	used_if_wanted='is not used'
 	test_core_pager "$@"
 }
@@ -432,18 +432,23 @@ test_core_pager() {
 		export PAGER &&
 		test_config core.pager 'wc >core.pager_used' &&
 		$full_command &&
-		${if_local_config}test_path_is_file core.pager_used
+		if test -n '$pager_wanted'
+		then
+			test_path_is_file core.pager_used
+		else
+			test_path_is_missing core.pager_used
+		fi
 	"
 }
 
 test_core_pager_subdir() {
-	if_local_config=
+	pager_wanted=true
 	used_if_wanted='overrides PAGER'
 	test_pager_subdir_helper "$@"
 }
 
 test_no_local_config_subdir() {
-	if_local_config='! '
+	pager_wanted=
 	used_if_wanted='is not used'
 	test_pager_subdir_helper "$@"
 }
@@ -464,7 +469,12 @@ test_pager_subdir_helper() {
 			cd sub &&
 			$full_command
 		) &&
-		${if_local_config}test_path_is_file core.pager_used
+		if test -n '$pager_wanted'
+		then
+			test_path_is_file core.pager_used
+		else
+			test_path_is_missing core.pager_used
+		fi
 	"
 }
 
Previous: Joey SalazarNext: Junio C Hamano
Message 7 of 16 in “t7006: Use test_path_is_* functions in test script”
  1. Joey SOct 20, 2020
  2. Phillip WoodOct 21, 2020
  3. Junio C HamanoOct 21, 2020
  4. Joey SalazarOct 21, 2020
  5. Junio C HamanoOct 21, 2020
  6. Joey SalazarOct 21, 2020
  7. Jonathan NiederOct 26, 2020
  8. Junio C HamanoOct 26, 2020
  9. Joey SalazarOct 26, 2020
  10. Jonathan NiederOct 26, 2020
  11. Joey SalazarOct 26, 2020
  12. Joey SalazarOct 27, 2020
  13. Jonathan NiederOct 27, 2020
  14. Joey SalazarOct 27, 2020
  15. Jonathan NiederOct 28, 2020
  16. Joey SalazarOct 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.