2013-09-11 17:51:07 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2013 The Perkeep Authors.
|
2013-09-11 17:51:07 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-10-22 15:11:36 +00:00
|
|
|
// This file adds the "test" subcommand to devcam, to run the full test suite.
|
|
|
|
|
2013-09-11 17:51:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2018-05-01 17:22:09 +00:00
|
|
|
"runtime"
|
2013-09-11 17:51:07 +00:00
|
|
|
"strings"
|
|
|
|
|
2018-04-22 19:35:28 +00:00
|
|
|
"perkeep.org/internal/osutil"
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/cmdmain"
|
2013-09-11 17:51:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type testCmd struct {
|
|
|
|
// start of flag vars
|
2014-10-02 05:03:53 +00:00
|
|
|
verbose bool
|
|
|
|
precommit bool
|
|
|
|
short bool
|
|
|
|
run string
|
2018-02-23 19:57:12 +00:00
|
|
|
sqlite bool
|
2013-09-11 17:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-03-06 21:39:14 +00:00
|
|
|
cmdmain.RegisterMode("test", func(flags *flag.FlagSet) cmdmain.CommandRunner {
|
2013-09-11 17:51:07 +00:00
|
|
|
cmd := new(testCmd)
|
|
|
|
flags.BoolVar(&cmd.short, "short", false, "Use '-short' with go test.")
|
2015-09-22 13:42:45 +00:00
|
|
|
flags.BoolVar(&cmd.precommit, "precommit", true, "Run the pre-commit githook as part of tests.")
|
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
|
|
|
flags.BoolVar(&cmd.verbose, "v", false, "Use '-v' (for verbose) with go test.")
|
|
|
|
flags.StringVar(&cmd.run, "run", "", "Use '-run' with go test.")
|
2018-02-23 19:57:12 +00:00
|
|
|
flags.BoolVar(&cmd.sqlite, "sqlite", false, "Run tests with SQLite built-in where relevant.")
|
2013-09-11 17:51:07 +00:00
|
|
|
return cmd
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testCmd) Usage() {
|
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
|
|
|
fmt.Fprintf(cmdmain.Stderr, "Usage: devcam test [test_opts] [targets]\n")
|
2013-09-11 17:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testCmd) Describe() string {
|
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
|
|
|
return "run the full test suite, or the tests in the specified target packages."
|
2013-09-11 17:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testCmd) RunCommand(args []string) error {
|
2014-10-02 05:03:53 +00:00
|
|
|
if c.precommit {
|
|
|
|
if err := c.runPrecommitHook(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 17:51:07 +00:00
|
|
|
if err := c.buildSelf(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-01-23 21:57:13 +00:00
|
|
|
if err := c.runTests(args); err != nil {
|
2013-09-11 17:51:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
println("PASS")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-22 19:13:28 +00:00
|
|
|
func (c *testCmd) env() *Env {
|
|
|
|
env := NewCopyEnv()
|
|
|
|
env.NoGo()
|
2018-02-23 19:57:12 +00:00
|
|
|
cmd := exec.Command("go", "env", "GOPATH")
|
2013-09-11 17:51:07 +00:00
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
2018-02-23 19:57:12 +00:00
|
|
|
panic("Cannot find GOPATH with 'go env GOPATH'")
|
2013-09-11 17:51:07 +00:00
|
|
|
}
|
2018-02-23 19:57:12 +00:00
|
|
|
gopath := strings.TrimSpace(string(out))
|
|
|
|
if gopath == "" {
|
|
|
|
panic("devcam test needs GOPATH to be set")
|
|
|
|
}
|
|
|
|
env.Set("GOPATH", gopath)
|
2018-05-01 17:22:09 +00:00
|
|
|
|
|
|
|
// Disable CGO on windows if it doesn't look like it's available.
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
if _, err := exec.LookPath("gcc"); err != nil {
|
|
|
|
if _, err := exec.LookPath("clang"); err != nil {
|
|
|
|
env.Set("CGO_ENABLED", "0")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-23 19:57:12 +00:00
|
|
|
return env
|
2013-09-11 17:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testCmd) buildSelf() error {
|
|
|
|
args := []string{
|
|
|
|
"install",
|
|
|
|
filepath.FromSlash("./dev/devcam"),
|
|
|
|
}
|
|
|
|
cmd := exec.Command("go", args...)
|
2013-09-22 19:13:28 +00:00
|
|
|
env := c.env()
|
|
|
|
cmd.Env = env.Flat()
|
2013-09-11 17:51:07 +00:00
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
return fmt.Errorf("Error building devcam: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2013-09-20 13:42:05 +00:00
|
|
|
|
2014-01-23 21:57:13 +00:00
|
|
|
func (c *testCmd) runTests(args []string) error {
|
|
|
|
targs := []string{"test"}
|
2018-02-23 19:57:12 +00:00
|
|
|
if c.sqlite {
|
2018-09-14 18:14:50 +00:00
|
|
|
targs = append(targs, "--tags=with_sqlite fake_android libsqlite3")
|
2015-09-25 14:27:43 +00:00
|
|
|
} else {
|
|
|
|
targs = append(targs, "--tags=fake_android")
|
2013-09-20 13:42:05 +00:00
|
|
|
}
|
|
|
|
if c.short {
|
2014-01-23 21:57:13 +00:00
|
|
|
targs = append(targs, "-short")
|
|
|
|
}
|
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
|
|
|
if c.verbose {
|
|
|
|
targs = append(targs, "-v")
|
|
|
|
}
|
|
|
|
if c.run != "" {
|
|
|
|
targs = append(targs, "-run="+c.run)
|
|
|
|
}
|
2014-01-23 21:57:13 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
targs = append(targs, args...)
|
|
|
|
} else {
|
|
|
|
targs = append(targs, []string{
|
2018-05-15 17:35:17 +00:00
|
|
|
"./internal/...",
|
2014-01-23 21:57:13 +00:00
|
|
|
"./pkg/...",
|
2018-04-21 18:04:53 +00:00
|
|
|
"./server/perkeepd",
|
2014-01-23 21:57:13 +00:00
|
|
|
"./cmd/...",
|
2018-05-15 17:35:17 +00:00
|
|
|
"./app/publisher/...",
|
2015-12-03 15:49:03 +00:00
|
|
|
"./misc/docker/...",
|
2018-04-25 19:19:04 +00:00
|
|
|
"./website/pk-web",
|
2014-01-23 21:57:13 +00:00
|
|
|
}...)
|
2013-09-20 13:42:05 +00:00
|
|
|
}
|
2013-09-22 19:13:28 +00:00
|
|
|
env := c.env()
|
|
|
|
env.Set("SKIP_DEP_TESTS", "1")
|
2014-01-23 21:57:13 +00:00
|
|
|
return runExec("go", targs, env)
|
2013-09-20 13:42:05 +00:00
|
|
|
}
|
2014-10-02 05:03:53 +00:00
|
|
|
|
|
|
|
func (c *testCmd) runPrecommitHook() error {
|
2018-04-22 19:35:28 +00:00
|
|
|
cmdBin, err := osutil.LookPathGopath("devcam")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out, err := exec.Command(cmdBin, "hook", "pre-commit", "test").CombinedOutput()
|
2014-10-02 05:03:53 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(string(out))
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|