From: Junio C Hamano Date: Thu, 20 Feb 2020 17:49:17 GMT Subject: Re: [GSoC PATCH v2 1/2] lib-log-graph: consolidate test_cmp_graph logic Message-ID: In-Reply-To: <20200220091528.28472-2-abhishekkumar8222@gmail.com> Abhishek Kumar writes: > Logic for comparing log graphs is duplicated across test scripts. > > This patch consolidates such logic into lib-log-graph. The proposed log message is a bit thin. It does a bit more than "conslidates", doesn't it? > Signed-off-by: Abhishek Kumar > --- > t/lib-log-graph.sh | 22 +++++++++++++++ > t/t3430-rebase-merges.sh | 5 ++-- > t/t4202-log.sh | 53 ++++++++++-------------------------- > t/t4214-log-graph-octopus.sh | 46 ++++++++++--------------------- > t/t4215-log-skewed-merges.sh | 5 ++-- > 5 files changed, 54 insertions(+), 77 deletions(-) > create mode 100755 t/lib-log-graph.sh > > diff --git a/t/lib-log-graph.sh b/t/lib-log-graph.sh > new file mode 100755 > index 0000000000..97cde44dc7 > --- /dev/null > +++ b/t/lib-log-graph.sh > @@ -0,0 +1,22 @@ > +# Helps shared by the test scripts for comparing log graphs. > + > +sanitize_log_output () { > + sed -e 's/ *$//' \ > + -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \ > + -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \ > + -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \ > + -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \ > + -e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/' > +} For example, discarding the singular/plural compat stuff from the t4202's version is OK, but we should record that is what we did in the log message to allow readers to notice. > +lib_test_cmp_graph () { Nicely named. > + git log --graph "$@" >output && > + sed 's/ *$//' >output.sanitized < output && Lose SP not just on the output redirection but also on the input redirection. I.e. sed 's/ *$//' >output.sanitized output.sanitized && People may find the latter easier to read. I personally do not have strong preference either way as long as it is consistent. > + test_i18ncmp expect output.sanitized > +} > + > +lib_test_cmp_short_graph () { > + git log --graph --pretty=short "$@" >output && > + sanitize_log_output >output.sanitized < output && sanitize_log_output output.sanitized && (I won't repeat) > check_graph () { > cat >expect && > - git log --graph --pretty=tformat:%s "$@" >actual.raw && > - sed "s/ *$//" actual.raw >actual && > - test_cmp expect actual > + lib_test_cmp_graph --format=%s "$@" > } Hmm, is this correct? The input goes to expect but the new helper you wrote, lib_test_cmp_graph, won't see it.