Skip to content

Commit

Permalink
all: make tests pass on the debian-minimal docker image
Browse files Browse the repository at this point in the history
Such a minimal system has no extra locales installed,
so trying to use "en_US.UTF-8" might fail.
Ideally we would want the standard "C" locale,
as it is meant for consumption by computers,
but unfortunately it also means no built-in UTF-8.

However, there's good news; "C.UTF-8" is emerging for our use case.
Many systems, like Debian, already ship with it by default.
glibc won't include it until 2.35, and Arch ships 2.33,
so for the time being, Arch Linux and some other distros lack it.
For their sake and mine, fall back to our previous locale.

Note that this backport excludes the interp/os_unix.go change in v3.5.
It seems a bit too risky for a bugfix backport.

Fixes #773.
  • Loading branch information
mvdan committed Dec 16, 2021
1 parent 0baab7e commit 06e9c53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 13 additions & 3 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ func TestMain(m *testing.M) {
}
os.Setenv("GOSH_PROG", prog)

os.Setenv("LANGUAGE", "en_US.UTF-8")
os.Setenv("LC_ALL", "en_US.UTF-8")
// Set the locale to computer-friendly English and UTF-8.
// Some systems like Arch miss C.UTF8, so fall back to the US English locale.
if out, _ := exec.Command("locale", "-a").Output(); strings.Contains(
strings.ToLower(string(out)), "c.utf",
) {
os.Setenv("LANGUAGE", "C.UTF-8")
os.Setenv("LC_ALL", "C.UTF-8")
} else {
os.Setenv("LANGUAGE", "en_US.UTF-8")
os.Setenv("LC_ALL", "en_US.UTF-8")
}

os.Unsetenv("CDPATH")
hasBash50 = checkBash()

Expand Down Expand Up @@ -2775,7 +2785,7 @@ set +o pipefail
}

var runTestsUnix = []runTest{
{"[[ -n $PPID && $PPID -gt 0 ]]", ""},
{"[[ -n $PPID && $PPID -ge 0 ]]", ""}, // can be 0 if running as the init process
{
// no root user on windows
"[[ ~root == '~root' ]]",
Expand Down
13 changes: 11 additions & 2 deletions syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,17 @@ func TestParseBats(t *testing.T) {
}

func TestMain(m *testing.M) {
os.Setenv("LANGUAGE", "en_US.UTF8")
os.Setenv("LC_ALL", "en_US.UTF8")
// Set the locale to computer-friendly English and UTF-8.
// Some systems like Arch miss C.UTF8, so fall back to the US English locale.
if out, _ := exec.Command("locale", "-a").Output(); strings.Contains(
strings.ToLower(string(out)), "c.utf",
) {
os.Setenv("LANGUAGE", "C.UTF-8")
os.Setenv("LC_ALL", "C.UTF-8")
} else {
os.Setenv("LANGUAGE", "en_US.UTF-8")
os.Setenv("LC_ALL", "en_US.UTF-8")
}
os.Exit(m.Run())
}

Expand Down

0 comments on commit 06e9c53

Please sign in to comment.