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

Add some linters and tests. #198

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ jobs:
with:
go-version: '1.21'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.7.0

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

- name: Test concurrency
run: go test -v -race ./... -run Concurrency
13 changes: 10 additions & 3 deletions expreduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ func main() {
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal(err)
}
defer pprof.StopCPUProfile()
}
if *netprofile {
//nolint:errcheck
go http.ListenAndServe(":8080", nil)
}

Expand All @@ -63,7 +66,9 @@ func main() {
defer f.Close()

buf := new(bytes.Buffer)
buf.ReadFrom(f)
if _, err := buf.ReadFrom(f); err != nil {
log.Fatal(err)
}
scriptText := buf.String()
expreduce.EvalInterpMany(scriptText, *initfile, es)
}
Expand All @@ -76,7 +81,9 @@ func main() {
defer f.Close()

buf := new(bytes.Buffer)
buf.ReadFrom(f)
if _, err := buf.ReadFrom(f); err != nil {
log.Fatal(err)
}
scriptText := buf.String()
scriptSession(es, scriptText, *scriptfile)
} else {
Expand Down
1 change: 1 addition & 0 deletions expreduce/builtin_random.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func getRandomDefinitions() (defs []Definition) {

asInt, isInt := this.GetParts()[1].(*atoms.Integer)
if isInt {
//nolint:staticcheck
rand.Seed(asInt.Val.Int64())
return atoms.NewSymbol("System`Null")
}
Expand Down
12 changes: 8 additions & 4 deletions expreduce/builtin_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/gob"
"flag"
"fmt"
"io/ioutil"
"log"
"math/big"
"os"
Expand Down Expand Up @@ -125,7 +124,7 @@ func tryReadFile(fn expreduceapi.Ex, es expreduceapi.EvalStateInterface) ([]byte
}
pathsToTry = append(pathsToTry, rawFn)
for _, rawPath := range pathsToTry {
dat, err := ioutil.ReadFile(rawPath)
dat, err := os.ReadFile(rawPath)
if err != nil {
continue
}
Expand Down Expand Up @@ -305,7 +304,10 @@ func getSystemDefinitions() (defs []Definition) {
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
err = pprof.WriteHeapProfile(f)
if err != nil {
log.Fatal(err)
}
f.Close()
}
fmt.Println(es.GetTimeCounter().String())
Expand Down Expand Up @@ -728,7 +730,9 @@ func getSystemDefinitions() (defs []Definition) {
file, err := os.Create(filename)
if err == nil {
// Write the header.
file.Write(exprFileHeader)
if _, err := file.Write(exprFileHeader); err != nil {
panic(err)
}
compressedWriter := zlib.NewWriter(file)
encoder := gob.NewEncoder(compressedWriter)
if err := encoder.Encode(definitions); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion expreduce/graphics/graphics.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ func Render(expr expreduceapi.Ex) (chart.Chart, error) {
Show: true,
StrokeColor: drawing.ColorBlack,
}
renderPrimitive(&graph, graphics.GetPart(1), &style)
err := renderPrimitive(&graph, graphics.GetPart(1), &style)
if err != nil {
return graph, errors.New("failed to render primitive")
}

return graph, nil
}
Expand Down
2 changes: 0 additions & 2 deletions expreduce/matcher/matchq.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var freezeStateDuringPreMatch = flag.Bool(

const maxUint = ^uint(0)
const maxInt = int(maxUint >> 1)
const maxUint64 = ^uint64(0)
const maxInt64 = int64(maxUint64 >> 1)

type MatchIter interface {
// returns ismatch, pd, isdone
Expand Down
1 change: 1 addition & 0 deletions expreduce/matcher/pdmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (pm *PDManager) len() int {
return len(pm.patternDefined)
}

//nolint:unused
func (pm *PDManager) string(es expreduceapi.EvalStateInterface) string {
var buffer bytes.Buffer
buffer.WriteString("{")
Expand Down
4 changes: 2 additions & 2 deletions expreduce/streammanager/streammanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (sm streamManagerImpl) WriteString(streamName string, streamIndex int64, to
if !hasWriter {
return false
}
writer.Write([]byte(toWrite))
return true
_, err := writer.Write([]byte(toWrite))
return err == nil
}

func (sm streamManagerImpl) AsExpr() expreduceapi.Ex {
Expand Down
16 changes: 8 additions & 8 deletions utils/factorout/factorout.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
for _, a := range def.Attributes {
b.WriteString(fmt.Sprintf("%s, ", a))
}
b.WriteString(fmt.Sprintf("Protected};\n"))
b.WriteString("Protected};\n")
var tests bytes.Buffer
hasTests := false
tests.WriteString(fmt.Sprintf("Tests`%v = {\n\t", def.Name))
Expand All @@ -60,7 +60,7 @@ func main() {
tests.WriteString(fmt.Sprintf("%v[\n", testColNames[i]))
}
for ti, t := range testCol {
tests.WriteString(fmt.Sprintf("\t\t"))
tests.WriteString("\t\t")
if tSame, tIsSame := t.(*expreduce.SameTest); tIsSame {
tests.WriteString(fmt.Sprintf("ESameTest[%v, %v]", tSame.Out, tSame.In))
} else if tComment, tIsComment := t.(*expreduce.TestComment); tIsComment {
Expand All @@ -70,25 +70,25 @@ func main() {
} else if tExampleOnly, tIsExampleOnly := t.(*expreduce.ExampleOnlyInstruction); tIsExampleOnly {
tests.WriteString(fmt.Sprintf("EExampleOnlyInstruction[\"%v\", \"%v\"]", tExampleOnly.Out, tExampleOnly.In))
} else if _, tIsResetState := t.(*expreduce.ResetState); tIsResetState {
tests.WriteString(fmt.Sprintf("EResetState[]"))
tests.WriteString("EResetState[]")
} else {
tests.WriteString(fmt.Sprintf("%v", t))
log.Fatalf("%v %v %v", t, defSet.Name, def.Name)
}
if ti != len(testCol)-1 {
tests.WriteString(fmt.Sprintf(","))
tests.WriteString(",")
}
tests.WriteString(fmt.Sprintf("\n"))
tests.WriteString("\n")
}
tests.WriteString(fmt.Sprintf("\t]"))
tests.WriteString("\t]")
hasTests = true
}
}
tests.WriteString(fmt.Sprintf("\n};"))
tests.WriteString("\n};")
if hasTests {
b.WriteString(fmt.Sprintf("%v\n", tests.String()))
}
b.WriteString(fmt.Sprintf("\n"))
b.WriteString("\n")
}
}
fmt.Printf("%s\n", strings.TrimSpace(strings.Replace(b.String(), "\t", " ", -1)))
Expand Down