Skip to content

Commit

Permalink
add test program
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-newman committed Jun 11, 2020
1 parent d9c6635 commit 61451bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions analysis/typecheck/typecheck_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package typecheck_test

// TODO: Figure out how to test this analyzer.
// The golang.org/x/tools/go/analysis/analysistest testing tools set up a
// "GOPATH-style project" [1], which seems to require vendoring dependencies.
// This is ok for testing the Go standard library but isn't practical for
// code with several transitive dependencies, as bigslice has.
// [1] https://pkg.go.dev/golang.org/x/[email protected]/go/analysis/analysistest?tab=doc
//
// Until then, run and see no errors for urls but a type error for wrongarg:
// $ go run github.com/grailbio/bigslice/cmd/slicetypecheck \
// github.com/grailbio/bigslice/cmd/urls \
// github.com/grailbio/bigslice/analysis/typecheck/typechecktest/wrongarg
// <snip>/wrongarg.go:22:34: bigslice type error: func "testFunc" argument "argInt" requires int, but got string
// exit status 3
23 changes: 23 additions & 0 deletions analysis/typecheck/typechecktest/wrongarg/wrongarg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Tests the static slice typechecker.
//
// This is a correctly-typed Go program (even though it's incomplete and thus
// not runnable, for simplicity). However, its bigslice Func invocation is
// incorrectly typed, and the static typechecker find that, in this case.
package main

import (
"context"

"github.com/grailbio/bigslice"
"github.com/grailbio/bigslice/exec"
)

var testFunc = bigslice.Func(func(argInt int, argString string) bigslice.Slice {
return nil
})

func main() {
ctx := context.Background()
var session *exec.Session
_ = session.Must(ctx, testFunc, "i should be an int", "i'm ok")
}

0 comments on commit 61451bd

Please sign in to comment.