Add test-tr: poor-man tr
PATCH 1/1 Add test-tr: poor-man tr
It offers a limited set of POSIX tr, in particular: no character class support and no [n*m] operators. Only 8bit. C-escapes supported, and character ranges. Deletion and squeezing should work, but -s does not match the GNU tr from coreutils (which, in turn, does not match POSIX).
---
Rebased on top of current master. I still think it makes the test suite more portable.
Makefile | 2 +- test-tr.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletions(-) create mode 100644 test-tr.c
Makefile +1 -1
@@ -1229,7 +1229,7 @@ endif ### Testing rules -TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-absolute-path$X test-parse-options$X +TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-absolute-path$X test-parse-options$X test-tr$X all:: $(TEST_PROGRAMS)
test-tr.c new file +206 -0
206 lines not on this page · raw message
Signature · 1 line
1.5.6.rc2.57.gc9624
PATCH 1/1 Use test-tr in the tests
--- t/annotate-tests.sh | 4 ++-- t/diff-lib.sh | 4 ++-- t/t0000-basic.sh | 2 +- t/t0020-crlf.sh | 10 +++++----- t/t0021-conversion.sh | 2 +- t/t1300-repo-config.sh | 4 ++-- t/t3300-funny-names.sh | 6 +++--- t/t3402-rebase-merge.sh | 4 ++-- t/t4004-diff-rename-symlink.sh | 2 +- t/t4015-diff-whitespace.sh | 6 +++--- t/t4019-diff-wserror.sh | 2 +- t/t4020-diff-external.sh | 2 +- t/t4022-diff-rewrite.sh | 2 +- t/t4101-apply-nonl.sh | 4 ++-- t/t4103-apply-binary.sh | 4 ++-- t/t4116-apply-reverse.sh | 4 ++-- t/t4118-apply-empty-context.sh | 4 ++-- t/t4200-rerere.sh | 2 +- t/t4201-shortlog.sh | 4 ++-- t/t5300-pack-object.sh | 2 +- t/t5500-fetch-pack.sh | 2 +- t/t5505-remote.sh | 4 ++-- t/t6003-rev-list-topo-order.sh | 2 +- t/t6033-merge-crlf.sh | 4 ++-- t/t7003-filter-branch.sh | 2 +- t/t9200-git-cvsexportcommit.sh | 2 +- t/t9401-git-cvsserver-crlf.sh | 4 ++-- t/test-lib.sh | 12 +++++++----- 28 files changed, 54 insertions(+), 52 deletions(-)
t/annotate-tests.sh +2 -2
@@ -104,7 +104,7 @@ test_expect_success \ test_expect_success \ 'an incomplete line added' \ - 'echo "incomplete" | tr -d "\\012" >>file && + 'echo "incomplete" | test-tr -d "\\012" >>file && GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"' test_expect_success \
@@ -115,7 +115,7 @@ test_expect_success \ 'some edit' \ 'mv file file.orig && sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" < file.orig > file && - echo "incomplete" | tr -d "\\012" >>file && + echo "incomplete" | test-tr -d "\\012" >>file && GIT_AUTHOR_NAME="D" git commit -a -m "edit"' test_expect_success \
t/diff-lib.sh +2 -2
@@ -21,8 +21,8 @@ compare_diff_raw_z () { # Also we do not check SHA1 hash generation in this test, which # is a job for t0000-basic.sh - perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1 - perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2 + test-tr '\000' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1 + test-tr '\000' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2 test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 }
t/t0000-basic.sh +1 -1
@@ -324,7 +324,7 @@ test_expect_success 'very long name in the index handled sanely' ' ( git ls-files -s path4 | sed -e "s/ .*/ /" | - tr -d "\012" + test-tr -d "\012" echo "$a" ) | git update-index --index-info && len=$(git ls-files "a*" | wc -c) &&
t/t0020-crlf.sh +5 -5
@@ -5,20 +5,20 @@ test_description='CRLF conversion' . ./test-lib.sh q_to_nul () { - perl -pe 'y/Q/\000/' + test-tr Q '\000' } q_to_cr () { - tr Q '\015' + test-tr Q '\015' } append_cr () { - sed -e 's/$/Q/' | tr Q '\015' + sed -e 's/$/Q/' | test-tr Q '\015' } remove_cr () { - tr '\015' Q <"$1" | grep Q >/dev/null && - tr '\015' Q <"$1" | sed -ne 's/Q$//p' + test-tr '\015' Q <"$1" | grep Q >/dev/null && + test-tr '\015' Q <"$1" | sed -ne 's/Q$//p' } test_expect_success setup '
t/t0021-conversion.sh +1 -1
@@ -5,7 +5,7 @@ test_description='blob conversion via gitattributes' . ./test-lib.sh cat <<\EOF >rot13.sh -tr \ +test-tr \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \ 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' EOF
t/t1300-repo-config.sh +2 -2
@@ -715,12 +715,12 @@ Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF -git config --null --list | perl -pe 'y/\000/Q/' > result +git config --null --list | test-tr '\000' Q > result echo >>result test_expect_success '--null --list' 'cmp result expect' -git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result +git config --null --get-regexp 'val[0-9]' | test-tr '\000' Q > result echo >>result test_expect_success '--null --get-regexp' 'cmp result expect'
t/t3300-funny-names.sh +3 -3
@@ -54,7 +54,7 @@ echo 'just space no-funny tabs ," (dq) and spaces' >expected test_expect_success 'git ls-files -z with-funny' \ - 'git ls-files -z | perl -pe y/\\000/\\012/ >current && + 'git ls-files -z | test-tr "\000" "\012" >current && test_cmp expected current' t1=`git write-tree`
@@ -83,11 +83,11 @@ test_expect_success 'git diff-tree with-funny' \ echo 'A tabs ," (dq) and spaces' >expected test_expect_success 'git diff-index -z with-funny' \ - 'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current && + 'git diff-index -z --name-status $t0 | test-tr "\000" "\012" >current && test_cmp expected current' test_expect_success 'git diff-tree -z with-funny' \ - 'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current && + 'git diff-tree -z --name-status $t0 $t1 | test-tr "\000" "\012" >current && test_cmp expected current' cat > expected <<\EOF
t/t3402-rebase-merge.sh +2 -2
@@ -30,11 +30,11 @@ test_expect_success setup ' git update-index --force-remove original && git commit -a -m"side renames and edits." && - tr "[a-z]" "[A-Z]" <original >newfile && + test-tr a-z A-Z <original >newfile && git add newfile && git commit -a -m"side edits further." && - tr "[a-m]" "[A-M]" <original >newfile && + test-tr a-m A-M <original >newfile && rm -f original && git commit -a -m"side edits once again." &&
t/t4004-diff-rename-symlink.sh +1 -1
@@ -14,7 +14,7 @@ by an edit for them. test_expect_success \ 'prepare reference tree' \ - 'echo xyzzy | tr -d '\\\\'012 >yomin && + 'echo xyzzy | test-tr -d "\012" >yomin && ln -s xyzzy frotz && git update-index --add frotz yomin && tree=$(git write-tree) &&
t/t4015-diff-whitespace.sh +3 -3
@@ -51,7 +51,7 @@ test_expect_success "Ray's example with -w" 'test_cmp expect out' git diff -b > out test_expect_success "Ray's example with -b" 'test_cmp expect out' -tr 'Q' '\015' << EOF > x +test-tr 'Q' '\015' << EOF > x whitespace at beginning whitespace change whitespace in the middle
@@ -71,7 +71,7 @@ unchanged line CR at end EOF -tr 'Q' '\015' << EOF > expect +test-tr 'Q' '\015' << EOF > expect diff --git a/x b/x index d99af23..8b32fb5 100644 --- a/x
@@ -99,7 +99,7 @@ EOF git diff -w > out test_expect_success 'another test, with -w' 'test_cmp expect out' -tr 'Q' '\015' << EOF > expect +test-tr 'Q' '\015' << EOF > expect diff --git a/x b/x index d99af23..8b32fb5 100644 --- a/x
t/t4019-diff-wserror.sh +1 -1
@@ -12,7 +12,7 @@ test_expect_success setup ' echo " Eight SP indent" >>F && echo " HT and SP indent" >>F && echo "With trailing SP " >>F && - echo "Carriage ReturnQ" | tr Q "\015" >>F && + echo "Carriage ReturnQ" | test-tr Q "\015" >>F && echo "No problem" >>F '
t/t4020-diff-external.sh +1 -1
@@ -99,7 +99,7 @@ test_expect_success 'no diff with -diff' ' git diff | grep Binary ' -echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file +echo NULZbetweenZwords | test-tr 'Z' '\000' > file test_expect_success 'force diff with "diff"' ' echo >.gitattributes "file diff" &&
t/t4022-diff-rewrite.sh +1 -1
@@ -8,7 +8,7 @@ test_expect_success setup ' cat ../../COPYING >test && git add test && - tr \ + test-tr \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \ "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \ <../../COPYING >test
t/t4101-apply-nonl.sh +2 -2
@@ -12,8 +12,8 @@ test_description='git apply should handle files with incomplete lines. (echo a; echo b) >frotz.0 (echo a; echo b; echo c) >frotz.1 -(echo a; echo b | tr -d '\012') >frotz.2 -(echo a; echo c; echo b | tr -d '\012') >frotz.3 +(echo a; echo b | test-tr -d '\012') >frotz.2 +(echo a; echo c; echo b | test-tr -d '\012') >frotz.3 for i in 0 1 2 3 do
t/t4103-apply-binary.sh +2 -2
@@ -24,10 +24,10 @@ git update-index --add --remove file1 file2 file4 git-commit -m 'Initial Version' 2>/dev/null git-checkout -b binary -perl -pe 'y/x/\000/' <file1 >file3 +test-tr x '\000' <file1 >file3 cat file3 >file4 git add file2 -perl -pe 'y/\000/v/' <file3 >file1 +test-tr '\000' v <file3 >file1 rm -f file2 git update-index --add --remove file1 file2 file3 file4 git-commit -m 'Second Version'
t/t4116-apply-reverse.sh +2 -2
@@ -12,14 +12,14 @@ test_description='git apply in reverse test_expect_success setup ' for i in a b c d e f g h i j k l m n; do echo $i; done >file1 && - perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 && + test-tr "ijk" "\000\001\002" <file1 >file2 && git add file1 file2 && git commit -m initial && git tag initial && for i in a b c g h i J K L m o n p q; do echo $i; done >file1 && - perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 && + test-tr "mon" "\000\001\002" <file1 >file2 && git commit -a -m second && git tag second &&
t/t4118-apply-empty-context.sh +2 -2
@@ -18,13 +18,13 @@ test_expect_success setup ' cat file1 >file1.orig && { cat file1 && - echo Q | tr -d "\\012" + echo Q | test-tr -d "\012" } >file2 && cat file2 >file2.orig git add file1 file2 && sed -e "/^B/d" <file1.orig >file1 && sed -e "/^[BQ]/d" <file2.orig >file2 && - echo Q | tr -d "\\012" >>file2 && + echo Q | test-tr -d "\012" >>file2 && cat file1 >file1.mods && cat file2 >file2.mods && git diff |
t/t4200-rerere.sh +1 -1
@@ -129,7 +129,7 @@ test_expect_success 'rerere kicked in' "! grep ======= a1" test_expect_success 'rerere prefers first change' 'test_cmp a1 expect' rm $rr/postimage -echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/rr-cache/MERGE_RR +echo "$sha1 a1" | test-tr '\012' '\000' > .git/rr-cache/MERGE_RR test_expect_success 'rerere clear' 'git rerere clear'
t/t4201-shortlog.sh +2 -2
@@ -19,12 +19,12 @@ git commit --quiet -m "This is a very, very long first line for the commit messa # test if the wrapping is still valid when replacing all i's by treble clefs. echo 3 > a1 -git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\360\235\204\236')" a1 +git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | test-tr 1234 '\360\235\204\236')" a1 # now fsck up the utf8 git config i18n.commitencoding non-utf-8 echo 4 > a1 -git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\370\235\204\236')" a1 +git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | test-tr 1234 '\370\235\204\236')" a1 echo 5 > a1 git commit --quiet -m "a 12 34 56 78" a1
t/t5300-pack-object.sh +1 -1
@@ -15,7 +15,7 @@ test_expect_success \ 'rm -f .git/index* for i in a b c do - dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i && + dd if=/dev/zero bs=4k count=1 | test-tr "\000" "$i" >$i && git update-index --add $i || return 1 done && cat c >d && echo foo >>d && git update-index --add d &&
t/t5500-fetch-pack.sh +1 -1
@@ -37,7 +37,7 @@ add () { } count_objects () { - ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " " + ls .git/objects/??/* 2>>log2.txt | wc -l | test-tr -d " " } test_expect_object_count () {
t/t5505-remote.sh +2 -2
@@ -22,8 +22,8 @@ setup_repository () { } tokens_match () { - echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && - echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && + echo "$1" | test-tr ' ' '\012' | sort | sed -e '/^$/d' >expect && + echo "$2" | test-tr ' ' '\012' | sort | sed -e '/^$/d' >actual && test_cmp expect actual }
t/t6003-rev-list-topo-order.sh +1 -1
@@ -79,7 +79,7 @@ save_tag g4 unique_commit g6 tree -p g3 -p h2 git update-ref HEAD $(tag l5) -test_output_expect_success 'rev-list has correct number of entries' 'git rev-list HEAD | wc -l | tr -d \" \"' <<EOF +test_output_expect_success 'rev-list has correct number of entries' 'git rev-list HEAD | wc -l | test-tr -d \" \"' <<EOF 19 EOF
t/t6033-merge-crlf.sh +2 -2
@@ -1,11 +1,11 @@ #!/bin/sh append_cr () { - sed -e 's/$/Q/' | tr Q '\015' + sed -e 's/$/Q/' | test-tr Q '\015' } remove_cr () { - tr '\015' Q | sed -e 's/Q$//' + test-tr '\015' Q | sed -e 's/Q$//' } test_description='merge conflict in crlf repo
t/t7003-filter-branch.sh +1 -1
@@ -4,7 +4,7 @@ test_description='git-filter-branch' . ./test-lib.sh make_commit () { - lower=$(echo $1 | tr '[A-Z]' '[a-z]') + lower=$(echo $1 | test-tr 'A-Z' 'a-z') echo $lower > $lower git add $lower test_tick
t/t9200-git-cvsexportcommit.sh +1 -1
@@ -35,7 +35,7 @@ check_entries () { then >expected else - printf '%s\n' "$2" | tr '|' '\012' >expected + printf '%s\n' "$2" | test-tr '|' '\012' >expected fi test_cmp expected actual }
t/t9401-git-cvsserver-crlf.sh +2 -2
@@ -12,11 +12,11 @@ repository using cvs CLI client via git-cvsserver server' . ./test-lib.sh q_to_nul () { - perl -pe 'y/Q/\000/' + test-tr Q '\000' } q_to_cr () { - tr Q '\015' + test-tr Q '\015' } marked_as () {
t/test-lib.sh +7 -5
@@ -44,11 +44,16 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR VISUAL GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} +# Test the binaries we have just built. The tests are kept in +# t/ subdirectory and are run in trash subdirectory. +PATH=$(pwd)/..:$PATH +export PATH + # Protect ourselves from common misconfiguration to export # CDPATH into the environment unset CDPATH -case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in +case $(echo $GIT_TRACE |test-tr A-Z a-z) in 1|2|true) echo "* warning: Some tests will not work if GIT_TRACE" \ "is set as to trace on STDERR ! *"
@@ -385,16 +390,13 @@ test_done () { esac } -# Test the binaries we have just built. The tests are kept in -# t/ subdirectory and are run in trash subdirectory. -PATH=$(pwd)/..:$PATH GIT_EXEC_PATH=$(pwd)/.. GIT_TEMPLATE_DIR=$(pwd)/../templates/blt unset GIT_CONFIG unset GIT_CONFIG_LOCAL GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_NOGLOBAL=1 -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL +export GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git export GITPERLLIB
Signature · 1 line
1.5.6.rc2.57.gc9624
Alex Riesen, Wed, Jun 11, 2008 20:25:01 +0200:
test-tr.c line 3
Quoted 6 lines
test-tr.c new file +3
-0@@ -0,0 +1,206 @@ +/* +vim: sw=8 +*/
Sorry about that...
Quoted 10 lines · Alex Riesen
It offers a limited set of POSIX tr, in particular: no character class support and no [n*m] operators. Only 8bit. C-escapes supported, and character ranges. Deletion and squeezing should work, but -s does not match the GNU tr from coreutils (which, in turn, does not match POSIX).
Signed-off-by Alex Riesen <[email protected]>---
Rebased on top of current master. I still think it makes the test suite more portable.
Having wrestled with Solaris tr, I can understand where you are coming from. However, does this _actually_ increase the portability of the test suite? That is, are there failing tests that this fixes, and if so, for which platforms (getting a successful run of the test suite on Solaris is still on my long-term todo, but I thought I had fixed all of the tr issues)?
Or is your rationale "this will prevent people from screwing up the test scripts accidentally in the future"?
I am not opposed to the latter, but I think it makes sense to state it clearly in the commit message.
-Peff
Jeff King, Thu, Jun 12, 2008 00:54:48 +0200:
Quoted 13 lines · Alex Riesen
Quoted 11 lines
It offers a limited set of POSIX tr, in particular: no character class support and no [n*m] operators. Only 8bit. C-escapes supported, and character ranges. Deletion and squeezing should work, but -s does not match the GNU tr from coreutils (which, in turn, does not match POSIX).
Signed-off-by Alex Riesen <[email protected]>---
Rebased on top of current master. I still think it makes the test suite more portable.
Quoted 6 lines
Having wrestled with Solaris tr, I can understand where you are coming from. However, does this _actually_ increase the portability of the test suite? That is, are there failing tests that this fixes, and if so, for which platforms (getting a successful run of the test suite on Solaris is still on my long-term todo, but I thought I had fixed all of the tr issues)?
Frankly, it started because I wanted to minimize use of Perl on Windows (because I can't get around ActiveState Perl at work, and it breaks almost everything it touches). Accidentally, it is also faster there (maybe just because it's smaller).
But, as was already noted, tr does not behave the same for all platforms (there were even differences in output, BSD or Solaris put out a stray LF?).
Quoted 2 lines
Or is your rationale "this will prevent people from screwing up the test scripts accidentally in the future"?
We just can't have that. Nothing can prevent people from screwing up anything in any given point of time :)
In any case, I wont push this change too hard. I must admit, that there is no real good reason besides one "screwed" company using obsoleted tools in a weird way. And it is a maintenance effort (and people will forget to use test-tr instead of perl and tr). And maybe someday my employment situation improves and I wont push it at all :)
Quoted 4 lines · Alex Riesen
Frankly, it started because I wanted to minimize use of Perl on Windows (because I can't get around ActiveState Perl at work, and it breaks almost everything it touches). Accidentally, it is also faster there (maybe just because it's smaller).
Ah, right. Well, I am not opposed to getting rid of perl in the test scripts (there is core functionality provided by perl, so one can easily run git on a system with no perl at all).
However, even with your patch, there is still some perl left, so I am not sure that it has really bought us very much.
Quoted 3 lines
But, as was already noted, tr does not behave the same for all platforms (there were even differences in output, BSD or Solaris put out a stray LF?).
I think those were all resolved by using perl, and your patch replaces them with test-tr.
Quoted 4 lines
Quoted 2 lines
Or is your rationale "this will prevent people from screwing up the test scripts accidentally in the future"?
We just can't have that. Nothing can prevent people from screwing up anything in any given point of time :)
Heh. At least we can yell at them after the fact for not using the available tool. :)
Quoted 4 lines
In any case, I wont push this change too hard. I must admit, that there is no real good reason besides one "screwed" company using obsoleted tools in a weird way. And it is a maintenance effort (and people will forget to use test-tr instead of perl and tr).
There is maintenance effort either way; people need to know not to do unportable things with tr (and other tools), and the solution to that is to run the test scripts on each platform (something we are starting to do).
So I am not opposed to test-tr, I just wanted you to explain it better in the commit log. ;)
-Peff
Quoted 3 lines · Jeff King
Ah, right. Well, I am not opposed to getting rid of perl in the test scripts (there is core functionality provided by perl, so one can easily run git on a system with no perl at all).
Er, sorry. This should read: "there is _no_ core functionality provide by perl".
-Peff
Jeff King, Thu, Jun 12, 2008 08:23:09 +0200:
Quoted 10 lines · Alex Riesen
Quoted 5 lines
Frankly, it started because I wanted to minimize use of Perl on Windows (because I can't get around ActiveState Perl at work, and it breaks almost everything it touches). Accidentally, it is also faster there (maybe just because it's smaller).
Ah, right. Well, I am not opposed to getting rid of perl in the test scripts (there is core functionality provided by perl, so one can easily run git on a system with no perl at all).
"git add --interactive" and "git send-mail". The first has a very good replacement (git gui). The other, even if not that "core", is a very popular tool. (And I can't use it at work at all: noone to understand word "patch" there. And even then, noone would care about change review anyway).
Quoted 2 lines
However, even with your patch, there is still some perl left, so I am not sure that it has really bought us very much.
I was forced to carefully check every instance and am positive that the others are ok with regard to ActiveState Perl and Windows quirks :) (IOW, I run the testsuite every day and it aint broke yet)
Quoted 6 lines
Quoted 3 lines
But, as was already noted, tr does not behave the same for all platforms (there were even differences in output, BSD or Solaris put out a stray LF?).
I think those were all resolved by using perl, and your patch replaces them with test-tr.
That was the problem. ActiveState Perl always replaces LF in the output with CRLF, which caused mismatches with template files in some tests (even the generated templates had LF line endings, cygwins tools follow that convention). At first, I tried to get by putting "binmode(STDOUT)" into every test, but this became boring with a time. Besides, the lines get very long and ugly (and make conflict resolving harder).
Quoted 9 lines
Quoted 4 lines
In any case, I wont push this change too hard. I must admit, that there is no real good reason besides one "screwed" company using obsoleted tools in a weird way. And it is a maintenance effort (and people will forget to use test-tr instead of perl and tr).
There is maintenance effort either way; people need to know not to do unportable things with tr (and other tools), and the solution to that is to run the test scripts on each platform (something we are starting to do).
With test-tr they still have to do all that, but also support its existence. So I'm not sure.
Quoted 2 lines
So I am not opposed to test-tr, I just wanted you to explain it better in the commit log. ;)
I already tried.
Quoted 7 lines · Alex Riesen
That was the problem. ActiveState Perl always replaces LF in the output with CRLF, which caused mismatches with template files in some tests (even the generated templates had LF line endings, cygwins tools follow that convention). At first, I tried to get by putting "binmode(STDOUT)" into every test, but this became boring with a time. Besides, the lines get very long and ugly (and make conflict resolving harder).
Does ActiveState respect the PERLIO environment variable? I haven't played with it much, but my understanding is that setting PERLIO=:unix:perlio should give you sane behavior (the default on Windows should be PERLIO=:unix:crlf).
Quoted 4 lines
Quoted 2 lines
So I am not opposed to test-tr, I just wanted you to explain it better in the commit log. ;)
I already tried.
I think this thread and the improved commit message have helped.
-Peff
Jeff King, Fri, Jun 13, 2008 08:02:15 +0200:
Quoted 10 lines · Alex Riesen
Quoted 8 lines
That was the problem. ActiveState Perl always replaces LF in the output with CRLF, which caused mismatches with template files in some tests (even the generated templates had LF line endings, cygwins tools follow that convention). At first, I tried to get by putting "binmode(STDOUT)" into every test, but this became boring with a time. Besides, the lines get very long and ugly (and make conflict resolving harder).
Quoted 4 lines
Does ActiveState respect the PERLIO environment variable? I haven't played with it much, but my understanding is that setting PERLIO=:unix:perlio should give you sane behavior (the default on Windows should be PERLIO=:unix:crlf).
I didn't know about it (and managed to miss it when I looked to workaround the problem. I even looked into the manpage documenting environment variables!)
Yes, it works. It has side effects (the scripts of some build processes will be affected), but that's already something...
Quoted 11 lines · Alex Riesen
Quoted 4 lines
Does ActiveState respect the PERLIO environment variable? I haven't played with it much, but my understanding is that setting PERLIO=:unix:perlio should give you sane behavior (the default on Windows should be PERLIO=:unix:crlf).
I didn't know about it (and managed to miss it when I looked to workaround the problem. I even looked into the manpage documenting environment variables!)
Yes, it works. It has side effects (the scripts of some build processes will be affected), but that's already something...
I was thinking that we could set it inside test-lib.sh to get consistent behavior. It should just be a no-op on sane systems.
-Peff
Hi Alex,
test-tr.c line 10
Quoted 3 lines
test-tr.c new file +3
-0+static unsigned char *unquote (const char *s,unsigned *len) +{ +unsigned char *result =malloc (strlen (s)), *r = result;
are you sure that the buffer is big enough?? Nomally you do a malloc(strlen(s)+1).
CU,
Alf
Hi,
Quoted 5 lines · Alf Clement
Review
Quoted 2 lines
(quoted diff) +2
-0+static unsigned char *unquote(const char *s, unsigned *len) +{ + unsigned char *result = malloc(strlen(s)), *r = result;are you sure that the buffer is big enough?? Nomally you do a malloc(strlen(s)+1).
AFAIU a "tr" really only ever replaces single characters by single characters. So, not even looking at the code -- just like you -- I would expect it to get the exact number of bytes read, and to write the same number of bytes.
I certainly would not expect it to do something string based, introducing a silly expectation of NUL-terminations (which tr(1) does not expect either).
Ciao,
Dscho
PATCH 1/1 Add test-tr: poor-man tr
It offers a limited set of POSIX tr, in particular: no character class support and no [n*m] operators. Only 8bit. C-escapes supported, and character ranges. Deletion and squeezing should work, but -s does not match the GNU tr from coreutils (which, in turn, does not match POSIX).
Even if the program does not offers the full tr features, what's left is guaranteed to work the same on every platform where you manage to compile it (unless the platform does something really nasty at low level). Originally written to overcome brokenness of ActiveState Perl on Windows, it should also improve (assuming it will be used instead of local "tr" and "perl -pe y///") portability of the test suite on other platforms.
---
Johannes Schindelin, Thu, Jun 12, 2008 09:25:09 +0200:
Quoted 8 lines · Alf Clement
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+static unsigned char *unquote(const char *s, unsigned *len) +{ + unsigned char *result = malloc(strlen(s)), *r = result;are you sure that the buffer is big enough?? Nomally you do a malloc(strlen(s)+1).
Quoted 8 lines
AFAIU a "tr" really only ever replaces single characters by single characters. So, not even looking at the code -- just like you -- I would expect it to get the exact number of bytes read, and to write the same number of bytes.
I certainly would not expect it to do something string based, introducing a silly expectation of NUL-terminations (which tr(1) does not expect either).
In any case, Alf is right. The unquote is called unconditionally with its arguments, even if there is nothing to unquote. In which case the size of result is off by one. Corrected test-tr.c (also with a sensible header) below.
Makefile | 2 +- test-tr.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletions(-) create mode 100644 test-tr.c
Makefile +1 -1
@@ -1229,7 +1229,7 @@ endif ### Testing rules -TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-absolute-path$X test-parse-options$X +TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-absolute-path$X test-parse-options$X test-tr$X all:: $(TEST_PROGRAMS)
test-tr.c new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
1.5.6.rc2.43.g77bfa