Skip to content

Commit

Permalink
fix: Broken pipe in FormatPath (#94)
Browse files Browse the repository at this point in the history
* test: enable TestFormatPath

* fix: Broken pipe in FormatPath
  • Loading branch information
jakezhu9 committed Apr 2, 2023
1 parent f2813c3 commit 50753f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 12 additions & 6 deletions pkg/kclvm_runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package kclvm_runtime

import (
"bytes"
"errors"
"io"
"net/rpc"
"os/exec"
Expand Down Expand Up @@ -106,15 +105,22 @@ func newLimitBuffer(cap int) *limitBuffer {
return &limitBuffer{cap: cap}
}

func (b *limitBuffer) Write(p []byte) (n int, err error) {
n = b.cap - b.buf.Len()
func (b *limitBuffer) Write(p []byte) (int, error) {
n := b.cap - b.buf.Len()
if n > 0 {
b.buf.Write(p[:n])
if n > len(p) {
n = len(p)
}
var err error
n, err = b.buf.Write(p[:n])
if err != nil {
return n, err
}
}
if n < len(p) {
err = errors.New("limitBuffer: overflow")
return n, io.ErrShortWrite
}
return n, err
return n, nil
}

func (b *limitBuffer) Read(p []byte) (n int, err error) {
Expand Down
5 changes: 1 addition & 4 deletions pkg/tools/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/fs"
"io/ioutil"
"path"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -37,9 +38,6 @@ func TestFormatCode(t *testing.T) {
}
}

// TODO: fix Broken pipe in kclvm_py, see in :
// https://github.com/KusionStack/kclvm-go/issues/75
/*
func TestFormatPath(t *testing.T) {
successDir := "testdata/success"
expectedFileSuffix := ".formatted"
Expand Down Expand Up @@ -90,7 +88,6 @@ func TestFormatPath(t *testing.T) {
assert.Equal(t, expected, get, fmt.Sprintf("format path get wrong result. formatted content mismatch, file: %s, expect: %s, get: %s", actualFile, expected, get))
}
}
*/

type filterFile func(fs.FileInfo) bool

Expand Down

0 comments on commit 50753f3

Please sign in to comment.