mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
loader: rewrite/refactor much of the code to use go list directly
There were a few problems with the go/packages package. While it is more
or less designed for our purpose, it didn't work quite well as it didn't
provide access to indirectly imported packages (most importantly the
runtime package). This led to a workaround that sometimes broke
`tinygo test`.
This PR contains a number of related changes:
* It uses `go list` directly to retrieve the list of packages/files to
compile, instead of relying on the go/packages package.
* It replaces our custom TestMain replace code with the standard code
for running tests (generated by `go list`).
* It adds a dummy runtime/pprof package and modifies the testing
package, to get tests to run again with the code generated by
`go list`.
This commit is contained in:
committed by
Ron Evans
parent
51238fba50
commit
c810628a20
@@ -15,3 +15,8 @@ type B struct {
|
||||
common
|
||||
N int
|
||||
}
|
||||
|
||||
type InternalBenchmark struct {
|
||||
Name string
|
||||
F func(b *B)
|
||||
}
|
||||
|
||||
+18
-7
@@ -154,18 +154,16 @@ func (c *common) Skipped() bool {
|
||||
return c.skipped
|
||||
}
|
||||
|
||||
// TestToCall is a reference to a test that should be called during a test suite run.
|
||||
type TestToCall struct {
|
||||
// Name of the test to call.
|
||||
// InternalTest is a reference to a test that should be called during a test suite run.
|
||||
type InternalTest struct {
|
||||
Name string
|
||||
// Function reference to the test.
|
||||
Func func(*T)
|
||||
F func(*T)
|
||||
}
|
||||
|
||||
// M is a test suite.
|
||||
type M struct {
|
||||
// tests is a list of the test names to execute
|
||||
Tests []TestToCall
|
||||
Tests []InternalTest
|
||||
}
|
||||
|
||||
// Run the test suite.
|
||||
@@ -180,7 +178,7 @@ func (m *M) Run() int {
|
||||
}
|
||||
|
||||
fmt.Printf("=== RUN %s\n", test.Name)
|
||||
test.Func(t)
|
||||
test.F(t)
|
||||
|
||||
if t.failed {
|
||||
fmt.Printf("--- FAIL: %s\n", test.Name)
|
||||
@@ -204,3 +202,16 @@ func (m *M) Run() int {
|
||||
func TestMain(m *M) {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M {
|
||||
return &M{
|
||||
Tests: tests,
|
||||
}
|
||||
}
|
||||
|
||||
type InternalExample struct {
|
||||
Name string
|
||||
F func()
|
||||
Output string
|
||||
Unordered bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user