mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.1k stars 336 forks source link

interp_test: fix sleep syntax compatibility #894

Closed riacataquian closed 2 years ago

riacataquian commented 2 years ago

Running the tests on master gives me the following error:

--- FAIL: TestRunnerRunConfirm (0.03s)
    --- FAIL: TestRunnerRunConfirm/#420 (0.02s)
        interp_test.go:3690: wrong bash output in "f() { echo 1; }; { sleep 0.01s; f; } & f() { echo 2; }; wait":
            want: "1\n"
            got:  "usage: sleep seconds\n1\n"

I am running on bash version 5.1.16(1)-release:

$ bash --version
GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin21.5.0)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

The error I suppose, is because of the difference of the sleep syntax on BSD/Unix/MacOS vs on GNU/Linux - the former requires no unit and defaults to seconds, while the latter requires either smdh as unit

To fix, fix the sleep test builtin to accept either of the syntax and default to seconds when none is found

Finally, modify the tests to run without units so it would pass when ran against real bash

mvdan commented 2 years ago

I guess this was always wrong but we never noticed because CI runs MacOS with an older Bash by default, and none of us developed locally with a recent enough MacOS... until now :)

mvdan commented 2 years ago

Happy for this to be merged btw - not sure if you added the WIP state on purpose.

mvdan commented 2 years ago

An alternative is to only support seconds as units. That's all we really need.

riacataquian commented 2 years ago

I wanted to keep the intention 😅 removed and fixed, thanks! I was away so I kept this as WIP, will merge now.