lib-log-graph.sh: consolidate test_cmp_graph logic
PATCH 1/5 lib-log-graph.sh: consolidate test_cmp_graph logic
Logic for comparing log graphs is duplicated across test scripts.
This patchset consolidates such logic into lib-log-graph.
---
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
t/lib-log-graph.sh new file +39 -0
@@ -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 "$@" +}
Signature · 1 line
2.25.0
PATCH 2/5 t3430: use lib-log-graph functions
--- t/t3430-rebase-merges.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
t/t3430-rebase-merges.sh +9 -15
@@ -20,13 +20,7 @@ Initial setup: ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh - -test_cmp_graph () { - cat >expect && - git log --graph --boundary --format=%s "$@" >output && - sed "s/ *$//" <output >output.trimmed && - test_cmp expect output.trimmed -} +. "$TEST_DIRECTORY"/lib-log-graph.sh test_expect_success 'setup' ' write_script replace-editor.sh <<-\EOF &&
@@ -84,7 +78,7 @@ test_expect_success 'create completely different structure' ' test_config sequence.editor \""$PWD"/replace-editor.sh\" && test_tick && git rebase -i -r A master && - test_cmp_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary <<-\EOF * Merge the topic branch '\''onebranch'\'' |\ | * D
@@ -201,7 +195,7 @@ test_expect_success 'with a branch tip that was cherry-picked already' ' git checkout already-upstream && test_tick && git rebase -i -r upstream-with-a2 && - test_cmp_graph upstream-with-a2.. <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary upstream-with-a2.. <<-\EOF * Merge branch A |\ | * A1
@@ -219,7 +213,7 @@ test_expect_success 'do not rebase cousins unless asked for' ' test_cmp_rev HEAD $before && test_tick && git rebase --rebase-merges=rebase-cousins HEAD^ && - test_cmp_graph HEAD^.. <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF * Merge the topic branch '\''onebranch'\'' |\ | * D
@@ -311,7 +305,7 @@ test_expect_success 'root commits' ' test $(git rev-parse second-root^0) != $(git rev-parse HEAD^) && test $(git rev-parse second-root:second-root.t) = \ $(git rev-parse HEAD^:second-root.t) && - test_cmp_graph HEAD <<-\EOF && + test_cmp_graph --pretty=tformat:%s --boundary HEAD <<-\EOF && * Merge the 3rd root |\ | * third-root
@@ -347,7 +341,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' ' test_tick && git rebase -f -r HEAD^ && test_cmp_rev ! HEAD^2 khnum && - test_cmp_graph HEAD^.. <<-\EOF && + test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF && * Merge branch '\''khnum'\'' into asherah |\ | * yama
@@ -355,7 +349,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' ' EOF test_tick && git rebase --rebase-merges=rebase-cousins HEAD^ && - test_cmp_graph HEAD^.. <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF * Merge branch '\''khnum'\'' into asherah |\ | * yama
@@ -402,7 +396,7 @@ test_expect_success 'octopus merges' ' git rebase -i --force-rebase -r HEAD^^ && test "Hank" = "$(git show -s --format=%an HEAD)" && test "$before" != $(git rev-parse HEAD) && - test_cmp_graph HEAD^^.. <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary HEAD^^.. <<-\EOF *-. Tüntenfüsch |\ \ | | * three
@@ -478,7 +472,7 @@ test_expect_success '--rebase-merges with message matched with onto label' ' git checkout -b onto-label E && git merge -m onto G && git rebase --rebase-merges --force-rebase E && - test_cmp_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary <<-\EOF * onto |\ | * G
Signature · 1 line
2.25.0
Re: [GSoC Patch 2/5] t3430: use lib-log-graph functions
Quoted 26 lines · Abhishek Kumar
Helped-by Johannes Schindelin <[email protected]>Signed-off-by Abhishek Kumar <[email protected]>--- t/t3430-rebase-merges.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)t/t3430-rebase-merges.sh +1
-7@@ -20,13 +20,7 @@ Initial setup: ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh - -test_cmp_graph () { - cat >expect && - git log --graph --boundary --format=%s "$@" >output && - sed "s/ *$//" <output >output.trimmed && - test_cmp expect output.trimmed -} +. "$TEST_DIRECTORY"/lib-log-graph.sh test_expect_success 'setup' ' write_script replace-editor.sh <<-\EOF &&
t/t3430-rebase-merges.sh test_expect_success 'create completely different structure' ' · line 81
Quoted 5 lines
t/t3430-rebase-merges.sh +1
-1@@ -84,7 +78,7 @@ test_expect_success 'create completely different structure' ' test_config sequence.editor \""$PWD"/replace-editor.sh\" && test_tick && git rebase -i -r A master && - test_cmp_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s --boundary <<-\EOF
The original used a more readble short-hand "--format=%s"; was there a strong reason why we wanted to use "--pretty=tformat:%s"?
The same comment applies to all the following hunks.
I actually have to wonder if this is a good change at all. Surely you lost one local and specialized test helper and replaced its use with a more flexible one from the lib-log-graph file, but because the one from the lib-log-graph is more flexible, you now need to tell it what options the tests want to give to the "git log" command, the same thing over and over, which would make it much more error prone, no?
It would have been more acceptable if we kept test_cmp_graph a local and specialized test helper defined in this file, but changed its implementation (i.e. the 4 lines we see above) to call to a more generic helper function defined in lib-log-graph file, i.e.
test_cmp_graph () {
test_cmp_graph_from_lib --boundary --format=%s "$@"
}but then the more flexible helper defined in lib-log-graph file cannot squat on the short-and-sweet name "test_cmp_graph" that is already used in the test scripts without unnecessary churn.
I dunno.
PATCH 3/5 t4215: use lib-log-graph functions
In reply to Abhishek Kumar--- t/t4215-log-skewed-merges.sh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
t/t4215-log-skewed-merges.sh +10 -16
@@ -3,13 +3,7 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh - -check_graph () { - cat >expect && - git log --graph --pretty=tformat:%s "$@" >actual.raw && - sed "s/ *$//" actual.raw >actual && - test_cmp expect actual -} +. "$TEST_DIRECTORY"/lib-log-graph.sh test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p &&
@@ -22,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF * H |\ | * G
@@ -50,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -84,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF * 1_H |\ | * 1_G
@@ -116,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF * 2_K |\ | * 2_J
@@ -152,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF * 3_J |\ | * 3_H
@@ -183,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + test_cmp_graph --pretty=tformat:%s --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -219,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF * 5_H |\ | *-. 5_G
@@ -258,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + test_cmp_graph --pretty=tformat:%s 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -337,7 +331,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + test_cmp_graph --pretty=tformat:%s M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
Signature · 1 line
2.25.0
Re: [GSoC Patch 3/5] t4215: use lib-log-graph functions
Quoted 26 lines · Abhishek Kumar
Helped-by Johannes Schindelin <[email protected]>Signed-off-by Abhishek Kumar <[email protected]>--- t/t4215-log-skewed-merges.sh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)t/t4215-log-skewed-merges.sh +1
-7@@ -3,13 +3,7 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh - -check_graph () { - cat >expect && - git log --graph --pretty=tformat:%s "$@" >actual.raw && - sed "s/ *$//" actual.raw >actual && - test_cmp expect actual -} +. "$TEST_DIRECTORY"/lib-log-graph.sh test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p &&
t/t4215-log-skewed-merges.sh test_expect_success 'log --graph with merge fusing with its left and right neigh · line 19
Quoted 5 lines
t/t4215-log-skewed-merges.sh +1
-1@@ -22,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + test_cmp_graph --pretty=tformat:%s <<-\EOF
Almost exactly the same comment as [2/5] applies here, but luckily the name of the local helper used here is check_graph, so we can discard all the hunks after -22,7 above and instead use
check_graph () {
test_cmp_graph --format:%s "$@"
}to reduce the code churn, I would think.
PATCH 4/5 t4214: use lib-log-graph functions
In reply to Abhishek Kumar--- t/t4214-log-graph-octopus.sh | 86 ++++++++---------------------------- 1 file changed, 19 insertions(+), 67 deletions(-)
t/t4214-log-graph-octopus.sh +19 -67
@@ -3,6 +3,7 @@ test_description='git log --graph of skewed left octopus merge.' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-log-graph.sh test_expect_success 'set up merge history' ' test_commit initial &&
@@ -24,7 +25,7 @@ test_expect_success 'set up merge history' ' ' test_expect_success 'log --graph with tricky octopus merge, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order left octopus-merge <<-\EOF * left | *-. octopus-merge |/|\ \
@@ -37,14 +38,11 @@ test_expect_success 'log --graph with tricky octopus merge, no color' ' |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s left octopus-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with tricky octopus merge with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order left octopus-merge <<-\EOF * left <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>.<RESET> octopus-merge <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET><BLUE>\<RESET> <MAGENTA>\<RESET>
@@ -57,16 +55,13 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' # Repeat the previous two tests with "normal" octopus merge (i.e., # without the first parent skewing to the "left" branch column). test_expect_success 'log --graph with normal octopus merge, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order octopus-merge <<-\EOF *---. octopus-merge |\ \ \ | | | * 4
@@ -78,13 +73,11 @@ test_expect_success 'log --graph with normal octopus merge, no color' ' |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s octopus-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with normal octopus merge with colors' ' - cat >expect.colors <<-\EOF && + test_config log.graphColors red,green,yellow,blue,magenta,cyan && + test_cmp_colored_graph --pretty=tformat:%s --date-order octopus-merge <<-\EOF *<YELLOW>-<RESET><YELLOW>-<RESET><BLUE>-<RESET><BLUE>.<RESET> octopus-merge <RED>|<RESET><GREEN>\<RESET> <YELLOW>\<RESET> <BLUE>\<RESET> <RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 4
@@ -96,14 +89,10 @@ test_expect_success 'log --graph with normal octopus merge with colors' ' <BLUE>|<RESET><BLUE>/<RESET> * initial EOF - test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with normal octopus merge and child, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order after-merge <<-\EOF * after-merge *---. octopus-merge |\ \ \
@@ -116,13 +105,11 @@ test_expect_success 'log --graph with normal octopus merge and child, no color' |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s after-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with normal octopus and child merge with colors' ' - cat >expect.colors <<-\EOF && + test_config log.graphColors red,green,yellow,blue,magenta,cyan && + test_cmp_colored_graph --pretty=tformat:%s --date-order after-merge <<-\EOF * after-merge *<BLUE>-<RESET><BLUE>-<RESET><MAGENTA>-<RESET><MAGENTA>.<RESET> octopus-merge <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <MAGENTA>\<RESET>
@@ -135,14 +122,10 @@ test_expect_success 'log --graph with normal octopus and child merge with colors <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with tricky octopus merge and its child, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order left after-merge <<-\EOF * left | * after-merge | *-. octopus-merge
@@ -156,14 +139,10 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s left after-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with tricky octopus merge and its child with colors' ' - test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order left after-merge <<-\EOF * left <RED>|<RESET> * after-merge <RED>|<RESET> *<CYAN>-<RESET><CYAN>.<RESET> octopus-merge
@@ -177,13 +156,10 @@ test_expect_success 'log --graph with tricky octopus merge and its child with co <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with crossover in octopus merge, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --date-order after-4 octopus-merge <<-\EOF * after-4 | *---. octopus-merge | |\ \ \
@@ -200,14 +176,11 @@ test_expect_success 'log --graph with crossover in octopus merge, no color' ' |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with crossover in octopus merge with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order after-4 octopus-merge <<-\EOF * after-4 <RED>|<RESET> *<BLUE>-<RESET><BLUE>-<RESET><RED>-<RESET><RED>.<RESET> octopus-merge <RED>|<RESET> <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <RED>\<RESET>
@@ -224,13 +197,10 @@ test_expect_success 'log --graph with crossover in octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with crossover in octopus merge and its child, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --date-order after-4 after-merge <<-\EOF * after-4 | * after-merge | *---. octopus-merge
@@ -248,14 +218,11 @@ test_expect_success 'log --graph with crossover in octopus merge and its child, |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with crossover in octopus merge and its child with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order after-4 after-merge <<-\EOF * after-4 <RED>|<RESET> * after-merge <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>-<RESET><RED>-<RESET><RED>.<RESET> octopus-merge
@@ -273,13 +240,10 @@ test_expect_success 'log --graph with crossover in octopus merge and its child w <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with unrelated commit and octopus tip, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order --pretty=tformat:%s after-initial octopus-merge <<-\EOF * after-initial | *---. octopus-merge | |\ \ \
@@ -296,14 +260,11 @@ test_expect_success 'log --graph with unrelated commit and octopus tip, no color |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with unrelated commit and octopus tip with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order after-initial octopus-merge <<-\EOF * after-initial <RED>|<RESET> *<BLUE>-<RESET><BLUE>-<RESET><MAGENTA>-<RESET><MAGENTA>.<RESET> octopus-merge <RED>|<RESET> <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <MAGENTA>\<RESET>
@@ -320,13 +281,10 @@ test_expect_success 'log --graph with unrelated commit and octopus tip with colo <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_expect_success 'log --graph with unrelated commit and octopus child, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order after-initial after-merge <<-\EOF * after-initial | * after-merge | *---. octopus-merge
@@ -344,14 +302,11 @@ test_expect_success 'log --graph with unrelated commit and octopus child, no col |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with unrelated commit and octopus child with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order after-initial after-merge <<-\EOF * after-initial <RED>|<RESET> * after-merge <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>-<RESET><CYAN>-<RESET><CYAN>.<RESET> octopus-merge
@@ -369,9 +324,6 @@ test_expect_success 'log --graph with unrelated commit and octopus child with co <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors ' test_done
Signature · 1 line
2.25.0
Re: [GSoC Patch 4/5] t4214: use lib-log-graph functions
Quoted 26 lines · Abhishek Kumar
t/t4214-log-graph-octopus.sh +2
-5@@ -24,7 +25,7 @@ test_expect_success 'set up merge history' ' ' test_expect_success 'log --graph with tricky octopus merge, no color' ' - cat >expect.uncolored <<-\EOF && + test_cmp_graph --pretty=tformat:%s --color=never --date-order left octopus-merge <<-\EOF * left | *-. octopus-merge |/|\ \@@ -37,14 +38,11 @@ test_expect_success 'log --graph with tricky octopus merge, no color' ' |/ * initial EOF - git log --color=never --graph --date-order --pretty=tformat:%s left octopus-merge >actual.raw && - sed "s/ *\$//" actual.raw >actual && - test_cmp expect.uncolored actual ' test_expect_success 'log --graph with tricky octopus merge with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && - cat >expect.colors <<-\EOF && + test_cmp_colored_graph --pretty=tformat:%s --date-order left octopus-merge <<-\EOF * left <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>.<RESET> octopus-merge <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET><BLUE>\<RESET> <MAGENTA>\<RESET>
t/t4214-log-graph-octopus.sh test_expect_success 'log --graph with tricky octopus merge with colors' ' · line 58
Quoted 8 lines
t/t4214-log-graph-octopus.sh +0
-3@@ -57,16 +55,13 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors '
Unlike the previous two steps, this does seem to make the script cleaner and slightly more readable (it is still unreadable but that is mostly due to the contents of the here-doc text and cannot be helped ;-).
PATCH 5/5 t4202: use lib-log-graph functions
In reply to Abhishek Kumar--- t/t4202-log.sh | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-)
t/t4202-log.sh +10 -39
@@ -5,6 +5,7 @@ test_description='git log' . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" . "$TEST_DIRECTORY/lib-terminal.sh" +. "$TEST_DIRECTORY/lib-log-graph.sh" test_expect_success setup '
@@ -452,8 +453,7 @@ cat > expect <<EOF EOF test_expect_success 'simple log --graph' ' - git log --graph --pretty=tformat:%s >actual && - test_cmp expect actual + test_cmp_graph_file --pretty=tformat:%s ' cat > expect <<EOF
@@ -467,8 +467,7 @@ cat > expect <<EOF EOF test_expect_success 'simple log --graph --line-prefix="123 "' ' - git log --graph --line-prefix="123 " --pretty=tformat:%s >actual && - test_cmp expect actual + test_cmp_graph_file --line-prefix="123 " --pretty=tformat:%s ' test_expect_success 'set up merge history' '
@@ -495,9 +494,7 @@ cat > expect <<\EOF EOF test_expect_success 'log --graph with merge' ' - git log --graph --date-order --pretty=tformat:%s | - sed "s/ *\$//" >actual && - test_cmp expect actual + test_cmp_graph_file --date-order --pretty=tformat:%s ' cat > expect <<\EOF
@@ -516,9 +513,7 @@ cat > expect <<\EOF EOF test_expect_success 'log --graph --line-prefix="| | | " with merge' ' - git log --line-prefix="| | | " --graph --date-order --pretty=tformat:%s | - sed "s/ *\$//" >actual && - test_cmp expect actual + test_cmp_graph_file --line-prefix="| | | " --date-order --pretty=tformat:%s ' cat > expect.colors <<\EOF
@@ -538,9 +533,7 @@ EOF test_expect_success 'log --graph with merge with log.graphColors' ' test_config log.graphColors " blue,invalid-color, cyan, red , " && - git log --color=always --graph --date-order --pretty=tformat:%s | - test_decode_color | sed "s/ *\$//" >actual && - test_cmp expect.colors actual + test_cmp_colored_graph_file --date-order --pretty=tformat:%s ' test_expect_success 'log --raw --graph -m with merge' '
@@ -1213,24 +1206,8 @@ cat >expect <<\EOF +one EOF -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/' -} - test_expect_success 'log --graph with diff and stats' ' - git log --no-renames --graph --pretty=short --stat -p >actual && - sanitize_output >actual.sanitized <actual && - test_i18ncmp expect actual.sanitized + test_cmp_graph_file --no-renames --graph --pretty=short --stat -p ' cat >expect <<\EOF
@@ -1505,9 +1482,7 @@ cat >expect <<\EOF EOF test_expect_success 'log --line-prefix="*** " --graph with diff and stats' ' - git log --line-prefix="*** " --no-renames --graph --pretty=short --stat -p >actual && - sanitize_output >actual.sanitized <actual && - test_i18ncmp expect actual.sanitized + test_cmp_graph_file --line-prefix="*** " --no-renames --graph --pretty=short --stat -p ' cat >expect <<-\EOF
@@ -1529,9 +1504,7 @@ cat >expect <<-\EOF EOF test_expect_success 'log --graph with --name-status' ' - git log --graph --format=%s --name-status tangle..reach >actual && - sanitize_output <actual >actual.sanitized && - test_cmp expect actual.sanitized + test_cmp_graph_file --pretty=tformat:%s --name-status tangle..reach ' cat >expect <<-\EOF
@@ -1553,9 +1526,7 @@ cat >expect <<-\EOF EOF test_expect_success 'log --graph with --name-only' ' - git log --graph --format=%s --name-only tangle..reach >actual && - sanitize_output <actual >actual.sanitized && - test_cmp expect actual.sanitized + test_cmp_graph_file --pretty=tformat:%s --name-only tangle..reach ' test_expect_success 'dotdot is a parent directory' '
Signature · 1 line
2.25.0
Re: [GSoC Patch 5/5] t4202: use lib-log-graph functions
Quoted 29 lines · Abhishek Kumar
Helped-by Johannes Schindelin <[email protected]>Signed-off-by Abhishek Kumar <[email protected]>--- t/t4202-log.sh | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-)t/t4202-log.sh +2
-2@@ -5,6 +5,7 @@ test_description='git log' . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" . "$TEST_DIRECTORY/lib-terminal.sh" +. "$TEST_DIRECTORY/lib-log-graph.sh" test_expect_success setup '@@ -452,8 +453,7 @@ cat > expect <<EOF EOF test_expect_success 'simple log --graph' ' - git log --graph --pretty=tformat:%s >actual && - test_cmp expect actual + test_cmp_graph_file --pretty=tformat:%s ' cat > expect <<EOF
t/t4202-log.sh cat > expect <<EOF · line 471
Quoted 7 lines
t/t4202-log.sh +1
-2@@ -467,8 +467,7 @@ cat > expect <<EOF EOF test_expect_success 'simple log --graph --line-prefix="123 "' ' - git log --graph --line-prefix="123 " --pretty=tformat:%s >actual && - test_cmp expect actual + test_cmp_graph_file --line-prefix="123 " --pretty=tformat:%s '
Like [4/5], and unlike [2/5] and [3/5], this step also does seem like an improvement.
Quoted 5 lines · Abhishek Kumar
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.
t/lib-log-graph.sh line 3
Quoted 9 lines
t/lib-log-graph.sh new file +3
-0@@ -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.
t/lib-log-graph.sh line 8
Quoted 5 lines
t/lib-log-graph.sh new file +5
-0+ 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.
t/lib-log-graph.sh line 13
Quoted 5 lines
t/lib-log-graph.sh new file +5
-0+ -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.
t/lib-log-graph.sh line 20
Quoted 7 lines
t/lib-log-graph.sh new file +7
-0+ -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".
t/lib-log-graph.sh line 27
Quoted 7 lines
t/lib-log-graph.sh new file +7
-0+ 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.
t/lib-log-graph.sh line 39
Quoted 11 lines
t/lib-log-graph.sh new file +11
-0+# 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(-)
t/lib-log-graph.sh +13 -7
@@ -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 "$@" }
Signature · 1 line
2.25.1-440-g39558b81cc
v2 cover Consolidate test_cmp_graph logic
In reply to Abhishek KumarChanges in v2:
- Arrange patches on functions changed, rather than files changed.
- Use specialized helper functions calling library functions.
- Fix SP and other style issues.
I would like to thank Junio for his suggestions - Really cut down on the needless changes.
Closes gitgitgadget issue #471.
Abhishek Kumar (2):
lib-log-graph: consolidate test_cmp_graph logic
lib-log-graph: consolidate colored graph cmp logic
t/lib-log-graph.sh | 28 ++++++++++++ t/t3430-rebase-merges.sh | 5 +-- t/t4202-log.sh | 57 +++++++------------------ t/t4214-log-graph-octopus.sh | 82 ++++++++++++------------------------ t/t4215-log-skewed-merges.sh | 9 ++-- 5 files changed, 74 insertions(+), 107 deletions(-) create mode 100755 t/lib-log-graph.sh
Signature · 1 line
2.25.0
PATCH v2 1/2 lib-log-graph: consolidate test_cmp_graph logic
Logic for comparing log graphs is duplicated across test scripts.
This patch consolidates such logic into lib-log-graph.
--- 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
t/lib-log-graph.sh new file +22 -0
@@ -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/' +} + +lib_test_cmp_graph () { + git log --graph "$@" >output && + sed 's/ *$//' >output.sanitized < output && + test_i18ncmp expect output.sanitized +} + +lib_test_cmp_short_graph () { + git log --graph --pretty=short "$@" >output && + sanitize_log_output >output.sanitized < output && + test_i18ncmp expect output.sanitized +}
t/t3430-rebase-merges.sh +2 -3
@@ -20,12 +20,11 @@ Initial setup: ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh +. "$TEST_DIRECTORY"/lib-log-graph.sh test_cmp_graph () { cat >expect && - git log --graph --boundary --format=%s "$@" >output && - sed "s/ *$//" <output >output.trimmed && - test_cmp expect output.trimmed + lib_test_cmp_graph --boundary --format=%s "$@" } test_expect_success 'setup' '
t/t4202-log.sh +14 -39
114 lines not on this page · raw message
t/t4214-log-graph-octopus.sh +14 -32
148 lines not on this page · raw message
t/t4215-log-skewed-merges.sh +2 -3
@@ -3,12 +3,11 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-log-graph.sh 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 "$@" } test_expect_success 'log --graph with merge fusing with its left and right neighbors' '
Signature · 1 line
2.25.0
Re: [GSoC PATCH v2 1/2] lib-log-graph: consolidate test_cmp_graph logic
Quoted 3 lines · Abhishek Kumar
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?
Quoted 16 lines
Signed-off-by Abhishek Kumar <[email protected]>--- 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.sht/lib-log-graph.sh new file +0
-0
t/lib-log-graph.sh line 10
Quoted 10 lines
t/lib-log-graph.sh new file +10
-0@@ -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.
t/lib-log-graph.sh line 12
Quoted 1 line
t/lib-log-graph.sh new file +1
-0+lib_test_cmp_graph () {
Nicely named.
t/lib-log-graph.sh line 14
Quoted 2 lines
t/lib-log-graph.sh new file +2
-0+ 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 &&
Or you can lose the input redirection altogether as "sed" knows to treat remaining command line arguments as names of its input files, i.e.
sed 's/ *$//' output >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.
t/lib-log-graph.sh line 20
Quoted 6 lines
t/lib-log-graph.sh new file +6
-0+ 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 >output.sanitized &&
(I won't repeat)
t/lib-log-graph.sh
Quoted 7 lines
t/lib-log-graph.sh new file +1
-3check_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.
PATCH v2 2/2 lib-log-graph: consolidate colored graph cmp logic
In reply to Abhishek Kumar--- t/lib-log-graph.sh | 6 ++++++ t/t4202-log.sh | 4 +--- t/t4214-log-graph-octopus.sh | 36 ++++++++++++------------------------ t/t4215-log-skewed-merges.sh | 4 +--- 4 files changed, 20 insertions(+), 30 deletions(-)
t/lib-log-graph.sh +6 -0
@@ -20,3 +20,9 @@ lib_test_cmp_short_graph () { sanitize_log_output >output.sanitized < output && test_i18ncmp expect output.sanitized } + +lib_test_cmp_colored_graph () { + git log --graph --color=always "$@" >output.colors.raw && + test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && + test_cmp expect.colors output.colors +}
t/t4202-log.sh +1 -3
@@ -537,9 +537,7 @@ EOF test_expect_success 'log --graph with merge with log.graphColors' ' test_config log.graphColors " blue,invalid-color, cyan, red , " && - git log --color=always --graph --date-order --pretty=tformat:%s | - test_decode_color | sed "s/ *\$//" >actual && - test_cmp expect.colors actual + lib_test_cmp_colored_graph --date-order --format=%s ' test_expect_success 'log --raw --graph -m with merge' '
t/t4214-log-graph-octopus.sh +12 -24
@@ -10,6 +10,10 @@ test_cmp_graph () { lib_test_cmp_graph --color=never --date-order --format=%s "$@" } +test_cmp_colored_graph () { + lib_test_cmp_colored_graph --date-order --format=%s "$@" +} + test_expect_success 'set up merge history' ' test_commit initial && for i in 1 2 3 4 ; do
@@ -60,9 +64,7 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph left octopus-merge ' # Repeat the previous two tests with "normal" octopus merge (i.e.,
@@ -97,9 +99,7 @@ test_expect_success 'log --graph with normal octopus merge with colors' ' * initial EOF test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph octopus-merge ' test_expect_success 'log --graph with normal octopus merge and child, no color' '
@@ -133,9 +133,7 @@ test_expect_success 'log --graph with normal octopus and child merge with colors * initial EOF test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-merge ' test_expect_success 'log --graph with tricky octopus merge and its child, no color' '
@@ -171,9 +169,7 @@ test_expect_success 'log --graph with tricky octopus merge and its child with co <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph left after-merge ' test_expect_success 'log --graph with crossover in octopus merge, no color' '
@@ -215,9 +211,7 @@ test_expect_success 'log --graph with crossover in octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-4 octopus-merge ' test_expect_success 'log --graph with crossover in octopus merge and its child, no color' '
@@ -261,9 +255,7 @@ test_expect_success 'log --graph with crossover in octopus merge and its child w <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-4 after-merge ' test_expect_success 'log --graph with unrelated commit and octopus tip, no color' '
@@ -305,9 +297,7 @@ test_expect_success 'log --graph with unrelated commit and octopus tip with colo <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-initial octopus-merge ' test_expect_success 'log --graph with unrelated commit and octopus child, no color' '
@@ -351,9 +341,7 @@ test_expect_success 'log --graph with unrelated commit and octopus child with co <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-initial after-merge ' test_done
t/t4215-log-skewed-merges.sh +1 -3
@@ -305,9 +305,7 @@ test_expect_success 'log --graph with multiple tips and colors' ' <BLUE>|<RESET><BLUE>/<RESET> * 6_A EOF - git log --color=always --graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + lib_test_cmp_colored_graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 ' test_expect_success 'log --graph with multiple tips' '
Signature · 1 line
2.25.0
PATCH v3 1/2 lib-log-graph: consolidate test_cmp_graph logic
In reply to Abhishek KumarLog graph comparision logic is duplicated many times in:
- t3430-rebase-merges.sh
- t4202-log.sh
- t4214-log-graph-octopus.sh
- t4215-log-skewed-merges.sh
This patch consolidates comparision and sanitization logic in lib-log-graph.
Replaces duplicated code with local and lib helpers - making test scripts cleaner and more readable.
Closes gitgitgadget issue #471
---
Changes in v3:
- Elaborate on first commit message.
- Fix SP violations in lib-log-graph.
Changes in v2:
- Arrange patches by functions changed instead of files changed.
- Rename library functions by prepending 'lib_'.
- Drop outdated sanitization calls to sed.
- Create specialized helpers to reduce code noise.
- Fix style violations.
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
t/lib-log-graph.sh new file +22 -0
@@ -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/' +} + +lib_test_cmp_graph () { + git log --graph "$@" >output && + sed 's/ *$//' >output.sanitized <output && + test_i18ncmp expect output.sanitized +} + +lib_test_cmp_short_graph () { + git log --graph --pretty=short "$@" >output && + sanitize_log_output >output.sanitized <output && + test_i18ncmp expect output.sanitized +}
t/t3430-rebase-merges.sh +2 -3
@@ -20,12 +20,11 @@ Initial setup: ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh +. "$TEST_DIRECTORY"/lib-log-graph.sh test_cmp_graph () { cat >expect && - git log --graph --boundary --format=%s "$@" >output && - sed "s/ *$//" <output >output.trimmed && - test_cmp expect output.trimmed + lib_test_cmp_graph --boundary --format=%s "$@" } test_expect_success 'setup' '
t/t4202-log.sh +14 -39
114 lines not on this page · raw message
t/t4214-log-graph-octopus.sh +14 -32
148 lines not on this page · raw message
t/t4215-log-skewed-merges.sh +2 -3
@@ -3,12 +3,11 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-log-graph.sh 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 "$@" } test_expect_success 'log --graph with merge fusing with its left and right neighbors' '
Signature · 1 line
2.25.1
PATCH v3 2/2 lib-log-graph: consolidate colored graph cmp logic
--- t/lib-log-graph.sh | 6 ++++++ t/t4202-log.sh | 4 +--- t/t4214-log-graph-octopus.sh | 36 ++++++++++++------------------------ t/t4215-log-skewed-merges.sh | 4 +--- 4 files changed, 20 insertions(+), 30 deletions(-)
t/lib-log-graph.sh +6 -0
@@ -20,3 +20,9 @@ lib_test_cmp_short_graph () { sanitize_log_output >output.sanitized <output && test_i18ncmp expect output.sanitized } + +lib_test_cmp_colored_graph () { + git log --graph --color=always "$@" >output.colors.raw && + test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && + test_cmp expect.colors output.colors +}
t/t4202-log.sh +1 -3
@@ -537,9 +537,7 @@ EOF test_expect_success 'log --graph with merge with log.graphColors' ' test_config log.graphColors " blue,invalid-color, cyan, red , " && - git log --color=always --graph --date-order --pretty=tformat:%s | - test_decode_color | sed "s/ *\$//" >actual && - test_cmp expect.colors actual + lib_test_cmp_colored_graph --date-order --format=%s ' test_expect_success 'log --raw --graph -m with merge' '
t/t4214-log-graph-octopus.sh +12 -24
@@ -10,6 +10,10 @@ test_cmp_graph () { lib_test_cmp_graph --color=never --date-order --format=%s "$@" } +test_cmp_colored_graph () { + lib_test_cmp_colored_graph --date-order --format=%s "$@" +} + test_expect_success 'set up merge history' ' test_commit initial && for i in 1 2 3 4 ; do
@@ -60,9 +64,7 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph left octopus-merge ' # Repeat the previous two tests with "normal" octopus merge (i.e.,
@@ -97,9 +99,7 @@ test_expect_success 'log --graph with normal octopus merge with colors' ' * initial EOF test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph octopus-merge ' test_expect_success 'log --graph with normal octopus merge and child, no color' '
@@ -133,9 +133,7 @@ test_expect_success 'log --graph with normal octopus and child merge with colors * initial EOF test_config log.graphColors red,green,yellow,blue,magenta,cyan && - git log --color=always --graph --date-order --pretty=tformat:%s after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-merge ' test_expect_success 'log --graph with tricky octopus merge and its child, no color' '
@@ -171,9 +169,7 @@ test_expect_success 'log --graph with tricky octopus merge and its child with co <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s left after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph left after-merge ' test_expect_success 'log --graph with crossover in octopus merge, no color' '
@@ -215,9 +211,7 @@ test_expect_success 'log --graph with crossover in octopus merge with colors' ' <MAGENTA>|<RESET><MAGENTA>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-4 octopus-merge ' test_expect_success 'log --graph with crossover in octopus merge and its child, no color' '
@@ -261,9 +255,7 @@ test_expect_success 'log --graph with crossover in octopus merge and its child w <CYAN>|<RESET><CYAN>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-4 after-merge ' test_expect_success 'log --graph with unrelated commit and octopus tip, no color' '
@@ -305,9 +297,7 @@ test_expect_success 'log --graph with unrelated commit and octopus tip with colo <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-initial octopus-merge ' test_expect_success 'log --graph with unrelated commit and octopus child, no color' '
@@ -351,9 +341,7 @@ test_expect_success 'log --graph with unrelated commit and octopus child with co <RED>|<RESET><RED>/<RESET> * initial EOF - git log --color=always --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + test_cmp_colored_graph after-initial after-merge ' test_done
t/t4215-log-skewed-merges.sh +1 -3
@@ -305,9 +305,7 @@ test_expect_success 'log --graph with multiple tips and colors' ' <BLUE>|<RESET><BLUE>/<RESET> * 6_A EOF - git log --color=always --graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 >actual.colors.raw && - test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors && - test_cmp expect.colors actual.colors + lib_test_cmp_colored_graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 ' test_expect_success 'log --graph with multiple tips' '
Signature · 1 line
2.25.1
Re: [GSoC Patch v3 1/2] lib-log-graph: consolidate test_cmp_graph logic
In reply to Abhishek KumarQuoted 10 lines · Abhishek Kumar
Changes in v3:
- Elaborate on first commit message.
- Fix SP violations in lib-log-graph.Changes in v2:
- Arrange patches by functions changed instead of files changed.
- Rename library functions by prepending 'lib_'.
- Drop outdated sanitization calls to sed.
- Create specialized helpers to reduce code noise.
- Fix style violations.
This round looks quite polished. I'll queue after massaging the log message of the first step.
Thanks.