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

Re: [PATCH 6/6] wildmatch test: create & test files on disk in addition to in-memory

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 24, 2017, 11:06 UTC
Message-ID
<874logs7vi.fsf@evledraar.gmail.com>
In-Reply-To
<8f4cdb23-8e2e-144a-1f70-99776b027166@kdbg.org>
On Sun, Dec 24 2017, Johannes Sixt jotted:
Show 13 quoted lines
> Am 23.12.2017 um 22:30 schrieb Ævar Arnfjörð Bjarmason:
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>   a[]b                 |   0
>>   t/t3070-wildmatch.sh | 336 ++++++++++++++++++++++++++++++++++++++++++++++++---
>>   2 files changed, 319 insertions(+), 17 deletions(-)
>>   create mode 100644 a[]b
>>
>> diff --git a/a[]b b/a[]b
>> new file mode 100644
>> index 0000000000..e69de29bb2
>
> A big no-no! This file can't be created on Windows!
Urgh, that was a mistake of mine. Will be gone in v2.
Show 41 quoted lines
>> diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh
>> index 47b479e423..d423bb01f3 100755
>> --- a/t/t3070-wildmatch.sh
>> +++ b/t/t3070-wildmatch.sh
>> @@ -4,31 +4,146 @@ test_description='wildmatch tests'
>>
>>   . ./test-lib.sh
>>
>> +create_test_file() {
>> +	file=$1
>> +
>> +	# `touch .` will succeed but obviously not do what we intend
>> +	# here.
>> +	test "$file" = "." && return 1
>> +	# We cannot create a file with an empty filename.
>> +	test "$file" = "" && return 1
>> +	# The tests that are testing that e.g. foo//bar is matched by
>> +	# foo/*/bar can't be tested on filesystems since there's no
>> +	# way we're getting a double slash.
>> +	echo "$file" | grep -q -F '//' && return 1
>> +	# When testing the difference between foo/bar and foo/bar/ we
>> +	# can't test the latter.
>> +	echo "$file" | grep -q -E '/$' && return 1
>> +
>> +	dirs=$(echo "$file" | sed -r 's!/[^/]+$!!')
>
> Booh! Booh! So many fork()s! ;)
>
> 	case "$file" in
> 	*//*)
> 		# The tests that are testing that e.g. foo//bar is matched by
> 		# foo/*/bar can't be tested on filesystems since there's no
> 		# way we're getting a double slash.
> 		return 1;;
> 	*/)
> 		# When testing the difference between foo/bar and foo/bar/ we
> 		# can't test the latter.
> 		return 1;;
> 	esac
>
> 	dirs=${file%/*}
Thanks. Will fix.
Show 67 quoted lines
>> +
>> +	# We touch "./$file" instead of "$file" because even an
>> +	# escaped "touch -- -" means something different.
>> +	if test "$file" != "$dirs"
>> +	then
>> +		mkdir -p -- "$dirs" 2>/dev/null &&
>> +		touch -- "./$file" 2>/dev/null &&
>> +		return 0
>> +	else
>> +		touch -- "./$file" 2>/dev/null &&
>> +		return 0
>> +	fi
>> +	return 1
>> +}
>> +
>>   wildtest() {
>> -	match_w_glob=$1
>> -	match_w_globi=$2
>> -	match_w_pathmatch=$3
>> -	match_w_pathmatchi=$4
>> -	text=$5
>> -	pattern=$6
>> +	if test "$#" = 6
>> +	then
>> +		# When test-wildmatch and git ls-files produce the same
>> +		# result.
>> +		match_w_glob=$1
>> +		match_f_w_glob=$match_w_glob
>> +		match_w_globi=$2
>> +		match_f_w_globi=$match_w_globi
>> +		match_w_pathmatch=$3
>> +		match_f_w_pathmatch=$match_w_pathmatch
>> +		match_w_pathmatchi=$4
>> +		match_f_w_pathmatchi=$match_w_pathmatchi
>> +		text=$5
>> +		pattern=$6
>> +	elif test "$#" = 10
>> +	then
>> +		match_w_glob=$1
>> +		match_w_globi=$2
>> +		match_w_pathmatch=$3
>> +		match_w_pathmatchi=$4
>> +		match_f_w_glob=$5
>> +		match_f_w_globi=$6
>> +		match_f_w_pathmatch=$7
>> +		match_f_w_pathmatchi=$8
>> +		text=$9
>> +		pattern=$10
>> +	fi
>>
>> +	# $1: Case sensitive glob match: test-wildmatch
>>   	if test "$match_w_glob" = 1
>>   	then
>> -		test_expect_success "wildmatch:     match '$text' '$pattern'" "
>> +		test_expect_success "wildmatch: match '$text' '$pattern'" "
>>   			test-wildmatch wildmatch '$text' '$pattern'
>>   		"
>>   	elif test "$match_w_glob" = 0
>>   	then
>> -		test_expect_success "wildmatch:  no match '$text' '$pattern'" "
>> +		test_expect_success "wildmatch: no match '$text' '$pattern'" "
>>   			! test-wildmatch wildmatch '$text' '$pattern'
>>   		"
>>   	else
>>   		test_expect_success "PANIC: Test framework error. Unknown matches value $match_w_glob" 'false'
>
> I think you can write this as 'say ...; exit 1'. See t0000*.
Thanks. Didn't see an existing idiom for this, will use that.
Show 15 quoted lines
>>   	fi
>>
>> +	# $1: Case sensitive glob match: ls-files
>> +	if test "$match_f_w_glob" = 'E'
>> +	then
>> +		if create_test_file "$text"
>> +		then
>> +			test_expect_success "wildmatch(ls): match dies on '$pattern' '$text'" "
>> +				test_when_finished \"
>> +					rm -rf -- * &&
>
> Can we be a bit more careful with this rm -rf, please?
> There is only one similarly loose case in t/t7003-filter-branch.sh,
> and it is outside test_when_finished, i.e., it is well under control;
> this instance here inside test_when_finished is not.

I can create the files inside some subfolder, cd to that and then run the ls-files there. It would also cover cases where we have pattern matching text that starts with ".".

Show 24 quoted lines
>> +					git reset
>> +				\" &&
>> +				git add -A &&
>> +				>expect.err &&
>> +				printf '%s' '$text' >expect &&
>> +				test_must_fail git --glob-pathspecs ls-files -z -- '$pattern'
>> +			"
>> +		else
>> +			test_expect_failure "wildmatch(ls): match skip '$pattern' '$text'" 'false'
>> +		fi
>> +	elif test "$match_f_w_glob" = 1
>> +	then
>> +		if create_test_file "$text"
>> +		then
>> +			test_expect_success "wildmatch(ls): match '$pattern' '$text'" "
>> +				test_when_finished \"
>> +					rm -rf -- * &&
>> +					git reset
>> +				\" &&
>> +				git add -A &&
>> +				>expect.err &&
>> +				printf '%s' '$text' >expect &&
>
> There are no single-quotes in any $text instances, right?
There's not, but maybe we should be more careful here and use here-docs.
>> +				git --glob-pathspecs ls-files -z -- '$pattern' 2>actual.err | tr -d '\0' >actual &&
>
> If possible, do not put git commands in the upstream of a pipe.
> It does not detect failures.
Thanks, will split these up.
Show 11 quoted lines
> Unfortunately, printf '%s\0' foo is not portable. If it were,
> you could omit the tr invocation alltogether.
>
>> +				test_cmp expect.err actual.err &&
>> +				test_cmp expect actual
>> +			"
>> +		else
>> +			test_expect_failure "wildmatch(ls): match skip '$pattern' '$text'" 'false'
>> +		fi
>
> -- Hannes
Previous: Johannes SixtNext: Johannes Sixt
Message 9 of 73 in “increase wildmatch test coverage”
  1. 0/6 increase wildmatch test coverageÆvar Arnfjörð Bjarmason, Dec 23, 2017
  2. 2/6 wildmatch test: use more standard shell styleÆvar Arnfjörð Bjarmason, Dec 23, 2017
  3. 1/6 wildmatch test: indent with tabs, not spacesÆvar Arnfjörð Bjarmason, Dec 23, 2017
  4. 3/6 wildmatch test: use a paranoia pattern from nul_match()Ævar Arnfjörð Bjarmason, Dec 23, 2017
  5. 4/6 wildmatch test: remove dead fnmatch() test codeÆvar Arnfjörð Bjarmason, Dec 23, 2017
  6. 5/6 wildmatch test: perform all tests under all wildmatch() modesÆvar Arnfjörð Bjarmason, Dec 23, 2017
  7. 6/6 wildmatch test: create & test files on disk in addition to in-memoryÆvar Arnfjörð Bjarmason, Dec 23, 2017
  8. Johannes SixtDec 24, 2017
  9. Ævar Arnfjörð BjarmasonDec 24, 2017
  10. Johannes SixtDec 24, 2017
  11. 0/7 increase wildmatch test coverageÆvar Arnfjörð Bjarmason, Dec 25, 2017
  12. 1/7 wildmatch test: indent with tabs, not spacesÆvar Arnfjörð Bjarmason, Dec 25, 2017
  13. 2/7 wildmatch test: use more standard shell styleÆvar Arnfjörð Bjarmason, Dec 25, 2017
  14. 3/7 wildmatch test: don't try to vertically align our outputÆvar Arnfjörð Bjarmason, Dec 25, 2017
  15. 4/7 wildmatch test: use a paranoia pattern from nul_match()Ævar Arnfjörð Bjarmason, Dec 25, 2017
  16. 5/7 wildmatch test: remove dead fnmatch() test codeÆvar Arnfjörð Bjarmason, Dec 25, 2017
  17. 6/7 wildmatch test: perform all tests under all wildmatch() modesÆvar Arnfjörð Bjarmason, Dec 25, 2017
  18. Junio C HamanoDec 28, 2017
  19. 7/7 wildmatch test: create & test files on disk in addition to in-memoryÆvar Arnfjörð Bjarmason, Dec 25, 2017
  20. Johannes SixtDec 25, 2017
  21. Junio C HamanoDec 27, 2017
  22. Adam DinwoodieJan 3, 2018
  23. Ævar Arnfjörð BjarmasonJan 3, 2018
  24. Adam DinwoodieJan 3, 2018
  25. Ævar Arnfjörð BjarmasonJan 3, 2018
  26. Adam DinwoodieJan 4, 2018
  27. 0/7 increase wildmatch test coverageÆvar Arnfjörð Bjarmason, Jan 4, 2018
  28. 1/7 wildmatch test: indent with tabs, not spacesÆvar Arnfjörð Bjarmason, Jan 4, 2018
  29. 2/7 wildmatch test: use more standard shell styleÆvar Arnfjörð Bjarmason, Jan 4, 2018
  30. 3/7 wildmatch test: don't try to vertically align our outputÆvar Arnfjörð Bjarmason, Jan 4, 2018
  31. 4/7 wildmatch test: use a paranoia pattern from nul_match()Ævar Arnfjörð Bjarmason, Jan 4, 2018
  32. 5/7 wildmatch test: remove dead fnmatch() test codeÆvar Arnfjörð Bjarmason, Jan 4, 2018
  33. 6/7 wildmatch test: perform all tests under all wildmatch() modesÆvar Arnfjörð Bjarmason, Jan 4, 2018
  34. 7/7 wildmatch test: create & test files on disk in addition to in-memoryÆvar Arnfjörð Bjarmason, Jan 4, 2018
  35. Johannes SchindelinJan 5, 2018
  36. Ævar Arnfjörð BjarmasonJan 5, 2018
  37. Johannes SchindelinJan 5, 2018
  38. 8/7 wildmatch test: skip file creation tests on Windows properÆvar Arnfjörð Bjarmason, Jan 5, 2018
  39. Junio C HamanoJan 5, 2018
  40. Johannes SchindelinJan 6, 2018
  41. Ævar Arnfjörð BjarmasonJan 6, 2018
  42. Johannes SchindelinJan 6, 2018
  43. Johannes SchindelinJan 8, 2018
  44. Junio C HamanoJan 8, 2018
  45. Duy NguyenJan 7, 2018
  46. Johannes SchindelinJan 8, 2018
  47. Duy NguyenJan 10, 2018
  48. Adam DinwoodieJan 10, 2018
  49. Duy NguyenJan 10, 2018
  50. Johannes SchindelinJan 10, 2018
  51. Duy NguyenJan 11, 2018
  52. 00/10 increase wildmatch test coverageÆvar Arnfjörð Bjarmason, Jan 30, 2018
  53. 01/10 wildmatch test: indent with tabs, not spacesÆvar Arnfjörð Bjarmason, Jan 30, 2018
  54. 02/10 wildmatch test: use more standard shell styleÆvar Arnfjörð Bjarmason, Jan 30, 2018
  55. 03/10 wildmatch test: don't try to vertically align our outputÆvar Arnfjörð Bjarmason, Jan 30, 2018
  56. 04/10 wildmatch test: use a paranoia pattern from nul_match()Ævar Arnfjörð Bjarmason, Jan 30, 2018
  57. 06/10 wildmatch test: use test_must_fail, not ! for test-wildmatchÆvar Arnfjörð Bjarmason, Jan 30, 2018
  58. 05/10 wildmatch test: remove dead fnmatch() test codeÆvar Arnfjörð Bjarmason, Jan 30, 2018
  59. 07/10 wildmatch test: perform all tests under all wildmatch() modesÆvar Arnfjörð Bjarmason, Jan 30, 2018
  60. 09/10 test-lib: add an EXPENSIVE_ON_WINDOWS prerequisiteÆvar Arnfjörð Bjarmason, Jan 30, 2018
  61. 10/10 wildmatch test: mark test as EXPENSIVE_ON_WINDOWSÆvar Arnfjörð Bjarmason, Jan 30, 2018
  62. 08/10 wildmatch test: create & test files on disk in addition to in-memoryÆvar Arnfjörð Bjarmason, Jan 30, 2018
  63. Junio C HamanoDec 28, 2017
  64. Ævar Arnfjörð BjarmasonDec 28, 2017
  65. 0/7 increase wildmatch test coverageÆvar Arnfjörð Bjarmason, Dec 28, 2017
  66. 1/7 wildmatch test: indent with tabs, not spacesÆvar Arnfjörð Bjarmason, Dec 28, 2017
  67. 3/7 wildmatch test: don't try to vertically align our outputÆvar Arnfjörð Bjarmason, Dec 28, 2017
  68. 2/7 wildmatch test: use more standard shell styleÆvar Arnfjörð Bjarmason, Dec 28, 2017
  69. 6/7 wildmatch test: perform all tests under all wildmatch() modesÆvar Arnfjörð Bjarmason, Dec 28, 2017
  70. 4/7 wildmatch test: use a paranoia pattern from nul_match()Ævar Arnfjörð Bjarmason, Dec 28, 2017
  71. 5/7 wildmatch test: remove dead fnmatch() test codeÆvar Arnfjörð Bjarmason, Dec 28, 2017
  72. 7/7 wildmatch test: create & test files on disk in addition to in-memoryÆvar Arnfjörð Bjarmason, Dec 28, 2017
  73. Ævar Arnfjörð BjarmasonDec 29, 2017

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.