Message ID | 20200216134750.18947-1-abhishekkumar8222@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [GSoC,1/5] lib-log-graph.sh: consolidate test_cmp_graph logic | expand |
Abhishek Kumar <abhishekkumar8222@gmail.com> writes: > Logic for comparing log graphs is duplicated across test scripts. > ... > t/lib-log-graph.sh | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > create mode 100644 t/lib-log-graph.sh The presentation order of the patches may be less than ideal, in that it introduces totally unused code in step 1/5 that is hard to compare with what it will be used to replace with, and it is impossible to tell if the potential issues readers see in this step are merely inherited from existing tests or new issues introduced by this series, before reading the later steps. > diff --git a/t/lib-log-graph.sh b/t/lib-log-graph.sh > new file mode 100644 > index 0000000000..999f2600de > --- /dev/null > +++ b/t/lib-log-graph.sh > @@ -0,0 +1,39 @@ > +# Helpers shared by the test scripts for comparing log graphs. > + > +sanitize_output() { One SP around both sides of (). I suspect that all helper functions in this patch has this style violation. As a library-ish function that can be used outside individual test script, "output" without any clarification is too broad a word to act as an object of sanitizing. Is this function to sanitize the output from "git log"? Perhaps at the minimum, it should be called sanitize_log_output then. > + 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/' \ These are understandable anonymization; so is the last "index" one. > + -e 's/, 0 deletions(-)//' \ > + -e 's/, 0 insertions(+)//' \ > + -e 's/ 1 files changed, / 1 file changed, /' \ > + -e 's/, 1 deletions(-)/, 1 deletion(-)/' \ > + -e 's/, 1 insertions(+)/, 1 insertion(+)/' \ These might deserve comments. IIUC, all of these are historical accident and no longer necessary. > + -e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/' > +} > + > +# Assume expected graph is in file `expect` > +test_cmp_graph_file() { > + git log --graph "$@" >output && > + sanitize_output >output.trimmed <output && Pay attention to the names. If you are "sanitizing", then the result is not "trimmed". Call it "sanitized". > + test_i18ncmp expect output.trimmed > +} > + > +test_cmp_graph() { > + cat >expect && > + test_cmp_graph_file "$@" > +} I am not sure if this wrapper is useful or obscuring. Open coding the caller of this wrapper, i.e. cat >expect <<-\EOF && expected pattern EOF test_cmp_graph_file $args is not all that cumbersome, and it might make it more transparent to the readers what is going on. I'd need to see the callsites in later steps to decide it is a good idea. > +# Assume expected graph is in file `expect.colors` > +test_cmp_colored_graph_file() { > + git log --graph --color=always "$@" >output.colors.raw && > + test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && > + test_cmp expect.colors output.colors > +} > + > +test_cmp_colored_graph() { > + cat >expect.colors && > + test_cmp_colored_graph_file "$@" > +} So unlike test_cmp_graph family, colored counterparts do not anonymize? That sounds a bit harder to use, but we cannot really tell if that is an issue before seeing the callsites in later steps. Thanks.
Here is what I said in the message I am responding to in the patch form. t/lib-log-graph.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/t/lib-log-graph.sh b/t/lib-log-graph.sh index 999f2600de..bc70f01e84 100644 --- a/t/lib-log-graph.sh +++ b/t/lib-log-graph.sh @@ -1,6 +1,12 @@ # Helpers shared by the test scripts for comparing log graphs. -sanitize_output() { +sanitize_output () { + # Versions of Git that predate 7f814632 ("Use correct grammar + # in diffstat summary line", 2012-02-01) did not correctly use + # singular when one path was involved, and a handful of rules + # were added to work with both older and newer versions of Git + # back then. These are probably not relevant anymore, and + # we'd want to lose them someday... sed -e 's/ *$//' \ -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \ -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \ @@ -15,25 +21,25 @@ sanitize_output() { } # Assume expected graph is in file `expect` -test_cmp_graph_file() { +test_cmp_graph_file () { git log --graph "$@" >output && - sanitize_output >output.trimmed <output && - test_i18ncmp expect output.trimmed + sanitize_output >output.sanitized <output && + test_i18ncmp expect output.sanitized } -test_cmp_graph() { +test_cmp_graph () { cat >expect && test_cmp_graph_file "$@" } # Assume expected graph is in file `expect.colors` -test_cmp_colored_graph_file() { +test_cmp_colored_graph_file () { git log --graph --color=always "$@" >output.colors.raw && test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } -test_cmp_colored_graph() { +test_cmp_colored_graph () { cat >expect.colors && test_cmp_colored_graph_file "$@" }
diff --git a/t/lib-log-graph.sh b/t/lib-log-graph.sh new file mode 100644 index 0000000000..999f2600de --- /dev/null +++ b/t/lib-log-graph.sh @@ -0,0 +1,39 @@ +# Helpers shared by the test scripts for comparing log graphs. + +sanitize_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/, 0 deletions(-)//' \ + -e 's/, 0 insertions(+)//' \ + -e 's/ 1 files changed, / 1 file changed, /' \ + -e 's/, 1 deletions(-)/, 1 deletion(-)/' \ + -e 's/, 1 insertions(+)/, 1 insertion(+)/' \ + -e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/' +} + +# Assume expected graph is in file `expect` +test_cmp_graph_file() { + git log --graph "$@" >output && + sanitize_output >output.trimmed <output && + test_i18ncmp expect output.trimmed +} + +test_cmp_graph() { + cat >expect && + test_cmp_graph_file "$@" +} + +# Assume expected graph is in file `expect.colors` +test_cmp_colored_graph_file() { + git log --graph --color=always "$@" >output.colors.raw && + test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && + test_cmp expect.colors output.colors +} + +test_cmp_colored_graph() { + cat >expect.colors && + test_cmp_colored_graph_file "$@" +}
Logic for comparing log graphs is duplicated across test scripts. This patchset consolidates such logic into lib-log-graph. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com> --- 1. I don't think this patchset requires a cover letter or extended commit descriptions - Fairly simple, straightforward changes. 2. This patchset closes issue #471 from gitgitgadget. t/lib-log-graph.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 t/lib-log-graph.sh