#!/bin/sh setglobal test_description = ''log/show --expand-tabs'' source ./test-lib.sh setglobal HT = '" '" setglobal title = ''tab indent at the beginning of the title line'' setglobal body = ''tab indent on a line in the body'' # usage: count_expand $indent $numSP $numHT @format_args proc count_expand { setglobal expect = '' setglobal count = $shExpr(' $1 + $2 ') ;# expected spaces while test $count -gt 0 { setglobal expect = ""$expect "" setglobal count = $shExpr(' $count - 1 ') } shift 2 setglobal count = $1 ;# expected tabs while test $count -gt 0 { setglobal expect = ""$expect$HT"" setglobal count = $shExpr(' $count - 1 ') } shift # The remainder of the command line is "git show -s" options match " $ifsjoin(ARGV) " { with *' --pretty=short '* setglobal line = $title with * setglobal line = $body } # Prefix the output with the command line arguments, and # replace SP with a dot both in the expecte and actual output # so that test_cmp would show the differene together with the # breakage in a way easier to consume by the debugging user. do { echo "git show -s $ifsjoin(ARGV)" echo "$expect$line" } | sed -e 's/ /./g' >expect do { echo "git show -s $ifsjoin(ARGV)" git show -s @ARGV | sed -n -e "/$line\$/p" } | sed -e 's/ /./g' >actual test_cmp expect actual } proc test_expand { setglobal fmt = $1 match $fmt { with *=raw | *=short | *=email setglobal default = '"0 1'" with * setglobal default = '"8 0'" } match $fmt { with *=email setglobal in = '0' with * setglobal in = '4' } test_expect_success "expand/no-expand$(fmt:+ for $fmt)" ' count_expand $in $default $fmt && count_expand $in 8 0 $fmt --expand-tabs && count_expand $in 8 0 --expand-tabs $fmt && count_expand $in 8 0 $fmt --expand-tabs=8 && count_expand $in 8 0 --expand-tabs=8 $fmt && count_expand $in 0 1 $fmt --no-expand-tabs && count_expand $in 0 1 --no-expand-tabs $fmt && count_expand $in 0 1 $fmt --expand-tabs=0 && count_expand $in 0 1 --expand-tabs=0 $fmt && count_expand $in 4 0 $fmt --expand-tabs=4 && count_expand $in 4 0 --expand-tabs=4 $fmt ' } test_expect_success 'setup' ' test_tick && sed -e "s/Q/$HT/g" <<-EOF >msg && Q$title Q$body EOF git commit --allow-empty -F msg ' test_expand "" test_expand --pretty test_expand --pretty=short test_expand --pretty=medium test_expand --pretty=full test_expand --pretty=fuller test_expand --pretty=raw test_expand --pretty=email test_done