Skip to content

Commit

Permalink
Merge branch 'master' into redirect-if-internal-console
Browse files Browse the repository at this point in the history
  • Loading branch information
gfszr committed Aug 16, 2022
2 parents c7c317a + 97a7455 commit 5991d03
Show file tree
Hide file tree
Showing 14 changed files with 486 additions and 230 deletions.
10 changes: 7 additions & 3 deletions _scripts/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,17 @@ func testCmdIntl(testSet, testRegex, testBackend, testBuildMode string) {
buildModeFlag = "-test-buildmode=" + testBuildMode
}

env := []string{}
if os.Getenv("CI") != "" {
env = os.Environ()
}

if len(testPackages) > 3 {
env := []string{}
executeq(env, "go", "test", testFlags(), buildFlags(), testPackages, backendFlag, buildModeFlag)
} else if testRegex != "" {
execute("go", "test", testFlags(), buildFlags(), testPackages, "-run="+testRegex, backendFlag, buildModeFlag)
executeq(env, "go", "test", testFlags(), buildFlags(), testPackages, "-run="+testRegex, backendFlag, buildModeFlag)
} else {
execute("go", "test", testFlags(), buildFlags(), testPackages, backendFlag, buildModeFlag)
executeq(env, "go", "test", testFlags(), buildFlags(), testPackages, backendFlag, buildModeFlag)
}
}

Expand Down
9 changes: 8 additions & 1 deletion _scripts/test_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [ "$version" = "gotip" ]; then
cd -
else
echo Finding latest patch version for $version
version=$(curl 'https://go.dev/dl/?mode=json&include=all' | jq '.[].version' --raw-output | egrep ^$version'($|\.|beta|rc)' | sort -rV | head -1)
version=$(curl 'https://go.dev/dl/?mode=json&include=all' | jq '.[].version' --raw-output | egrep ^$version'($|\.|^beta|^rc)' | sort -rV | head -1)
echo "Go $version on $arch"
getgo $version
fi
Expand All @@ -57,6 +57,13 @@ elif [ ${version:4:2} -gt 17 ]; then
export GOFLAGS=-buildvcs=false
fi

if [ "$arch" = "386" ]; then
ver=$(go version)
if [ "$ver" = "go version go1.19 linux/386" ]; then
export CGO_CFLAGS='-g -O0 -fno-stack-protector'
fi
fi

set +e
make test
x=$?
Expand Down
9 changes: 7 additions & 2 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ func TestBuild(t *testing.T) {

scan := bufio.NewScanner(stderr)
// wait for the debugger to start
scan.Scan()
t.Log(scan.Text())
for scan.Scan() {
text := scan.Text()
t.Log(text)
if strings.Contains(text, "API server pid = ") {
break
}
}
go func() {
for scan.Scan() {
t.Log(scan.Text())
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func SplitQuotedFields(in string, quote rune) []string {
} else if unicode.IsSpace(ch) {
r = append(r, buf.String())
buf.Reset()
state = inSpace
} else {
buf.WriteRune(ch)
}
Expand All @@ -60,7 +61,7 @@ func SplitQuotedFields(in string, quote rune) []string {
}
}

if buf.Len() != 0 {
if state == inField || buf.Len() != 0 {
r = append(r, buf.String())
}

Expand Down
54 changes: 44 additions & 10 deletions pkg/config/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,52 @@ func TestSplitQuotedFields(t *testing.T) {
}

func TestSplitDoubleQuotedFields(t *testing.T) {
in := `field"A" "fieldB" fie"l'd"C "field\"D" "yet another field"`
tgt := []string{"fieldA", "fieldB", "fiel'dC", "field\"D", "yet another field"}
out := SplitQuotedFields(in, '"')

if len(tgt) != len(out) {
t.Fatalf("expected %#v, got %#v (len mismatch)", tgt, out)
tests := []struct {
name string
in string
expected []string
}{
{
name: "generic test case",
in: `field"A" "fieldB" fie"l'd"C "field\"D" "yet another field"`,
expected: []string{"fieldA", "fieldB", "fiel'dC", "field\"D", "yet another field"},
},
{
name: "with empty string in the end",
in: `field"A" "" `,
expected: []string{"fieldA", ""},
},
{
name: "with empty string at the beginning",
in: ` "" field"A"`,
expected: []string{"", "fieldA"},
},
{
name: "lots of spaces",
in: ` field"A" `,
expected: []string{"fieldA"},
},
{
name: "only empty string",
in: ` "" "" "" """" "" `,
expected: []string{"", "", "", "", ""},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
in := tt.in
tgt := tt.expected
out := SplitQuotedFields(in, '"')
if len(tgt) != len(out) {
t.Fatalf("expected %#v, got %#v (len mismatch)", tgt, out)
}

for i := range tgt {
if tgt[i] != out[i] {
t.Fatalf(" expected %#v, got %#v (mismatch at %d)", tgt, out, i)
}
for i := range tgt {
if tgt[i] != out[i] {
t.Fatalf(" expected %#v, got %#v (mismatch at %d)", tgt, out, i)
}
}
})
}
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/locspec/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,19 @@ func SubstitutePath(path string, rules [][2]string) string {
}

// Otherwise check if it's a directory prefix.
if !strings.HasSuffix(from, separator) {
if from != "" && !strings.HasSuffix(from, separator) {
from = from + separator
}
if !strings.HasSuffix(to, separator) {
if to != "" && !strings.HasSuffix(to, separator) {
to = to + separator
}
if strings.HasPrefix(path, from) {

// Expand relative paths with the specified prefix
if from == "" && !filepath.IsAbs(path) {
return strings.Replace(path, from, to, 1)
}

if from != "" && strings.HasPrefix(path, from) {
return strings.Replace(path, from, to, 1)
}
}
Expand Down
55 changes: 55 additions & 0 deletions pkg/locspec/locations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package locspec

import (
"runtime"
"testing"
)

Expand Down Expand Up @@ -66,3 +67,57 @@ func TestFunctionLocationParsing(t *testing.T) {
assertNormalLocationSpec(t, "github.com/go-delve/delve/pkg/proc.Process.Continue:10", NormalLocationSpec{"github.com/go-delve/delve/pkg/proc.Process.Continue", &FuncLocationSpec{PackageName: "github.com/go-delve/delve/pkg/proc", ReceiverName: "Process", BaseName: "Continue"}, 10})
assertNormalLocationSpec(t, "github.com/go-delve/delve/pkg/proc.Continue:10", NormalLocationSpec{"github.com/go-delve/delve/pkg/proc.Continue", &FuncLocationSpec{PackageName: "github.com/go-delve/delve/pkg/proc", BaseName: "Continue"}, 10})
}

func assertSubstitutePathEqual(t *testing.T, expected string, substituted string) {
if expected != substituted {
t.Fatalf("Expected substitutedPath to be %s got %s instead", expected, substituted)
}
}

func TestSubstitutePathUnix(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping unix SubstitutePath test in windows")
}

// Relative paths mapping
assertSubstitutePathEqual(t, "/my/asb/folder/relative/path", SubstitutePath("relative/path", [][2]string{{"", "/my/asb/folder/"}}))
assertSubstitutePathEqual(t, "/already/abs/path", SubstitutePath("/already/abs/path", [][2]string{{"", "/my/asb/folder/"}}))
assertSubstitutePathEqual(t, "relative/path", SubstitutePath("/my/asb/folder/relative/path", [][2]string{{"/my/asb/folder/", ""}}))
assertSubstitutePathEqual(t, "/another/folder/relative/path", SubstitutePath("/another/folder/relative/path", [][2]string{{"/my/asb/folder/", ""}}))
assertSubstitutePathEqual(t, "my/path", SubstitutePath("relative/path/my/path", [][2]string{{"relative/path", ""}}))
assertSubstitutePathEqual(t, "/abs/my/path", SubstitutePath("/abs/my/path", [][2]string{{"abs/my", ""}}))

// Absolute paths mapping
assertSubstitutePathEqual(t, "/new/mapping/path", SubstitutePath("/original/path", [][2]string{{"/original", "/new/mapping"}}))
assertSubstitutePathEqual(t, "/no/change/path", SubstitutePath("/no/change/path", [][2]string{{"/original", "/new/mapping"}}))
assertSubstitutePathEqual(t, "/folder/should_not_be_replaced/path", SubstitutePath("/folder/should_not_be_replaced/path", [][2]string{{"should_not_be_replaced", ""}}))

// Mix absolute and relative mapping
assertSubstitutePathEqual(t, "/new/mapping/path", SubstitutePath("/original/path", [][2]string{{"", "/my/asb/folder/"}, {"/my/asb/folder/", ""}, {"/original", "/new/mapping"}}))
assertSubstitutePathEqual(t, "/my/asb/folder/path", SubstitutePath("path", [][2]string{{"/original", "/new/mapping"}, {"", "/my/asb/folder/"}, {"/my/asb/folder/", ""}}))
assertSubstitutePathEqual(t, "path", SubstitutePath("/my/asb/folder/path", [][2]string{{"/original", "/new/mapping"}, {"/my/asb/folder/", ""}, {"", "/my/asb/folder/"}}))
}

func TestSubstitutePathWindows(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Skipping windows SubstitutePath test in unix")
}

// Relative paths mapping
assertSubstitutePathEqual(t, "c:\\my\\asb\\folder\\relative\\path", SubstitutePath("relative\\path", [][2]string{{"", "c:\\my\\asb\\folder\\"}}))
assertSubstitutePathEqual(t, "f:\\already\\abs\\path", SubstitutePath("F:\\already\\abs\\path", [][2]string{{"", "c:\\my\\asb\\folder\\"}}))
assertSubstitutePathEqual(t, "relative\\path", SubstitutePath("C:\\my\\asb\\folder\\relative\\path", [][2]string{{"c:\\my\\asb\\folder\\", ""}}))
assertSubstitutePathEqual(t, "f:\\another\\folder\\relative\\path", SubstitutePath("F:\\another\\folder\\relative\\path", [][2]string{{"c:\\my\\asb\\folder\\", ""}}))
assertSubstitutePathEqual(t, "my\\path", SubstitutePath("relative\\path\\my\\path", [][2]string{{"relative\\path", ""}}))
assertSubstitutePathEqual(t, "c:\\abs\\my\\path", SubstitutePath("c:\\abs\\my\\path", [][2]string{{"abs\\my", ""}}))

// Absolute paths mapping
assertSubstitutePathEqual(t, "c:\\new\\mapping\\path", SubstitutePath("D:\\original\\path", [][2]string{{"d:\\original", "c:\\new\\mapping"}}))
assertSubstitutePathEqual(t, "f:\\no\\change\\path", SubstitutePath("F:\\no\\change\\path", [][2]string{{"d:\\original", "c:\\new\\mapping"}}))
assertSubstitutePathEqual(t, "c:\\folder\\should_not_be_replaced\\path", SubstitutePath("c:\\folder\\should_not_be_replaced\\path", [][2]string{{"should_not_be_replaced", ""}}))

// Mix absolute and relative mapping
assertSubstitutePathEqual(t, "c:\\new\\mapping\\path", SubstitutePath("D:\\original\\path", [][2]string{{"", "c:\\my\\asb\\folder\\"}, {"c:\\my\\asb\\folder\\", ""}, {"d:\\original", "c:\\new\\mapping"}}))
assertSubstitutePathEqual(t, "c:\\my\\asb\\folder\\path\\", SubstitutePath("path\\", [][2]string{{"d:\\original", "c:\\new\\mapping"}, {"", "c:\\my\\asb\\folder\\"}, {"c:\\my\\asb\\folder\\", ""}}))
assertSubstitutePathEqual(t, "path", SubstitutePath("C:\\my\\asb\\folder\\path", [][2]string{{"d:\\original", "c:\\new\\mapping"}, {"c:\\my\\asb\\folder\\", ""}, {"", "c:\\my\\asb\\folder\\"}}))
}
Loading

0 comments on commit 5991d03

Please sign in to comment.