diff mbox series

t7800-difftool: don't accidentally match tmp dirs

Message ID 20201224092431.13354-1-szeder.dev@gmail.com (mailing list archive)
State Superseded
Headers show
Series t7800-difftool: don't accidentally match tmp dirs | expand

Commit Message

SZEDER Gábor Dec. 24, 2020, 9:24 a.m. UTC
In a bunch of test cases in 't7800-difftool.sh' we 'grep' for specific
filenames in 'git difftool's output, and those test cases are prone to
occasional failures because those filenames might be part of the name
of difftool's temporary directory as well, e.g.:

  +git difftool --dir-diff --no-symlinks --extcmd ls v1
  +grep sub output
  +test_line_count = 2 sub-output
  test_line_count: line count for sub-output != 2
  /tmp/git-difftool.Ssubfq/left/:
  sub
  /tmp/git-difftool.Ssubfq/right/:
  sub
  error: last command exited with $?=1
  not ok 50 - difftool --dir-diff v1 from subdirectory --no-symlinks

Fix this by tightening those test cases: filter out difftool's
temporary directories from its output, and use here docs to list and
test_cmp to check all files expected to present in those directories
explicitly.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t7800-difftool.sh | 112 ++++++++++++++++++++++++++++++--------------
 1 file changed, 78 insertions(+), 34 deletions(-)

Comments

Junio C Hamano Jan. 7, 2021, 6:24 a.m. UTC | #1
SZEDER Gábor <szeder.dev@gmail.com> writes:

> diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
> index a578b35761..fe02fe1688 100755
> --- a/t/t7800-difftool.sh
> +++ b/t/t7800-difftool.sh
> @@ -439,73 +439,104 @@ run_dir_diff_test () {
>  }
>  
>  run_dir_diff_test 'difftool -d' '
> +	cat >expect <<-\EOF &&
> +	file
> +	file2
> +
> +	file
> +	file2
> +	sub
> +	EOF
>  	git difftool -d $symlinks --extcmd ls branch >output &&
> -	grep sub output &&
> -	grep file output
> +	grep -v ^/ output >actual &&

This unfortunately would not catch full paths on certain platforms.

See https://github.com/git/git/runs/1660588243?check_suite_focus=true#step:7:4186
for an example X-<.

> +	test_cmp expect actual
>  '
SZEDER Gábor Jan. 8, 2021, 9:20 a.m. UTC | #2
On Wed, Jan 06, 2021 at 10:24:27PM -0800, Junio C Hamano wrote:
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
> > diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
> > index a578b35761..fe02fe1688 100755
> > --- a/t/t7800-difftool.sh
> > +++ b/t/t7800-difftool.sh
> > @@ -439,73 +439,104 @@ run_dir_diff_test () {
> >  }
> >  
> >  run_dir_diff_test 'difftool -d' '
> > +	cat >expect <<-\EOF &&
> > +	file
> > +	file2
> > +
> > +	file
> > +	file2
> > +	sub
> > +	EOF
> >  	git difftool -d $symlinks --extcmd ls branch >output &&
> > -	grep sub output &&
> > -	grep file output
> > +	grep -v ^/ output >actual &&
> 
> This unfortunately would not catch full paths on certain platforms.
> 
> See https://github.com/git/git/runs/1660588243?check_suite_focus=true#step:7:4186
> for an example X-<.

Hrm, one has to log in to view those CI logs?  Really?! :(

Anyway, I (apparently falsely) assumed that the output these tests
look at come from Git itself, and therefore we can rely on difftool's
temporary directories being normalized UNIX-style absolute paths...
But it seems they don't actually come from Git but from 'ls', because
that's what those '--extcmd ls' options do, and I now going to assume
that 'ls' prints those absolute paths with drive letter prefixes and
whatnot on Windows.

The initial version of this patch just tightened all potentially
problematic 'grep' patterns, e.g. 'grep ^sub$ output && grep ^file$
output'.  That should work on Windows as well, shouldn't it.  Will see
whether I can dig it out from the reflogs.
Johannes Schindelin Jan. 8, 2021, 3:23 p.m. UTC | #3
Hi Gábor,

On Fri, 8 Jan 2021, SZEDER Gábor wrote:

> On Wed, Jan 06, 2021 at 10:24:27PM -0800, Junio C Hamano wrote:
> > SZEDER Gábor <szeder.dev@gmail.com> writes:
> >
> > > diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
> > > index a578b35761..fe02fe1688 100755
> > > --- a/t/t7800-difftool.sh
> > > +++ b/t/t7800-difftool.sh
> > > @@ -439,73 +439,104 @@ run_dir_diff_test () {
> > >  }
> > >
> > >  run_dir_diff_test 'difftool -d' '
> > > +	cat >expect <<-\EOF &&
> > > +	file
> > > +	file2
> > > +
> > > +	file
> > > +	file2
> > > +	sub
> > > +	EOF
> > >  	git difftool -d $symlinks --extcmd ls branch >output &&
> > > -	grep sub output &&
> > > -	grep file output
> > > +	grep -v ^/ output >actual &&
> >
> > This unfortunately would not catch full paths on certain platforms.
> >
> > See https://github.com/git/git/runs/1660588243?check_suite_focus=true#step:7:4186
> > for an example X-<.
>
> Hrm, one has to log in to view those CI logs?  Really?! :(
>
> Anyway, I (apparently falsely) assumed that the output these tests
> look at come from Git itself, and therefore we can rely on difftool's
> temporary directories being normalized UNIX-style absolute paths...
> But it seems they don't actually come from Git but from 'ls', because
> that's what those '--extcmd ls' options do, and I now going to assume
> that 'ls' prints those absolute paths with drive letter prefixes and
> whatnot on Windows.
>
> The initial version of this patch just tightened all potentially
> problematic 'grep' patterns, e.g. 'grep ^sub$ output && grep ^file$
> output'.  That should work on Windows as well, shouldn't it.  Will see
> whether I can dig it out from the reflogs.

The logs ends thusly:

-- snipsnap --
 ++++ diff -u expect actual
--- expect	2021-01-07 05:12:54.687742100 +0000
+++ actual	2021-01-07 05:12:55.370745600 +0000
@@ -1,6 +1,8 @@
+C:\Users\RUNNER~1\AppData\Local\Temp/git-difftool.a01364/left/:
 file
 file2

+C:\Users\RUNNER~1\AppData\Local\Temp/git-difftool.a01364/right/:
 file
 file2
 sub
error: last command exited with $?=1
not ok 42 - difftool -d --no-symlinks
Junio C Hamano Jan. 8, 2021, 8:10 p.m. UTC | #4
SZEDER Gábor <szeder.dev@gmail.com> writes:

> On Wed, Jan 06, 2021 at 10:24:27PM -0800, Junio C Hamano wrote:
>> SZEDER Gábor <szeder.dev@gmail.com> writes:
>> 
>> > diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
>> > index a578b35761..fe02fe1688 100755
>> > --- a/t/t7800-difftool.sh
>> > +++ b/t/t7800-difftool.sh
>> > @@ -439,73 +439,104 @@ run_dir_diff_test () {
>> >  }
>> >  
>> >  run_dir_diff_test 'difftool -d' '
>> > +	cat >expect <<-\EOF &&
>> > +	file
>> > +	file2
>> > +
>> > +	file
>> > +	file2
>> > +	sub
>> > +	EOF
>> >  	git difftool -d $symlinks --extcmd ls branch >output &&
>> > -	grep sub output &&
>> > -	grep file output
>> > +	grep -v ^/ output >actual &&
>> 
>> This unfortunately would not catch full paths on certain platforms.
>> 
>> See https://github.com/git/git/runs/1660588243?check_suite_focus=true#step:7:4186
>> for an example X-<.
>
> Hrm, one has to log in to view those CI logs?  Really?! :(

Yup, it sucks.  I am curious (but not strongly interested enough to
demand) to learn the reason why from GitHub folks.

> Anyway, I (apparently falsely) assumed that the output these tests
> look at come from Git itself, and therefore we can rely on difftool's
> temporary directories being normalized UNIX-style absolute paths...
> But it seems they don't actually come from Git but from 'ls', because
> that's what those '--extcmd ls' options do, and I now going to assume
> that 'ls' prints those absolute paths with drive letter prefixes and
> whatnot on Windows.
>
> The initial version of this patch just tightened all potentially
> problematic 'grep' patterns, e.g. 'grep ^sub$ output && grep ^file$
> output'.  That should work on Windows as well, shouldn't it.  Will see
> whether I can dig it out from the reflogs.

I only see 'file', 'file2', 'b', 'c', etc. used in the tests; do we
ever use any path that ends with a colon?

I wonder if would it be more robust to use something like

	sed -e 's|^.*/\([a-z]*\)/:$|/directory-path-\1/:|'

in place of "grep -v /" to redact the temporary directory names
difftool creates.  It would give you /directory-path-left/: or
/directory-path-right/: instead of removing these lines and it would
clarify what these two series of file names are, which may be an
added bonus.
diff mbox series

Patch

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a578b35761..fe02fe1688 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -439,73 +439,104 @@  run_dir_diff_test () {
 }
 
 run_dir_diff_test 'difftool -d' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool -d $symlinks --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		file
+		file2
+
+		file
+		file2
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls branch >output &&
-		# "sub" must only exist in "right"
-		# "file" and "file2" must be listed in both "left" and "right"
-		grep sub output >sub-output &&
-		test_line_count = 1 sub-output &&
-		grep file"$" output >file-output &&
-		test_line_count = 2 file-output &&
-		grep file2 output >file2-output &&
-		test_line_count = 2 file2-output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		file
+		sub
+
+		file
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
-		# "sub" and "file" exist in both v1 and HEAD.
-		# "file2" is unchanged.
-		grep sub output >sub-output &&
-		test_line_count = 2 sub-output &&
-		grep file output >file-output &&
-		test_line_count = 2 file-output &&
-		! grep file2 output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
-		# "sub" only exists in "right"
-		# "file" and "file2" must not be listed
-		grep sub output >sub-output &&
-		test_line_count = 1 sub-output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		sub
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
-		# "sub" exists in v1 and HEAD
-		# "file" is filtered out by the pathspec
-		grep sub output >sub-output &&
-		test_line_count = 2 sub-output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
@@ -516,18 +547,31 @@  run_dir_diff_test 'difftool --dir-diff from subdirectory with GIT_DIR set' '
 		GIT_WORK_TREE=$(pwd) &&
 		export GIT_WORK_TREE &&
 		cd sub &&
+		cat >expect <<-\EOF &&
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls \
 			branch -- sub >output &&
-		grep sub output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
 	test_when_finished git reset --hard &&
 	rm file2 &&
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --extcmd ls branch master >output &&
-	grep file2 output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff with unmerged files' '