#!/bin/sh setvar test_description = ''log/show --expand-tabs'' source ./test-lib.sh setvar HT = "" "" setvar title = ''tab indent at the beginning of the title line'' setvar body = ''tab indent on a line in the body'' # usage: count_expand $indent $numSP $numHT @format_args proc count_expand { setvar expect = '' setvar count = $(( $1 + $2 )) ;# expected spaces while test $count -gt 0 { setvar expect = ""$expect "" setvar count = $(( $count - 1 )) } shift 2 setvar count = "$1" ;# expected tabs while test $count -gt 0 { setvar expect = ""$expect$HT"" setvar count = $(( $count - 1 )) } shift # The remainder of the command line is "git show -s" options case{ *' --pretty=short '* { setvar line = "$title" } * { setvar 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 $[join(ARGV)]" echo "$expect$line" } | sed -e 's/ /./g' >expect do { echo "git show -s $[join(ARGV)]" git show -s @ARGV | sed -n -e "/$line\$/p" } | sed -e 's/ /./g' >actual test_cmp expect actual } proc test_expand { setvar fmt = "$1" case (fmt) { *=raw | *=short | *=email { setvar default = ""0 1"" } * { setvar default = ""8 0"" } } case (fmt) { *=email { setvar in = '0' } * { setvar 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