From 0bb75189da9ec2757306e250dfe8f9dfb925a513 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 15 Dec 2023 16:30:59 -0800 Subject: [PATCH] Fix TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces on darwin TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces use "echo -n", which fails on darwin. These tests weren't running on darwin because they were only run in Soong, which always limits to only short tests. The test are now run in aosp-build-tools, which doesn't limit to short tests. Remove the unsupported -n argument from echo and trim the added newline instead. Test: TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces Change-Id: I3d8ff1c0db0af386e1dc13cb6c2dabe561c1c89e --- proptools/escape_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proptools/escape_test.go b/proptools/escape_test.go index 72e3ddc..2937058 100644 --- a/proptools/escape_test.go +++ b/proptools/escape_test.go @@ -15,6 +15,7 @@ package proptools import ( + "bytes" "os/exec" "reflect" "testing" @@ -143,8 +144,9 @@ func TestExternalShellEscaping(t *testing.T) { return } for _, testCase := range shellEscapeTestCase { - cmd := "echo -n " + ShellEscape(testCase.in) + cmd := "echo " + ShellEscape(testCase.in) got, err := exec.Command("/bin/sh", "-c", cmd).Output() + got = bytes.TrimSuffix(got, []byte("\n")) if err != nil { t.Error(err) } @@ -159,8 +161,9 @@ func TestExternalShellEscapeIncludingSpaces(t *testing.T) { return } for _, testCase := range shellEscapeIncludingSpacesTestCase { - cmd := "echo -n " + ShellEscapeIncludingSpaces(testCase.in) + cmd := "echo " + ShellEscapeIncludingSpaces(testCase.in) got, err := exec.Command("/bin/sh", "-c", cmd).Output() + got = bytes.TrimSuffix(got, []byte("\n")) if err != nil { t.Error(err) }