Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test windows #356

Merged
merged 13 commits into from
Jan 25, 2021
20 changes: 17 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
go: ["1.14", "1.13", "1.12"]
steps:
- uses: actions/[email protected]
- uses: actions/setup-go@v2-beta
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go build -x -work ./cmds/...
Expand All @@ -19,14 +19,28 @@ jobs:
with:
node-version: "10.x"
- run: npm install
go-test:
lint:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since lint is only for ubuntu and not windows, did you want it in this PR or did you want to split it off into separate smaller PR?

runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/setup-go@v2
with:
go-version: "1.13"
- run: |
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint
export PATH=$GOPATH/bin:$PATH
golangci-lint run ./...
env:
GOPATH: /tmp/gopath
go-test:
strategy:
matrix:
go: ["1.14", "1.13", "1.12"]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- uses: actions/setup-go@v2-beta
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go test -race ./...
Expand Down
10 changes: 8 additions & 2 deletions codesearch/index/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ func TestMerge(t *testing.T) {
out2 := f2.Name()
out3 := f3.Name()

buildIndex(out1, mergePaths1, mergeFiles1)
buildIndex(out2, mergePaths2, mergeFiles2)
err := buildIndex(out1, mergePaths1, mergeFiles1)
if err != nil {
t.Fatal(err)
}
err = buildIndex(out2, mergePaths2, mergeFiles2)
if err != nil {
t.Fatal(err)
}

Merge(out3, out1, out2)

Expand Down
5 changes: 4 additions & 1 deletion codesearch/index/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func TestTrivialPosting(t *testing.T) {
f, _ := ioutil.TempFile("", "index-test")
defer os.Remove(f.Name())
out := f.Name()
buildIndex(out, nil, postFiles)
err := buildIndex(out, nil, postFiles)
if err != nil {
t.Fatal(err)
}
ix := Open(out)
if l := ix.PostingList(tri('S', 'e', 'a')); !equalList(l, []uint32{1, 3}) {
t.Errorf("PostingList(Sea) = %v, want [1 3]", l)
Expand Down
11 changes: 6 additions & 5 deletions codesearch/index/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (ix *IndexWriter) Add(name string, f io.Reader) string {
}

// Flush flushes the index entry to the target file.
func (ix *IndexWriter) Flush() {
func (ix *IndexWriter) Flush() error {
ix.addName("")

var off [5]uint32
Expand Down Expand Up @@ -257,7 +257,7 @@ func (ix *IndexWriter) Flush() {

log.Printf("%d data bytes, %d index bytes", ix.totalBytes, ix.main.offset())

ix.main.flush()
return ix.main.flush()
}

func (ix *IndexWriter) Close() {
Expand Down Expand Up @@ -563,15 +563,16 @@ func (b *bufWriter) offset() uint32 {
return uint32(off)
}

func (b *bufWriter) flush() {
func (b *bufWriter) flush() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we care that the other callers of flush() besides Flush() are not handling the returned error?

flush_callers

if len(b.buf) == 0 {
return
return nil
}
_, err := b.file.Write(b.buf)
if err != nil {
log.Fatalf("writing %s: %v", b.name, err)
return fmt.Errorf("writing %s: %s", b.name, err)
}
b.buf = b.buf[:0]
return nil
}

// finish flushes the file to disk and returns an open file ready for reading.
Expand Down
13 changes: 8 additions & 5 deletions codesearch/index/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func fileList(list ...uint32) string {
return string(buf)
}

func buildFlushIndex(out string, paths []string, doFlush bool, fileData map[string]string) {
func buildFlushIndex(out string, paths []string, doFlush bool, fileData map[string]string) error {
ix := Create(out)
ix.AddPaths(paths)
var files []string
Expand All @@ -129,18 +129,21 @@ func buildFlushIndex(out string, paths []string, doFlush bool, fileData map[stri
if doFlush {
ix.flushPost()
}
ix.Flush()
return ix.Flush()
}

func buildIndex(name string, paths []string, fileData map[string]string) {
buildFlushIndex(name, paths, false, fileData)
func buildIndex(name string, paths []string, fileData map[string]string) error {
return buildFlushIndex(name, paths, false, fileData)
}

func testTrivialWrite(t *testing.T, doFlush bool) {
f, _ := ioutil.TempFile("", "index-test")
defer os.Remove(f.Name())
out := f.Name()
buildFlushIndex(out, nil, doFlush, trivialFiles)
err := buildFlushIndex(out, nil, doFlush, trivialFiles)
if err != nil {
t.Fatal(err)
}

data, err := ioutil.ReadFile(out)
if err != nil {
Expand Down
Loading