simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
2.93k stars 317 forks source link

Some shelltests fails locally but pass on Travis #573

Closed ony closed 7 years ago

ony commented 7 years ago

Travis:

:tests/csv/read.test:1: [OK]
:tests/csv/read.test:2: [OK]
:tests/csv/read.test:3: [OK]
:tests/csv/read.test:4: [OK]
:tests/csv/read.test:5: [OK]
:tests/csv/read.test:6: [OK]
:tests/csv/read.test:7: [OK]

Locally:

zsh% COLUMNS=80 stack exec -- shelltest --execdir -p --debug -- tests/csv/read.test 
shelltest 1.3.5
args: Args {all_ = False, color = False, diff = False, precise = True, exclude = [], execdir = True, extension = ".test", with = "", debug = True, debug_parse = False, help_format = False, testpaths = ["tests/csv/read.test"]}
processing 1 test files: tests/csv/read.test
parsed tests/csv/read.test:
 ShellTest {testname = "tests/csv/read.test:1", command = FixedCommand "rm -rf t.rules$$; printf 'fields date, description, amount\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/09/10 Flubber Co
    income:unknown            $-50
    assets:myacct              $50

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:2", command = FixedCommand "printf 'account1 Assets:MyAccount\\ndate %%1\\ndate-format %%d/%%Y/%%m\\ndescription %%2\\namount-in %%3\\namount-out %%4\\ncurrency $\\n' >$$.rules ; hledger -f- print --rules-file $$.rules; rm -rf $$.rules", stdin = "10/2009/09,Flubber Co,50,\n11/2009/09,Flubber Co,,50\n", stdoutExpected = Just 2009/09/10 Flubber Co
    income:unknown              $-50
    Assets:MyAccount             $50

2009/09/11 Flubber Co
    expenses:unknown             $50
    Assets:MyAccount            $-50

, stderrExpected = Just /using conversion rules file.*[0-9]+\.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:3", command = FixedCommand "rm -rf t.rules$$; printf 'fields date, description, amount\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\nif Flubber\\n  account2 acct\\n  comment cmt' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/09/10 Flubber Co    ; cmt
    acct                     $-50
    assets:myacct             $50

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:4", command = FixedCommand "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/09/10 Flubber Co
    income:unknown            $-50
    assets:myacct              $50 = $123

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:5", command = FixedCommand "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123\\n11/2009/09,Blubber Co,60,' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/09/10 Flubber Co
    income:unknown            $-50
    assets:myacct              $50 = $123

2009/09/11 Blubber Co
    income:unknown            $-60
    assets:myacct              $60

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:6", command = FixedCommand "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123\\n11/2009/09,Blubber Co,60,   ' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/09/10 Flubber Co
    income:unknown            $-50
    assets:myacct              $50 = $123

2009/09/11 Blubber Co
    income:unknown            $-60
    assets:myacct              $60

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
 ShellTest {testname = "tests/csv/read.test:7", command = FixedCommand "rm -rf t.rules$$; printf 'skip 1\\n\\ncurrency $\\n\\nfields date, payee, payment\\n\\namount -%%payment\\naccount1 liabilities:bank\\naccount2 expense:other' >t.rules$$; echo 'date,payee,amount\\n2009/10/9,Flubber Co,50\\n2009/11/09,Merchant Credit,-60' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$", stdin = Nothing, stdoutExpected = Just 2009/10/09
    expense:other                $50
    liabilities:bank            $-50

2009/11/09
    expense:other               $-60
    liabilities:bank             $60

, stderrExpected = Just /using conversion rules file.*t.rules/, exitCodeExpected = 0}
command was: "rm -rf t.rules$$; printf 'fields date, description, amount\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"
stdout was : "2009/09/10 Flubber Co\n    income:unknown            $-50\n    assets:myacct              $50\n\n"
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8533\n"
exit was   : "0"
:tests/csv/read.test:1: [OK]
command was: "printf 'account1 Assets:MyAccount\\ndate %%1\\ndate-format %%d/%%Y/%%m\\ndescription %%2\\namount-in %%3\\namount-out %%4\\ncurrency $\\n' >$$.rules ; hledger -f- print --rules-file $$.rules; rm -rf $$.rules"
stdout was : "2009/09/10 Flubber Co\n    income:unknown              $-50\n    Assets:MyAccount             $50\n\n2009/09/11 Flubber Co\n    expenses:unknown             $50\n    Assets:MyAccount            $-50\n\n"
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/8542.rules\n"
exit was   : "0"
:tests/csv/read.test:2: [OK]
command was: "rm -rf t.rules$$; printf 'fields date, description, amount\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\nif Flubber\\n  account2 acct\\n  comment cmt' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"
stdout was : "2009/09/10 Flubber Co    ; cmt\n    acct                     $-50\n    assets:myacct             $50\n\n"
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8548\n"
exit was   : "0"
:tests/csv/read.test:3: [OK]
command was: "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"
stdout was : "2009/09/10 Flubber Co\n    income:unknown            $-50\n    assets:myacct              $50 = $123\n\n"
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8556\n"
exit was   : "0"
:tests/csv/read.test:4: [OK]
command was: "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123\\n11/2009/09,Blubber Co,60,' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"
stdout was : ""
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8564\nhledger: error: could not parse \"123\\n11/2009/09\" as balance amount\nthe CSV record is:       \"10/2009/09\", \"Flubber Co\", \"50\", \"123\\\\n11/2009/09\", \"Blubber Co\", \"60\", \"\"\nthe balance rule is:      %4\nthe currency rule is:    $\nthe default-currency is: unspecified\nthe parse error is:      ParseError {errorPos = SourcePos {sourceName = \"\", sourceLine = Pos 1, sourceColumn = Pos 5} :| [], errorUnexpected = fromList [...(211 more)"
exit was   : "0"
:tests/csv/read.test:5: [Failed]
command was: "rm -rf t.rules$$; printf 'fields date, description, amount, balance\\ndate-format %%d/%%Y/%%m\\ncurrency $\\naccount1 assets:myacct\\n' >t.rules$$; echo '10/2009/09,Flubber Co,50,123\\n11/2009/09,Blubber Co,60,   ' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"

Expected stdout: "2009/09/10 Flubber Co\n    income:unknown            $-50\n    assets:myacct              $50 = $123\n\n2009/09/11 Blubber Co\n    income:unknown            $-60\n    assets:myacct              $60\n\n"
Got stdout:      ""
stdout was : ""
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8572\nhledger: error: could not parse \"123\\n11/2009/09\" as balance amount\nthe CSV record is:       \"10/2009/09\", \"Flubber Co\", \"50\", \"123\\\\n11/2009/09\", \"Blubber Co\", \"60\", \"   \"\nthe balance rule is:      %4\nthe currency rule is:    $\nthe default-currency is: unspecified\nthe parse error is:      ParseError {errorPos = SourcePos {sourceName = \"\", sourceLine = Pos 1, sourceColumn = Pos 5} :| [], errorUnexpected = fromLis...(214 more)"
exit was   : "0"
:tests/csv/read.test:6: [Failed]

Expected stdout: "2009/09/10 Flubber Co\n    income:unknown            $-50\n    assets:myacct              $50 = $123\n\n2009/09/11 Blubber Co\n    income:unknown            $-60\n    assets:myacct              $60\n\n"
Got stdout:      ""command was: "rm -rf t.rules$$; printf 'skip 1\\n\\ncurrency $\\n\\nfields date, payee, payment\\n\\namount -%%payment\\naccount1 liabilities:bank\\naccount2 expense:other' >t.rules$$; echo 'date,payee,amount\\n2009/10/9,Flubber Co,50\\n2009/11/09,Merchant Credit,-60' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$"

stdout was : ""
stderr was : "using conversion rules file /.private/contrib/hledger-rewrite/tests/csv/t.rules8580\nhledger: -:1:1:\nunexpected 'd'\nexpecting end of input or transaction or directive\n\n"
exit was   : "0"
:tests/csv/read.test:7: [Failed]

Expected stdout: "2009/10/09\n    expense:other                $50\n    liabilities:bank            $-50\n\n2009/11/09\n    expense:other               $-60\n    liabilities:bank             $60\n\n"
Got stdout:      ""

         Test Cases  Total      
 Passed  4           4          
 Failed  3           3          
 Total   7           7          
simonmichael commented 7 years ago

Cf #501.

simonmichael commented 7 years ago

Ah, thanks for this. I see there is a wrong use of echo in several tests, better to use printf consistently. I haven't yet discovered why the tests pass on my machine and travis's though; there is something peculiar going on with hledger or shelltestrunner which needs explaining.

simonmichael commented 7 years ago

I believe 9d33fbe should resolve this, making the tests pass on your machine as well.

I've noted a possible shelltestrunner bug for investigation. This fails on my machine, but perhaps it passes on yours, due to different /bin/echo or $SHELL ?

# \n should be passed as-is to echo. Doesn't work on my mac.
 echo 'a\nb'
>>>
a\nb
>>>2
>>>=0
simonmichael commented 7 years ago

Assuming the immediate issue is fixed.

ony commented 7 years ago

Yep. It works on linux now. Thank you.

Regarding \n interpretation. GNU version of echo by default doesn't interpret that character and BSD version from Mac have no support for -e option at all to interpret backslash specially. Both under Linux and Mac I can see that zsh do weird interpretation regardless of quotes style or omitting them at all. I.e. 'a\'n'b' and 'a\\nb' both being interpreted and this is so wrong...

But by some reason for

# \n should be passed as-is to echo. Doesn't work on my mac.
 echo 'a\nb'
>>>
a\nb
>>>2
>>>=0

 zsh
<<<
echo 'a\nb'
>>>
a\nb
>>>2
>>>=0

 bash
<<<
echo 'a\nb'
>>>
a\nb
>>>2
>>>=0

I get fail only for second case (zsh) even that my $SHELL is /bin/zsh