diff --git a/DEPS.bzl b/DEPS.bzl index 030a95d1f2fe..114db13e156b 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -2103,6 +2103,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/dustin/go-humanize/com_github_dustin_go_humanize-v1.0.0.zip", ], ) + go_repository( + name = "com_github_dvyukov_go_fuzz", + build_file_proto_mode = "disable_global", + importpath = "github.com/dvyukov/go-fuzz", + sha256 = "0a4c4bc0a550c729115d74f6a636e5802894b33bc50aa8af99c4a70196d5990b", + strip_prefix = "github.com/dvyukov/go-fuzz@v0.0.0-20210103155950-6a8e9d1f2415", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/dvyukov/go-fuzz/com_github_dvyukov_go_fuzz-v0.0.0-20210103155950-6a8e9d1f2415.zip", + ], + ) go_repository( name = "com_github_eapache_go_resiliency", build_file_proto_mode = "disable_global", @@ -2173,6 +2183,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/elastic/gosigar/com_github_elastic_gosigar-v0.14.1.zip", ], ) + go_repository( + name = "com_github_elazarl_go_bindata_assetfs", + build_file_proto_mode = "disable_global", + importpath = "github.com/elazarl/go-bindata-assetfs", + sha256 = "ee91e4dedf0efd24ddf201e8f8b62f0b79a64efd0d205b30bcd9fa95f905cd15", + strip_prefix = "github.com/elazarl/go-bindata-assetfs@v1.0.1", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/elazarl/go-bindata-assetfs/com_github_elazarl_go_bindata_assetfs-v1.0.1.zip", + ], + ) go_repository( name = "com_github_elazarl_goproxy", build_file_proto_mode = "disable_global", @@ -4107,6 +4127,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/influxdata/usage-client/com_github_influxdata_usage_client-v0.0.0-20160829180054-6d3895376368.zip", ], ) + go_repository( + name = "com_github_irfansharif_recorder", + build_file_proto_mode = "disable_global", + importpath = "github.com/irfansharif/recorder", + sha256 = "4a2f085d5339eba18558059c51110de1ff6d9ab8389ece8818fd2f62b7b2e7ab", + strip_prefix = "github.com/irfansharif/recorder@v0.0.0-20211218081646-a21b46510fd6", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/irfansharif/recorder/com_github_irfansharif_recorder-v0.0.0-20211218081646-a21b46510fd6.zip", + ], + ) go_repository( name = "com_github_iris_contrib_blackfriday", build_file_proto_mode = "disable_global", @@ -4567,6 +4597,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/julienschmidt/httprouter/com_github_julienschmidt_httprouter-v1.3.0.zip", ], ) + go_repository( + name = "com_github_julusian_godocdown", + build_file_proto_mode = "disable_global", + importpath = "github.com/Julusian/godocdown", + sha256 = "1bd26f1d29b20d40b3eb0a5678691a2e6e153c473efe079b8b1bbd97a7cc1f57", + strip_prefix = "github.com/Julusian/godocdown@v0.0.0-20170816220326-6d19f8ff2df8", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/Julusian/godocdown/com_github_julusian_godocdown-v0.0.0-20170816220326-6d19f8ff2df8.zip", + ], + ) go_repository( name = "com_github_jung_kurt_gofpdf", build_file_proto_mode = "disable_global", @@ -6603,6 +6643,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/retailnext/hllpp/com_github_retailnext_hllpp-v1.0.1-0.20180308014038-101a6d2f8b52.zip", ], ) + go_repository( + name = "com_github_robertkrimen_godocdown", + build_file_proto_mode = "disable_global", + importpath = "github.com/robertkrimen/godocdown", + sha256 = "789ed4a63a797e0dbac7c358eafa8fec4c9885f67ee61da941af4bad2d8c3b55", + strip_prefix = "github.com/robertkrimen/godocdown@v0.0.0-20130622164427-0bfa04905481", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/robertkrimen/godocdown/com_github_robertkrimen_godocdown-v0.0.0-20130622164427-0bfa04905481.zip", + ], + ) go_repository( name = "com_github_robfig_cron_v3", build_file_proto_mode = "disable_global", @@ -7093,6 +7143,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stefanberger/go-pkcs11uri/com_github_stefanberger_go_pkcs11uri-v0.0.0-20201008174630-78d3cae3a980.zip", ], ) + go_repository( + name = "com_github_stephens2424_writerset", + build_file_proto_mode = "disable_global", + importpath = "github.com/stephens2424/writerset", + sha256 = "a5444ddf04cda5666c4511e5ca793a80372d560376c4193a1fa2e2294d0760dc", + strip_prefix = "github.com/stephens2424/writerset@v1.0.2", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stephens2424/writerset/com_github_stephens2424_writerset-v1.0.2.zip", + ], + ) go_repository( name = "com_github_stoewer_go_strcase", build_file_proto_mode = "disable_global", diff --git a/dev b/dev index 9c0955b0a165..728fd677b6c7 100755 --- a/dev +++ b/dev @@ -3,7 +3,7 @@ set -euo pipefail # Bump this counter to force rebuilding `dev` on all machines. -DEV_VERSION=12 +DEV_VERSION=13 THIS_DIR=$(cd "$(dirname "$0")" && pwd) BINARY_DIR=$THIS_DIR/bin/dev-versions diff --git a/go.mod b/go.mod index f44c1da5d695..226054889ef9 100644 --- a/go.mod +++ b/go.mod @@ -82,6 +82,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/goware/modvendor v0.5.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/irfansharif/recorder v0.0.0-20211218081646-a21b46510fd6 github.com/jackc/pgconn v1.10.0 github.com/jackc/pgproto3/v2 v2.1.1 github.com/jackc/pgtype v1.8.1 diff --git a/go.sum b/go.sum index c02982bba372..76513dacaee1 100644 --- a/go.sum +++ b/go.sum @@ -165,6 +165,7 @@ github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtix github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM= +github.com/Julusian/godocdown v0.0.0-20170816220326-6d19f8ff2df8/go.mod h1:INZr5t32rG59/5xeltqoCJoNY7e5x/3xoY9WSWVWg74= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic= github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= @@ -637,6 +638,7 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3 github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q= github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= @@ -650,6 +652,7 @@ github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaB github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/elastic/gosigar v0.14.1 h1:T0aQ7n/n2ZA9W7DmAnj60v+qzqKERdBgJBO1CG2W6rc= github.com/elastic/gosigar v0.14.1/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= +github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/dot v0.15.0 h1:XDBW0Xco1QNyRb33cqLe10cT04yMWL1XpCZfa98Q6Og= @@ -1229,6 +1232,8 @@ github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bS github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/tdigest v0.0.2-0.20210216194612-fc98d27c9e8b/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= +github.com/irfansharif/recorder v0.0.0-20211218081646-a21b46510fd6 h1:fwL5Wt/OpP14udrdhV+INmmRES4GWoPWqHamttadwKU= +github.com/irfansharif/recorder v0.0.0-20211218081646-a21b46510fd6/go.mod h1:0vDkLIc8rDX+zYp5wX/DG5MAWaHBAqmtXH/SE54vhpY= github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI= github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0= github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI= @@ -1841,6 +1846,7 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5X github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= +github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -1952,6 +1958,7 @@ github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8= +github.com/stephens2424/writerset v1.0.2/go.mod h1:aS2JhsMn6eA7e82oNmW4rfsgAOp9COBTTl8mzkwADnc= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= @@ -2507,6 +2514,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/cmd/dev/BUILD.bazel b/pkg/cmd/dev/BUILD.bazel index f9f7fd8edb3f..90592d536b55 100644 --- a/pkg/cmd/dev/BUILD.bazel +++ b/pkg/cmd/dev/BUILD.bazel @@ -42,16 +42,17 @@ go_test( name = "dev_test", srcs = [ "datadriven_test.go", - "dev_test.go", + "recorderdriven_test.go", ], data = glob(["testdata/**"]), embed = [":dev_lib"], deps = [ "//pkg/cmd/dev/io/exec", "//pkg/cmd/dev/io/os", - "//pkg/cmd/dev/recording", "//pkg/testutils", + "@com_github_alessio_shellescape//:shellescape", "@com_github_cockroachdb_datadriven//:datadriven", + "@com_github_irfansharif_recorder//:recorder", "@com_github_stretchr_testify//require", ], ) diff --git a/pkg/cmd/dev/bench.go b/pkg/cmd/dev/bench.go index 1dfd42bad544..35f5fc54d98f 100644 --- a/pkg/cmd/dev/bench.go +++ b/pkg/cmd/dev/bench.go @@ -12,8 +12,6 @@ package main import ( "fmt" - "path/filepath" - "sort" "strings" "github.com/spf13/cobra" @@ -42,6 +40,7 @@ func makeBenchCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Com benchCmd.Flags().BoolP(vFlag, "v", false, "show benchmark process output") benchCmd.Flags().BoolP(showLogsFlag, "", false, "show crdb logs in-line") benchCmd.Flags().Int(countFlag, 1, "run benchmark n times") + benchCmd.Flags().Bool(ignoreCacheFlag, false, "ignore cached benchmark runs") // We use a string flag for benchtime instead of a duration; the go test // runner accepts input of the form "Nx" to run the benchmark N times (see // `go help testflag`). @@ -55,14 +54,15 @@ func (d *dev) bench(cmd *cobra.Command, commandLine []string) error { pkgs, additionalBazelArgs := splitArgsAtDash(cmd, commandLine) ctx := cmd.Context() var ( - filter = mustGetFlagString(cmd, filterFlag) - timeout = mustGetFlagDuration(cmd, timeoutFlag) - short = mustGetFlagBool(cmd, shortFlag) - showLogs = mustGetFlagBool(cmd, showLogsFlag) - verbose = mustGetFlagBool(cmd, vFlag) - count = mustGetFlagInt(cmd, countFlag) - benchTime = mustGetFlagString(cmd, benchTimeFlag) - benchMem = mustGetFlagBool(cmd, benchMemFlag) + filter = mustGetFlagString(cmd, filterFlag) + ignoreCache = mustGetFlagBool(cmd, ignoreCacheFlag) + timeout = mustGetFlagDuration(cmd, timeoutFlag) + short = mustGetFlagBool(cmd, shortFlag) + showLogs = mustGetFlagBool(cmd, showLogsFlag) + verbose = mustGetFlagBool(cmd, vFlag) + count = mustGetFlagInt(cmd, countFlag) + benchTime = mustGetFlagString(cmd, benchTimeFlag) + benchMem = mustGetFlagBool(cmd, benchMemFlag) ) // Enumerate all benches to run. @@ -70,86 +70,76 @@ func (d *dev) bench(cmd *cobra.Command, commandLine []string) error { // Empty `dev bench` does the same thing as `dev bench pkg/...` pkgs = append(pkgs, "pkg/...") } - benchesMap := make(map[string]bool) + + var args []string + args = append(args, "test") + args = append(args, mustGetRemoteCacheArgs(remoteCacheAddr)...) + if numCPUs != 0 { + args = append(args, fmt.Sprintf("--local_cpu_resources=%d", numCPUs)) + } + if timeout > 0 { + args = append(args, fmt.Sprintf("--test_timeout=%d", int(timeout.Seconds()))) + } + + var testTargets []string for _, pkg := range pkgs { - dir, isRecursive, tag, err := d.parsePkg(pkg) - if err != nil { - return err + pkg = strings.TrimPrefix(pkg, "//") + pkg = strings.TrimPrefix(pkg, "./") + pkg = strings.TrimRight(pkg, "/") + + if !strings.HasPrefix(pkg, "pkg/") { + return fmt.Errorf("malformed package %q, expecting %q", pkg, "pkg/{...}") } - if isRecursive { - // Use `git grep` to find all Go files that contain benchmark tests. - out, err := d.exec.CommandContextSilent(ctx, "git", "grep", "-l", "^func Benchmark", "--", dir+"/*_test.go") - if err != nil { - return err - } - files := strings.Split(strings.TrimSpace(string(out)), "\n") - for _, file := range files { - dir, _ = filepath.Split(file) - dir = strings.TrimSuffix(dir, "/") - benchesMap[dir] = true - } - } else if tag != "" { - return fmt.Errorf("malformed package %q, tags not supported in 'bench' command", pkg) + + var target string + if strings.Contains(pkg, ":") { + // For parity with bazel, we allow specifying named build targets. + target = pkg } else { - benchesMap[dir] = true + target = fmt.Sprintf("%s:all", pkg) } + testTargets = append(testTargets, target) } - // De-duplicate and sort the list of benches to run. - var benches []string - for pkg := range benchesMap { - benches = append(benches, pkg) + + args = append(args, testTargets...) + if ignoreCache { + args = append(args, "--nocache_test_results") } - sort.Slice(benches, func(i, j int) bool { return benches[i] < benches[j] }) - var argsBase []string - // NOTE the --config=test here. It's very important we compile the test binary with the - // appropriate stuff (gotags, etc.) - argsBase = append(argsBase, "run", "--config=test", "--test_sharding_strategy=disabled") - argsBase = append(argsBase, mustGetRemoteCacheArgs(remoteCacheAddr)...) - if numCPUs != 0 { - argsBase = append(argsBase, fmt.Sprintf("--local_cpu_resources=%d", numCPUs)) + if filter == "" { + args = append(args, "--test_arg", "-test.bench=.") + } else { + args = append(args, "--test_arg", fmt.Sprintf("-test.bench=%s", filter)) + } + if short { + args = append(args, "--test_arg", "-test.short") } if verbose { - argsBase = append(argsBase, "--test_arg", "-test.v") + args = append(args, "--test_arg", "-test.v") } if showLogs { - argsBase = append(argsBase, "--test_arg", "-show-logs") + args = append(args, "--test_arg", "-show-logs") } if count != 1 { - argsBase = append(argsBase, "--test_arg", fmt.Sprintf("-test.count=%d", count)) + args = append(args, "--test_arg", fmt.Sprintf("-test.count=%d", count)) } if benchTime != "" { - argsBase = append(argsBase, "--test_arg", fmt.Sprintf("-test.benchtime=%s", benchTime)) + args = append(args, "--test_arg", fmt.Sprintf("-test.benchtime=%s", benchTime)) } if benchMem { - argsBase = append(argsBase, "--test_arg", "-test.benchmem") + args = append(args, "--test_arg", "-test.benchmem") } - for _, bench := range benches { - args := make([]string, len(argsBase)) - copy(args, argsBase) - base := filepath.Base(bench) - target := "//" + bench + ":" + base + "_test" - args = append(args, target) - args = append(args, additionalBazelArgs...) - args = append(args, "--", "-test.run=-") - if filter == "" { - args = append(args, "-test.bench=.") - } else { - args = append(args, "-test.bench="+filter) - } - if timeout > 0 { - args = append(args, fmt.Sprintf("-test.timeout=%s", timeout.String())) - } - if short { - args = append(args, "-test.short", "-test.benchtime=1ns") - } - logCommand("bazel", args...) - err := d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...) - if err != nil { - return err + { // Handle test output flags. + testOutputArgs := []string{"--test_output", "errors"} + if verbose || showLogs { + testOutputArgs = []string{"--test_output", "all"} } + args = append(args, testOutputArgs...) } - return nil + args = append(args, additionalBazelArgs...) + + logCommand("bazel", args...) + return d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...) } diff --git a/pkg/cmd/dev/builder.go b/pkg/cmd/dev/builder.go index 5c27eb07fe5b..fed94f379ce3 100644 --- a/pkg/cmd/dev/builder.go +++ b/pkg/cmd/dev/builder.go @@ -41,7 +41,7 @@ func makeBuilderCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.C func (d *dev) builder(cmd *cobra.Command, extraArgs []string) error { ctx := cmd.Context() volume := mustGetFlagString(cmd, volumeFlag) - args, err := d.getDockerRunArgs(ctx, volume, true) + args, err := d.getDockerRunArgs(ctx, volume, false) args = append(args, extraArgs...) if err != nil { return err diff --git a/pkg/cmd/dev/datadriven_test.go b/pkg/cmd/dev/datadriven_test.go index 02bb7d88a83c..46a33a25226d 100644 --- a/pkg/cmd/dev/datadriven_test.go +++ b/pkg/cmd/dev/datadriven_test.go @@ -16,99 +16,104 @@ import ( "io" "io/ioutil" "log" - stdos "os" - "path/filepath" - "strings" "testing" + "github.com/alessio/shellescape" "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/exec" "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/os" - "github.com/cockroachdb/cockroach/pkg/cmd/dev/recording" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/datadriven" "github.com/stretchr/testify/require" ) -// TestDataDriven makes use of datadriven to play back all operations executed -// by individual `dev` invocations. The testcases are defined under testdata/*, -// where each test files corresponds to a recording capture found in -// testdata/recording/*. +const ( + crdbCheckoutPlaceholder = "crdb-checkout" + sandboxPlaceholder = "sandbox" +) + +// TestDataDriven makes use of datadriven to capture all operations executed by +// individual dev invocations. The testcases are defined under +// testdata/datadriven/*. // // DataDriven divvies up these files as subtests, so individual "files" are // runnable through: // -// go test -run TestDataDriven/ +// dev test pkg/cmd/dev -f TestDataDrivenDriven/ [--rewrite] +// OR go test ./pkg/cmd/dev -run TestDataDrivenDriven/ [-rewrite] // -// Recordings are used to mock out "system" behavior. During these test runs -// (unless -record is specified), attempts to shell out to `bazel` or perform -// other OS operations are intercepted and responses are constructed using -// recorded data. +// NB: See commentary on TestRecorderDriven to see how they compare. +// TestDataDriven is well suited for exercising flows that don't depend on +// reading external state in order to function (simply translating a `dev test +// ` to its corresponding bazel invocation for e.g.). It's not well +// suited for flows that do (reading a list of go files in the bazel generated +// sandbox and copying them over one-by-one). func TestDataDriven(t *testing.T) { verbose := testing.Verbose() - testdata := testutils.TestDataPath(t) + testdata := testutils.TestDataPath(t, "datadriven") datadriven.Walk(t, testdata, func(t *testing.T, path string) { - if strings.HasPrefix(path, filepath.Join(testdata, "recording")) { - return - } - - dir, file := filepath.Split(path) - recordingPath := filepath.Join(dir, "recording", file) // path to the recording, if any - // We'll match against printed logs for datadriven. var logger io.ReadWriter = bytes.NewBufferString("") - var exopts []exec.Option - var osopts []os.Option - - exopts = append(exopts, exec.WithLogger(log.New(logger, "", 0))) - osopts = append(osopts, os.WithLogger(log.New(logger, "", 0))) - - if !verbose { - // Suppress all internal output unless told otherwise. - exopts = append(exopts, exec.WithStdOutErr(ioutil.Discard, ioutil.Discard)) + execOpts := []exec.Option{ + exec.WithLogger(log.New(logger, "", 0)), + exec.WithDryrun(), + exec.WithIntercept(workspaceCmd(), crdbCheckoutPlaceholder), + exec.WithIntercept(bazelbinCmd(), sandboxPlaceholder), + } + osOpts := []os.Option{ + os.WithLogger(log.New(logger, "", 0)), + os.WithDryrun(), } - frecording, err := stdos.OpenFile(recordingPath, stdos.O_RDONLY, 0600) - require.NoError(t, err) - defer func() { - require.NoError(t, frecording.Close()) - }() + if !verbose { // suppress all internal output unless told otherwise + execOpts = append(execOpts, exec.WithStdOutErr(ioutil.Discard, ioutil.Discard)) + } - r := recording.WithReplayFrom(frecording, recordingPath) - exopts = append(exopts, exec.WithRecording(r)) - osopts = append(osopts, os.WithRecording(r)) + devExec := exec.New(execOpts...) + devOS := os.New(osOpts...) - devExec := exec.New(exopts...) - devOS := os.New(osopts...) + // TODO(irfansharif): Because these tests are run in dry-run mode, if + // "accidentally" adding a test for a mixed-io command (see top-level test + // comment), it may appear as a test failure where the output of a + // successful shell-out attempt returns an empty response, maybe resulting + // in NPEs. We could catch these panics/errors here and suggest a more + // informative error to test authors. datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string { dev := makeDevCmd() - dev.exec = devExec - dev.os = devOS + dev.exec, dev.os = devExec, devOS + dev.knobs.skipDoctorCheck = true + dev.knobs.devBinOverride = "dev" + dev.log = log.New(logger, "", 0) if !verbose { dev.cli.SetErr(ioutil.Discard) dev.cli.SetOut(ioutil.Discard) } - switch d.Cmd { - case "dev": - var args []string - for _, cmdArg := range d.CmdArgs { - args = append(args, cmdArg.Key) - if len(cmdArg.Vals) != 0 { - args = append(args, cmdArg.Vals[0]) - } + require.Equalf(t, d.Cmd, "dev", "unknown command: %s", d.Cmd) + var args []string + for _, cmdArg := range d.CmdArgs { + args = append(args, cmdArg.Key) + if len(cmdArg.Vals) != 0 { + args = append(args, cmdArg.Vals[0]) } - dev.cli.SetArgs(args) - require.NoError(t, dev.cli.Execute()) - - logs, err := ioutil.ReadAll(logger) - require.NoError(t, err) - - return string(logs) - default: - return fmt.Sprintf("unknown command: %s", d.Cmd) } + dev.cli.SetArgs(args) + if err := dev.cli.Execute(); err != nil { + return fmt.Sprintf("err: %s", err) + } + + logs, err := ioutil.ReadAll(logger) + require.NoError(t, err) + return string(logs) }) }) } + +func workspaceCmd() string { + return fmt.Sprintf("bazel %s", shellescape.QuoteCommand([]string{"info", "workspace", "--color=no"})) +} + +func bazelbinCmd() string { + return fmt.Sprintf("bazel %s", shellescape.QuoteCommand([]string{"info", "bazel-bin", "--color=no"})) +} diff --git a/pkg/cmd/dev/dev.go b/pkg/cmd/dev/dev.go index f4c32a104794..e870bd9be0e1 100644 --- a/pkg/cmd/dev/dev.go +++ b/pkg/cmd/dev/dev.go @@ -25,6 +25,11 @@ type dev struct { cli *cobra.Command os *os.OS exec *exec.Exec + + knobs struct { // testing knobs + skipDoctorCheck bool + devBinOverride string + } } func makeDevCmd() *dev { @@ -129,7 +134,7 @@ Typical usage: ret.cli.PersistentFlags().BoolVar(&debugVar, "debug", false, "enable debug logging for dev") ret.cli.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { isDoctor := cmd.Name() == "doctor" - if !isTesting && !isDoctor { + if !isDoctor { if err := ret.checkDoctorStatus(cmd.Context()); err != nil { return err } diff --git a/pkg/cmd/dev/dev_test.go b/pkg/cmd/dev/dev_test.go deleted file mode 100644 index 65882d7df1c1..000000000000 --- a/pkg/cmd/dev/dev_test.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2021 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package main - -import ( - "bytes" - "io" - "log" - "strings" - "testing" - - "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/exec" - "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/os" - "github.com/cockroachdb/cockroach/pkg/cmd/dev/recording" - "github.com/stretchr/testify/require" -) - -func init() { - isTesting = true -} - -func TestSetupPath(t *testing.T) { - rec := `getenv PATH ----- -/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin - -which cc ----- -/usr/local/opt/ccache/libexec/cc - -readlink /usr/local/opt/ccache/libexec/cc ----- -../bin/ccache - -export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin ----- - -` - r := recording.WithReplayFrom(strings.NewReader(rec), "TestSetupPath") - var logger io.ReadWriter = bytes.NewBufferString("") - var exopts []exec.Option - exopts = append(exopts, exec.WithRecording(r)) - exopts = append(exopts, exec.WithLogger(log.New(logger, "", 0))) - var osopts []os.Option - osopts = append(osopts, os.WithRecording(r)) - osopts = append(osopts, os.WithLogger(log.New(logger, "", 0))) - devExec := exec.New(exopts...) - devOS := os.New(osopts...) - dev := makeDevCmd() - dev.exec = devExec - dev.os = devOS - - require.NoError(t, setupPath(dev)) -} diff --git a/pkg/cmd/dev/doctor.go b/pkg/cmd/dev/doctor.go index 1e99d379f742..e5c25047682a 100644 --- a/pkg/cmd/dev/doctor.go +++ b/pkg/cmd/dev/doctor.go @@ -38,6 +38,10 @@ const ( ) func (d *dev) checkDoctorStatus(ctx context.Context) error { + if d.knobs.skipDoctorCheck { + return nil + } + dir, err := d.getWorkspace(ctx) if err != nil { return err @@ -230,12 +234,13 @@ Please add one of the following to your %s/.bazelrc.user:`, workspace) } } - if success { - if err := d.writeDoctorStatus(ctx, d.exec); err != nil { - return err - } - log.Println("You are ready to build :)") - return nil + if !success { + return errors.New("please address the errors described above and try again") } - return errors.New("please address the errors described above and try again") + + if err := d.writeDoctorStatus(ctx, d.exec); err != nil { + return err + } + log.Println("You are ready to build :)") + return nil } diff --git a/pkg/cmd/dev/generate.go b/pkg/cmd/dev/generate.go index 6401407db1b2..8e72452595c4 100644 --- a/pkg/cmd/dev/generate.go +++ b/pkg/cmd/dev/generate.go @@ -90,10 +90,14 @@ func (d *dev) generateBazel(cmd *cobra.Command) error { executable := filepath.Join(workspace, "build", "bazelutil", "bazel-generate.sh") env := os.Environ() if mirror { - env = append(env, "COCKROACH_BAZEL_CAN_MIRROR=1") + envvar := "COCKROACH_BAZEL_CAN_MIRROR=1" + d.log.Printf("export %s", envvar) + env = append(env, envvar) } if force { - env = append(env, "COCKROACH_BAZEL_FORCE_GENERATE=1") + envvar := "COCKROACH_BAZEL_FORCE_GENERATE=1" + d.log.Printf("export %s", envvar) + env = append(env, envvar) } return d.exec.CommandContextWithEnv(ctx, env, executable) } diff --git a/pkg/cmd/dev/io/exec/BUILD.bazel b/pkg/cmd/dev/io/exec/BUILD.bazel index 548614278048..a91324f32200 100644 --- a/pkg/cmd/dev/io/exec/BUILD.bazel +++ b/pkg/cmd/dev/io/exec/BUILD.bazel @@ -6,7 +6,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/exec", visibility = ["//visibility:public"], deps = [ - "//pkg/cmd/dev/recording", "@com_github_alessio_shellescape//:shellescape", + "@com_github_irfansharif_recorder//:recorder", ], ) diff --git a/pkg/cmd/dev/io/exec/exec.go b/pkg/cmd/dev/io/exec/exec.go index 5c68687dc603..40bfb9db9fb2 100644 --- a/pkg/cmd/dev/io/exec/exec.go +++ b/pkg/cmd/dev/io/exec/exec.go @@ -21,17 +21,31 @@ import ( "strings" "github.com/alessio/shellescape" - "github.com/cockroachdb/cockroach/pkg/cmd/dev/recording" + "github.com/irfansharif/recorder" ) -// Exec is a convenience wrapper around the stdlib os/exec package. It lets us -// mock all instances where we shell out for tests. +// Exec is a convenience wrapper around the stdlib os/exec package. It lets us: +// +// (a) mock all instances where we shell out, for tests, and +// (b) capture all instances of shelling out that take place during execution +// +// We achieve (a) by embedding a Recorder, and either replaying from it if +// configured to do so, or "doing the real thing" and recording the fact into +// the Recorder for future playback. +// +// For (b), each operation is logged (if configured to do so). These messages +// can be captured by the caller and compared against what is expected. type Exec struct { dir string logger *log.Logger stdout, stderr io.Writer blocking bool - *recording.Recording + *recorder.Recorder + + knobs struct { // testing knobs + dryrun bool + intercept map[string]string // maps commands to outputs + } } // New returns a new Exec with the given options. @@ -76,10 +90,10 @@ func WithStdOutErr(stdout, stderr io.Writer) func(e *Exec) { } } -// WithRecording configures Exec to use the provided recording. -func WithRecording(r *recording.Recording) func(e *Exec) { +// WithRecorder configures Exec to use the provided recorder. +func WithRecorder(r *recorder.Recorder) func(e *Exec) { return func(e *Exec) { - e.Recording = r + e.Recorder = r } } @@ -91,8 +105,43 @@ func (e *Exec) AsNonBlocking() *Exec { return &out } +// WithWorkingDir configures Exec to use the provided working directory. +func WithWorkingDir(dir string) func(e *Exec) { + return func(e *Exec) { + e.dir = dir + } +} + +// WithDryrun configures Exec to run in dryrun mode. +func WithDryrun() func(e *Exec) { + return func(e *Exec) { + e.knobs.dryrun = true + } +} + +// WithIntercept configures Exec to intercept the given command and return the +// given output instead. +func WithIntercept(command, output string) func(e *Exec) { + return func(e *Exec) { + if e.knobs.intercept == nil { + e.knobs.intercept = make(map[string]string) + } + e.knobs.intercept[command] = output + } +} + +// LookPath wraps around exec.LookPath, which searches for an executable named +// file in the directories named by the PATH environment variable. +func (e *Exec) LookPath(file string) (string, error) { + command := fmt.Sprintf("which %s", file) + e.logger.Print(command) + return e.Next(command, func() (string, error) { + return exec.LookPath(file) + }) +} + // CommandContextSilent is like CommandContext, but does not take over -// stdout/stderr. It's to be used for "internal" operations, and always blocks. +// stdout/stderr. It's used for "internal" operations, and always blocks. func (e *Exec) CommandContextSilent( ctx context.Context, name string, args ...string, ) ([]byte, error) { @@ -135,8 +184,7 @@ func (e *Exec) commandContextInheritingStdStreamsImpl( } e.logger.Print(command) - if e.Recording == nil { - // Do the real thing. + _, err := e.Next(command, func() (string, error) { cmd := exec.CommandContext(ctx, name, args...) cmd.Stdin = os.Stdin cmd.Stdout = e.stdout @@ -145,40 +193,19 @@ func (e *Exec) commandContextInheritingStdStreamsImpl( cmd.Env = env if err := cmd.Start(); err != nil { - return err + return "", err } if e.blocking { if err := cmd.Wait(); err != nil { - return err + return "", err } } - return nil - } + return "", nil + }) - _, err := e.replay(command) return err } -// LookPath wraps around exec.LookPath, which searches for an executable named -// file in the directories named by the PATH environment variable. -func (e *Exec) LookPath(path string) (string, error) { - command := fmt.Sprintf("which %s", path) - e.logger.Print(command) - - if e.Recording == nil { - // Do the real thing. - var err error - fullPath, err := exec.LookPath(path) - if err != nil { - return "", err - } - return fullPath, nil - } - - ret, err := e.replay(command) - return ret, err -} - func (e *Exec) commandContextImpl( ctx context.Context, stdin io.Reader, silent bool, name string, args ...string, ) ([]byte, error) { @@ -190,10 +217,9 @@ func (e *Exec) commandContextImpl( } e.logger.Print(command) - var buffer bytes.Buffer - if e.Recording == nil { - // Do the real thing. + output, err := e.Next(command, func() (string, error) { cmd := exec.CommandContext(ctx, name, args...) + var buffer bytes.Buffer if silent { cmd.Stdout = &buffer cmd.Stderr = nil @@ -207,37 +233,29 @@ func (e *Exec) commandContextImpl( cmd.Dir = e.dir if err := cmd.Start(); err != nil { - return nil, err + return "", err } if err := cmd.Wait(); err != nil { - return nil, err + return "", err } - return buffer.Bytes(), nil - } - - output, err := e.replay(command) + return buffer.String(), nil + }) if err != nil { return nil, err } - return []byte(output), nil } -// replay replays the specified command, erroring out if it's mismatched with -// what the recording plays back next. It returns the recorded output. -func (e *Exec) replay(command string) (output string, err error) { - found, err := e.Recording.Next(func(op recording.Operation) error { - if op.Command != command { - return fmt.Errorf("expected %q, got %q", op.Command, command) - } - output = op.Output - return nil - }) - if err != nil { - return "", err +// Next is a thin interceptor for all exec activity, running them through +// testing knobs first. +func (e *Exec) Next(command string, f func() (output string, err error)) (string, error) { + if e.knobs.dryrun { + return "", nil } - if !found { - return "", fmt.Errorf("recording for %q not found", command) + if e.knobs.intercept != nil { + if output, ok := e.knobs.intercept[command]; ok { + return output, nil + } } - return output, nil + return e.Recorder.Next(command, f) } diff --git a/pkg/cmd/dev/io/os/BUILD.bazel b/pkg/cmd/dev/io/os/BUILD.bazel index 44d20af907f5..0ddfe1abaea4 100644 --- a/pkg/cmd/dev/io/os/BUILD.bazel +++ b/pkg/cmd/dev/io/os/BUILD.bazel @@ -6,6 +6,6 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/os", visibility = ["//visibility:public"], deps = [ - "//pkg/cmd/dev/recording", + "@com_github_irfansharif_recorder//:recorder", ], ) diff --git a/pkg/cmd/dev/io/os/os.go b/pkg/cmd/dev/io/os/os.go index 526a34358a78..cd3da9f83361 100644 --- a/pkg/cmd/dev/io/os/os.go +++ b/pkg/cmd/dev/io/os/os.go @@ -19,16 +19,31 @@ import ( "os" "os/user" "path/filepath" + "strconv" "strings" - "github.com/cockroachdb/cockroach/pkg/cmd/dev/recording" + "github.com/irfansharif/recorder" ) -// OS is a convenience wrapper around the stdlib os package. It lets us -// mock operating system calls in tests. +// OS is a convenience wrapper around the stdlib os package. It lets us: +// +// (a) mock operating system calls in tests, and +// (b) capture the set of calls that take place during execution +// +// We achieve (a) by embedding a Recorder, and either replaying from it if +// configured to do so, or "doing the real thing" and recording the fact into +// the Recorder for future playback. +// +// For (b), each operation is logged (if configured to do so). These messages +// can be captured by the caller and compared against what is expected. type OS struct { + dir string logger *log.Logger - *recording.Recording + *recorder.Recorder + + knobs struct { // testing knobs + dryrun bool + } } // New constructs a new OS handle, configured with the provided options. @@ -62,10 +77,24 @@ func WithLogger(logger *log.Logger) func(o *OS) { } } -// WithRecording configures OS to use the provided recording. -func WithRecording(r *recording.Recording) func(o *OS) { +// WithRecorder configures OS to use the provided recorder. +func WithRecorder(r *recorder.Recorder) func(o *OS) { return func(o *OS) { - o.Recording = r + o.Recorder = r + } +} + +// WithWorkingDir configures OS to use the provided working directory. +func WithWorkingDir(dir string) func(o *OS) { + return func(o *OS) { + o.dir = dir + } +} + +// WithDryrun configures OS to run in dryrun mode. +func WithDryrun() func(e *OS) { + return func(e *OS) { + e.knobs.dryrun = true } } @@ -75,15 +104,9 @@ func (o *OS) MkdirAll(path string) error { command := fmt.Sprintf("mkdir %s", path) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - if err := os.MkdirAll(path, 0755); err != nil { - return err - } - return nil - } - - _, err := o.replay(command) + _, err := o.Next(command, func() (output string, err error) { + return "", os.MkdirAll(path, 0755) + }) return err } @@ -92,15 +115,12 @@ func (o *OS) Remove(path string) error { command := fmt.Sprintf("rm %s", path) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. + _, err := o.Next(command, func() (output string, err error) { if err := os.Remove(path); err != nil && !os.IsNotExist(err) { - return err + return "", err } - return nil - } - - _, err := o.replay(command) + return "", nil + }) return err } @@ -110,15 +130,9 @@ func (o *OS) Symlink(to, from string) error { command := fmt.Sprintf("ln -s %s %s", to, from) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - if err := os.Symlink(to, from); err != nil { - return err - } - return nil - } - - _, err := o.replay(command) + _, err := o.Next(command, func() (output string, err error) { + return "", os.Symlink(to, from) + }) return err } @@ -128,13 +142,13 @@ func (o OS) Getenv(key string) string { command := fmt.Sprintf("getenv %s", key) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - return os.Getenv(key) + output, err := o.Next(command, func() (output string, err error) { + return os.Getenv(key), nil + }) + if err != nil { + log.Fatalf("%v", err) } - - ret, _ := o.replay(command) - return ret + return output } // Setenv wraps around os.Setenv, which sets the value of the environment @@ -143,12 +157,9 @@ func (o *OS) Setenv(key, value string) error { command := fmt.Sprintf("export %s=%s", key, value) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - return os.Setenv(key, value) - } - - _, err := o.replay(command) + _, err := o.Next(command, func() (output string, err error) { + return "", os.Setenv(key, value) + }) return err } @@ -158,13 +169,9 @@ func (o *OS) Readlink(filename string) (string, error) { command := fmt.Sprintf("readlink %s", filename) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. + return o.Next(command, func() (output string, err error) { return os.Readlink(filename) - } - - ret, err := o.replay(command) - return ret, err + }) } // IsDir wraps around os.Stat, which returns the os.FileInfo of the named @@ -174,17 +181,18 @@ func (o *OS) IsDir(dirname string) (bool, error) { command := fmt.Sprintf("find %s -type d", dirname) o.logger.Print(command) - if o.Recording == nil { + output, err := o.Next(command, func() (output string, err error) { // Do the real thing. stat, err := os.Stat(dirname) if err != nil { - return false, err + return "", err } - return stat.IsDir(), nil + return strconv.FormatBool(stat.IsDir()), nil + }) + if err != nil { + return false, err } - - res, err := o.replay(command) - return err == nil && res != "", err + return strconv.ParseBool(strings.TrimSpace(output)) } // ReadFile wraps around ioutil.ReadFile, reading a file from disk and @@ -193,31 +201,24 @@ func (o *OS) ReadFile(filename string) (string, error) { command := fmt.Sprintf("cat %s", filename) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. + return o.Next(command, func() (output string, err error) { buf, err := ioutil.ReadFile(filename) if err != nil { return "", err } return string(buf), nil - } - - ret, err := o.replay(command) - return ret, err + }) } // WriteFile wraps around ioutil.ReadFile, writing the given contents to // the given file on disk. func (o *OS) WriteFile(filename, contents string) error { - command := fmt.Sprintf("echo %s > %s", strings.TrimSpace(contents), filename) + command := fmt.Sprintf("echo %q > %s", strings.TrimSpace(contents[:10]), filename) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - return ioutil.WriteFile(filename, []byte(contents), 0666) - } - - _, err := o.replay(command) + _, err := o.Next(command, func() (output string, err error) { + return "", ioutil.WriteFile(filename, []byte(contents), 0666) + }) return err } @@ -231,42 +232,39 @@ func (o *OS) CopyFile(src, dst string) error { command := fmt.Sprintf("cp %s %s", src, dst) o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. + _, err := o.Next(command, func() (output string, err error) { srcFile, err := os.Open(src) if err != nil { - return err + return "", err } defer func() { _ = srcFile.Close() }() originalDstFile, err := os.Open(dst) if err != nil && !os.IsNotExist(err) { - return err + return "", err } else if err == nil { defer func() { _ = originalDstFile.Close() }() srcInfo, err := srcFile.Stat() if err != nil { - return err + return "", err } dstInfo, err := originalDstFile.Stat() if err != nil { - return err + return "", err } // If src points to the same file as dst, there's // nothing to be done. if os.SameFile(srcInfo, dstInfo) { - return nil + return "", nil } } dstFile, err := os.Create(dst) if err != nil { - return err + return "", err } defer func() { _ = dstFile.Close() }() _, err = io.Copy(dstFile, srcFile) - return err - } - - _, err := o.replay(command) + return "", err + }) return err } @@ -276,12 +274,11 @@ func (o *OS) ListFilesWithSuffix(root, suffix string) ([]string, error) { command := fmt.Sprintf("find %s -name *%s", root, suffix) o.logger.Print(command) - var ret []string - if o.Recording == nil { - // Do the real thing. - err := filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { - // If there's an error walking the tree, throw it away -- there's nothing - // interesting we can do with it. + output, err := o.Next(command, func() (output string, err error) { + var ret []string + if err := filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { + // If there's an error walking the tree, throw it away -- there's + // nothing interesting we can do with it. if err != nil || info.IsDir() { //nolint:returnerrcheck return nil @@ -290,18 +287,16 @@ func (o *OS) ListFilesWithSuffix(root, suffix string) ([]string, error) { ret = append(ret, path) } return nil - }) - if err != nil { - return nil, err + }); err != nil { + return "", err } - return ret, nil - } - lines, err := o.replay(command) + return fmt.Sprintf("%s\n", strings.Join(ret, "\n")), nil + }) if err != nil { return nil, err } - return strings.Split(strings.TrimSpace(lines), "\n"), nil + return strings.Split(strings.TrimSpace(output), "\n"), nil } // CurrentUserAndGroup returns the user and effective group. @@ -309,41 +304,26 @@ func (o *OS) CurrentUserAndGroup() (uid string, gid string, err error) { command := "id" o.logger.Print(command) - if o.Recording == nil { - // Do the real thing. - var currentUser *user.User - currentUser, err = user.Current() + output, err := o.Next(command, func() (output string, err error) { + current, err := user.Current() if err != nil { - return + return "", err } - uid = currentUser.Uid - gid = currentUser.Gid - return - } - - output, err := o.replay(command) + return fmt.Sprintf("%s:%s", current.Uid, current.Gid), nil + }) if err != nil { - return + return "", "", err } + ids := strings.Split(strings.TrimSpace(output), ":") return ids[0], ids[1], nil } -// replay replays the specified command, erroring out if it's mismatched with -// what the recording plays back next. It returns the recorded output. -func (o *OS) replay(command string) (output string, err error) { - found, err := o.Recording.Next(func(op recording.Operation) error { - if op.Command != command { - return fmt.Errorf("expected %q, got %q", op.Command, command) - } - output = op.Output - return nil - }) - if err != nil { - return "", err - } - if !found { - return "", fmt.Errorf("recording for %q not found", command) +// Next is a thin interceptor for all os activity, running them through +// testing knobs first. +func (o *OS) Next(command string, f func() (output string, err error)) (string, error) { + if o.knobs.dryrun { + return "", nil } - return output, nil + return o.Recorder.Next(command, f) } diff --git a/pkg/cmd/dev/lint.go b/pkg/cmd/dev/lint.go index 6ef7b6ce97aa..bc49becb3d38 100644 --- a/pkg/cmd/dev/lint.go +++ b/pkg/cmd/dev/lint.go @@ -63,13 +63,18 @@ func (d *dev) lint(cmd *cobra.Command, commandLine []string) error { args = append(args, "-test.run", fmt.Sprintf("Lint/%s", filter)) } logCommand("bazel", args...) - if len(pkgs) > 0 { + if len(pkgs) > 1 { + return fmt.Errorf("can only lint a single package (found %s)", strings.Join(pkgs, ", ")) + } + if len(pkgs) == 1 { pkg := strings.TrimRight(pkgs[0], "/") if !strings.HasPrefix(pkg, "./") { pkg = "./" + pkg } env := os.Environ() - env = append(env, fmt.Sprintf("PKG=%s", pkg)) + envvar := fmt.Sprintf("PKG=%s", pkg) + d.log.Printf("export %s", envvar) + env = append(env, envvar) return d.exec.CommandContextWithEnv(ctx, env, "bazel", args...) } return d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...) diff --git a/pkg/cmd/dev/recorderdriven_test.go b/pkg/cmd/dev/recorderdriven_test.go new file mode 100644 index 000000000000..84ab64e0f0cf --- /dev/null +++ b/pkg/cmd/dev/recorderdriven_test.go @@ -0,0 +1,202 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "bytes" + "flag" + "fmt" + "io" + "io/ioutil" + "log" + stdos "os" + stdexec "os/exec" + "strings" + "testing" + + "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/exec" + "github.com/cockroachdb/cockroach/pkg/cmd/dev/io/os" + "github.com/cockroachdb/cockroach/pkg/testutils" + "github.com/cockroachdb/datadriven" + "github.com/irfansharif/recorder" + "github.com/stretchr/testify/require" +) + +// TestRecorderDriven makes use of datadriven to record (if --rewrite is +// specified) or play back (if --rewrite is omitted) all operations executed by +// individual `dev` invocations. The testcases are defined under +// testdata/recorderdriven/*; each test file corresponds to a captured recording +// found in testdata/recorderdriven/*.rec. +// +// DataDriven divvies up these files as subtests, so individual "files" are +// runnable through: +// +// dev test pkg/cmd/dev -f TestRecorderDriven/ +// OR go test ./pkg/cmd/dev -run TestRecorderDriven/ +// +// Recordings are used to mock out "system" behavior. When --rewrite is +// specified, attempts to shell out to bazel or perform other OS operations +// (like creating, removing, symlinking filepaths) are intercepted and system +// responses are recorded for future playback. To update the test files with new +// capture data, try: +// +// go test ./pkg/cmd/dev -run TestRecorderDriven/ -rewrite +// +// NB: This test is worth contrasting to TestDataDriven, where all operations +// are run in "dry-run" mode when --rewrite is specified. Here we'll actually +// shell out (and take time proportional to running the actual commands). In +// dry-run mode (TestDataDriven) all exec and os commands return successfully +// with no error, with an empty response. This makes it suitable for testing +// workflows that don't make use of external state to execute actions (like +// reading the set of targets from a file for e.g., or hoisting files from a +// sandbox by searching through the file system directly). +// +// TODO(irfansharif): When --rewrite-ing, because these tests shell out to the +// actual host system, it makes it difficult to run under bazel/dev (currently +// disallowed). Probably these tests should be ripped out entirely. Dev's +// currently in the business of doing a lot of interactive I/O with the host +// system, instead of pushing it all down into bazel rules. The recorder tests +// are the few remaining examples of this. As we push more things down into +// bazel rules, we should re-evaluate whether this harness provides much value. +// Probably dev commands that require writing a TestRecorderDriven test is worth +// re-writing. +// +func TestRecorderDriven(t *testing.T) { + rewriting := false + if f := flag.Lookup("rewrite"); f != nil && f.Value.String() == "true" { + rewriting = true + } + if rewriting { + t.Fatalf("not supported under bazel") // needs to shell out to bazel itself + } + + verbose := testing.Verbose() + testdata := testutils.TestDataPath(t, "recorderdriven") + datadriven.Walk(t, testdata, func(t *testing.T, path string) { + if strings.HasSuffix(path, ".rec") { + return + } + + recordingPath := fmt.Sprintf("%s.rec", path) + + // We'll match against printed logs for datadriven. + var logger io.ReadWriter = bytes.NewBufferString("") + var recording io.ReadWriter + var rec *recorder.Recorder + + execOpts := []exec.Option{exec.WithLogger(log.New(logger, "", 0))} + osOpts := []os.Option{os.WithLogger(log.New(logger, "", 0))} + + if !verbose { + // Suppress all internal output unless told otherwise. + execOpts = append(execOpts, exec.WithStdOutErr(ioutil.Discard, ioutil.Discard)) + } + + if rewriting { + workspaceResult := workspace(t) + bazelbinResult := bazelbin(t) + execOpts = append(execOpts, + exec.WithWorkingDir(workspaceResult), + exec.WithIntercept(workspaceCmd(), workspaceResult), + exec.WithIntercept(bazelbinCmd(), bazelbinResult), + ) + osOpts = append(osOpts, os.WithWorkingDir(workspaceResult)) + + recording = bytes.NewBufferString("") + rec = recorder.New(recorder.WithRecording(recording)) // the thing to record into + } else { + execOpts = append(execOpts, + exec.WithIntercept(workspaceCmd(), crdbCheckoutPlaceholder), + exec.WithIntercept(bazelbinCmd(), sandboxPlaceholder), + ) + + frecording, err := stdos.OpenFile(recordingPath, stdos.O_RDONLY, 0600) + require.NoError(t, err) + defer func() { require.NoError(t, frecording.Close()) }() + rec = recorder.New(recorder.WithReplay(frecording, recordingPath)) // the recording we're playing back from + } + + require.NotNil(t, rec) + execOpts = append(execOpts, exec.WithRecorder(rec)) + osOpts = append(osOpts, os.WithRecorder(rec)) + + devExec := exec.New(execOpts...) + devOS := os.New(osOpts...) + + datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string { + dev := makeDevCmd() + dev.exec, dev.os = devExec, devOS + dev.knobs.skipDoctorCheck = true + dev.knobs.devBinOverride = "dev" + + if !verbose { + dev.cli.SetErr(ioutil.Discard) + dev.cli.SetOut(ioutil.Discard) + } + + require.Equalf(t, d.Cmd, "dev", "unknown command: %s", d.Cmd) + var args []string + for _, cmdArg := range d.CmdArgs { + args = append(args, cmdArg.Key) + if len(cmdArg.Vals) != 0 { + args = append(args, cmdArg.Vals[0]) + } + } + dev.cli.SetArgs(args) + if err := dev.cli.Execute(); err != nil { + return fmt.Sprintf("err: %s", err) + } + + logs, err := ioutil.ReadAll(logger) + require.NoError(t, err) + if rewriting { + logs = anonymize(t, logs) + } + return string(logs) + }) + + if rewriting { + recording, err := ioutil.ReadAll(recording) + require.NoError(t, err) + + frecording, err := stdos.OpenFile(recordingPath, stdos.O_CREATE|stdos.O_WRONLY|stdos.O_TRUNC|stdos.O_SYNC, 0600) + require.NoError(t, err) + defer func() { require.NoError(t, frecording.Close()) }() + + recording = anonymize(t, recording) + _, err = frecording.Write(recording) + require.NoError(t, err) + } + }) +} + +func anonymize(t *testing.T, input []byte) []byte { + output := bytes.ReplaceAll(input, []byte(workspace(t)), []byte(crdbCheckoutPlaceholder)) + return bytes.ReplaceAll(output, []byte(bazelbin(t)), []byte(sandboxPlaceholder)) +} + +func workspace(t *testing.T) string { + cmd := stdexec.Command("bazel", "info", "workspace") + var stdout, stderr bytes.Buffer + cmd.Stdout, cmd.Stderr = &stdout, &stderr + require.NoError(t, cmd.Start()) + require.NoError(t, cmd.Wait(), stderr.String()) + return strings.TrimSpace(stdout.String()) +} + +func bazelbin(t *testing.T) string { + cmd := stdexec.Command("bazel", "info", "bazel-bin") + var stdout, stderr bytes.Buffer + cmd.Stdout, cmd.Stderr = &stdout, &stderr + require.NoError(t, cmd.Start()) + require.NoError(t, cmd.Wait(), stderr.String()) + return strings.TrimSpace(stdout.String()) +} diff --git a/pkg/cmd/dev/recording/BUILD.bazel b/pkg/cmd/dev/recording/BUILD.bazel deleted file mode 100644 index 19a47a095bb1..000000000000 --- a/pkg/cmd/dev/recording/BUILD.bazel +++ /dev/null @@ -1,12 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "recording", - srcs = [ - "operation.go", - "recording.go", - "scanner.go", - ], - importpath = "github.com/cockroachdb/cockroach/pkg/cmd/dev/recording", - visibility = ["//visibility:public"], -) diff --git a/pkg/cmd/dev/recording/operation.go b/pkg/cmd/dev/recording/operation.go deleted file mode 100644 index a14d775050e3..000000000000 --- a/pkg/cmd/dev/recording/operation.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package recording - -import "strings" - -// Operation represents the base unit of what can be recorded. It consists of a -// command and an expected output. -// -// The printed form of the command is defined by the following grammar: -// -// # comment -// \ -// -// ---- -// -// -// By default cannot contain blank lines. This alternative syntax -// allows the use of blank lines. -// -// -// ---- -// ---- -// -// -// -// ---- -// ---- -type Operation struct { - Command string // - Output string // -} - -// String returns a printable form for the given Operation. See type-level -// comment to understand the grammar we're constructing against. -func (o *Operation) String() string { - var sb strings.Builder - sb.WriteString(o.Command) - sb.WriteString("\n") - - sb.WriteString("----\n") - - multiline := strings.ContainsAny(strings.TrimRight(o.Output, "\n"), "\n") - if multiline { - sb.WriteString("----\n") - } - - sb.WriteString(o.Output) - if o.Output != "" && !strings.HasSuffix(o.Output, "\n") { - sb.WriteString("\n") - } - - if multiline { - sb.WriteString("----\n") - sb.WriteString("----\n") - } - - sb.WriteString("\n") - return sb.String() -} diff --git a/pkg/cmd/dev/recording/recording.go b/pkg/cmd/dev/recording/recording.go deleted file mode 100644 index 3cc87368ae46..000000000000 --- a/pkg/cmd/dev/recording/recording.go +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2021 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package recording - -import ( - "bytes" - "fmt" - "io" - "strings" -) - -// Recording can be used to play back a set of operations (defined only by a -// "command" and an "expected output"). It provides a handy way to mock out the -// components being recorded. -type Recording struct { - // scanner is where we're replaying the recording from. op is the - // scratch space used to parse out the current operation being read. - scanner *scanner - op Operation -} - -// WithReplayFrom is used to configure a Recording to play back from the given -// reader. The provided name is used only for diagnostic purposes, it's -// typically the name of the file being read. -func WithReplayFrom(r io.Reader, name string) *Recording { - re := &Recording{} - re.scanner = newScanner(r, name) - return re -} - -// Next is used to step through the next operation found in the recording, if -// any. -func (r *Recording) Next(f func(Operation) error) (found bool, err error) { - parsed, err := r.parseOperation() - if err != nil { - return false, err - } - - if !parsed { - return false, nil - } - - if err := f(r.op); err != nil { - return false, fmt.Errorf("%s: %w", r.scanner.pos(), err) - } - return true, nil -} - -// parseOperation parses out the next Operation from the internal scanner. See -// type-level comment on Operation to understand the grammar we're parsing -// against. -func (r *Recording) parseOperation() (parsed bool, err error) { - for r.scanner.Scan() { - r.op = Operation{} - line := r.scanner.Text() - - line = strings.TrimSpace(line) - if strings.HasPrefix(line, "#") { - // Skip comment lines. - continue - } - - // Support wrapping command directive lines using "\". - for strings.HasSuffix(line, `\`) && r.scanner.Scan() { - nextLine := r.scanner.Text() - line = strings.TrimSuffix(line, `\`) - line = strings.TrimSpace(line) - line = fmt.Sprintf("%s %s", line, strings.TrimSpace(nextLine)) - } - - command, err := r.parseCommand(line) - if err != nil { - return false, err - } - if command == "" { - // Nothing to do here. - continue - } - r.op.Command = command - - if err := r.parseSeparator(); err != nil { - return false, err - } - - if err := r.parseOutput(); err != nil { - return false, err - } - - return true, nil - } - return false, nil -} - -// parseCommand parses a line and returns it if parsed correctly. See -// type-level comment on Operation to understand the grammar we're parsing -// against. -func (r *Recording) parseCommand(line string) (cmd string, err error) { - line = strings.TrimSpace(line) - if line == "" { - return "", nil - } - - origLine := line - cmd = strings.TrimSpace(line) - if cmd == "" { - column := len(origLine) - len(line) + 1 - return "", fmt.Errorf("%s: cannot parse command at col %d: %s", r.scanner.pos(), column, origLine) - } - return cmd, nil -} - -// parseSeparator parses a separator ('----'), erroring out if it's not parsed -// correctly. See type-level comment on Operation to understand the grammar -// we're parsing against. -func (r *Recording) parseSeparator() error { - if !r.scanner.Scan() { - return fmt.Errorf("%s: expected to find separator after command", r.scanner.pos()) - } - line := r.scanner.Text() - if line != "----" { - return fmt.Errorf("%s: expected to find separator after command, found %q instead", r.scanner.pos(), line) - } - return nil -} - -// parseOutput parses an . See type-level comment on Operation to -// understand the grammar we're parsing against. -func (r *Recording) parseOutput() error { - var buf bytes.Buffer - var line string - - var allowBlankLines bool - if r.scanner.Scan() { - line = r.scanner.Text() - if line == "----" { - allowBlankLines = true - } - } - - if !allowBlankLines { - // Terminate on first blank line. - for { - if strings.TrimSpace(line) == "" { - break - } - - if _, err := fmt.Fprintln(&buf, line); err != nil { - return err - } - - if !r.scanner.Scan() { - break - } - - line = r.scanner.Text() - } - r.op.Output = buf.String() - return nil - } - - // Look for two successive lines of "----" before terminating. - for r.scanner.Scan() { - line = r.scanner.Text() - if line != "----" { - // We just picked up a regular line that's part of the command - // output. - if _, err := fmt.Fprintln(&buf, line); err != nil { - return err - } - - continue - } - - // We picked up a separator. We could either be part of the - // command output, or it was actually intended by the user as a - // separator. Let's check to see if we can parse a second one. - if err := r.parseSeparator(); err == nil { - // We just saw the second separator, the output portion is done. - // Read the following blank line. - if r.scanner.Scan() && r.scanner.Text() != "" { - return fmt.Errorf("%s: non-blank line after end of double ---- separator section", r.scanner.pos()) - } - break - } - - // The separator we saw was part of the command output. - // Let's collect both lines (the first separator, and the - // new one). - if _, err := fmt.Fprintln(&buf, line); err != nil { - return err - } - - line2 := r.scanner.Text() - if _, err := fmt.Fprintln(&buf, line2); err != nil { - return err - } - } - - r.op.Output = buf.String() - return nil -} diff --git a/pkg/cmd/dev/recording/scanner.go b/pkg/cmd/dev/recording/scanner.go deleted file mode 100644 index 06d2c8c22764..000000000000 --- a/pkg/cmd/dev/recording/scanner.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2021 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package recording - -import ( - "bufio" - "fmt" - "io" -) - -// scanner is a convenience wrapper around a bufio.Scanner that keeps track of -// the currently read line number (and an associated name for the reader - -// typically a file name). -type scanner struct { - *bufio.Scanner - line int - name string -} - -func newScanner(r io.Reader, name string) *scanner { - bufioScanner := bufio.NewScanner(r) - // We use a large max-token-size to account for lines in the output that far - // exceed the default bufio scanner token size. - bufioScanner.Buffer(make([]byte, 100), 10*bufio.MaxScanTokenSize) - return &scanner{ - Scanner: bufioScanner, - name: name, - } -} - -func (s *scanner) Scan() bool { - ok := s.Scanner.Scan() - if ok { - s.line++ - } - return ok -} - -// pos is a file:line prefix for the input file, suitable for inclusion in logs -// and error messages. -func (s *scanner) pos() string { - return fmt.Sprintf("%s:%d", s.name, s.line) -} diff --git a/pkg/cmd/dev/test.go b/pkg/cmd/dev/test.go index 9feb1980ffb7..8a81f7c38932 100644 --- a/pkg/cmd/dev/test.go +++ b/pkg/cmd/dev/test.go @@ -11,15 +11,11 @@ package main import ( - "context" - "errors" "fmt" - "os/exec" "path/filepath" "strings" "time" - "github.com/alessio/shellescape" "github.com/spf13/cobra" ) @@ -98,6 +94,12 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error { vModule = mustGetFlagString(cmd, vModuleFlag) ) + // Enumerate all tests to run. + if len(pkgs) == 0 { + // Empty `dev test` does the same thing as `dev test pkg/...` + pkgs = append(pkgs, "pkg/...") + } + var args []string args = append(args, "test") args = append(args, mustGetRemoteCacheArgs(remoteCacheAddr)...) @@ -112,54 +114,25 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error { var testTargets []string for _, pkg := range pkgs { - dir, isRecursive, tag, err := d.parsePkg(pkg) - if err != nil { - return err + pkg = strings.TrimPrefix(pkg, "//") + pkg = strings.TrimPrefix(pkg, "./") + pkg = strings.TrimRight(pkg, "/") + + if !strings.HasPrefix(pkg, "pkg/") { + return fmt.Errorf("malformed package %q, expecting %q", pkg, "pkg/{...}") } - querySuffix := "" - if isRecursive { - // Similar to `go test`, we implement `...` expansion to allow - // callers to use the following pattern to test all packages under a - // named one: - // - // dev test pkg/util/... -v - // - // NB: We'll want to filter for just the go_test targets here. Not - // doing so prompts bazel to try and build all named targets. This - // is undesirable for the various `*_proto` targets seeing as how - // they're not buildable in isolation. This is because we often - // attach methods to proto types in hand-written files, files that - // are not picked up by the proto bazel targets[1]. Regular bazel - // compilation is still fine seeing as how the top-level go_library - // targets both embeds the proto target, and sources the - // hand-written file. But the proto target in isolation may not be - // buildable because without those additional methods, those types - // may fail to satisfy required interfaces. - // - // So, blinding selecting for all targets won't work, and we'll want - // to filter things out first. - // - // [1]: pkg/rpc/heartbeat.proto is one example of this pattern, - // where we define `Stringer` separately for the `RemoteOffset` - // type. - querySuffix = "/..." + + var target string + if strings.Contains(pkg, ":") { + // For parity with bazel, we allow specifying named build targets. + target = pkg } else { - if tag == "" { - tag = "all" - } - querySuffix = ":" + tag + target = fmt.Sprintf("%s:all", pkg) } - query := fmt.Sprintf("kind(go_test, //%s%s)", dir, querySuffix) - out, err := d.getQueryOutput(ctx, query) - if err != nil { - return err - } - tests := strings.Split(strings.TrimSpace(string(out)), "\n") - testTargets = append(testTargets, tests...) + testTargets = append(testTargets, target) } args = append(args, testTargets...) - if ignoreCache { args = append(args, "--nocache_test_results") } @@ -213,7 +186,7 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error { // NB: Run with -bazel, which propagates `TEST_TMPDIR` to `TMPDIR`, // and -shardable-artifacts set such that we can merge the XML output // files. - fmt.Sprintf("%s -bazel -shardable-artifacts 'XML_OUTPUT_FILE=%s merge-test-xmls' %s", stressTarget, getDevBin(), strings.Join(stressCmdArgs, " "))) + fmt.Sprintf("%s -bazel -shardable-artifacts 'XML_OUTPUT_FILE=%s merge-test-xmls' %s", stressTarget, d.getDevBin(), strings.Join(stressCmdArgs, " "))) } if filter != "" { @@ -254,6 +227,12 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error { logCommand("bazel", args...) return d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...) + + // TODO(irfansharif): Both here and in `dev bench`, if the command is + // unsuccessful we could explicitly check for "missing package" errors. The + // situation is not so bad currently however: + // + // [...] while parsing 'pkg/f:all': no such package 'pkg/f' } func getDirectoryFromTarget(target string) string { @@ -264,25 +243,3 @@ func getDirectoryFromTarget(target string) string { } return target[:colon] } - -// getQueryOutput runs `bazel query` w/ the given arguments, but returns -// a more informative error if the query fails. -func (d *dev) getQueryOutput(ctx context.Context, args ...string) ([]byte, error) { - queryArgs := []string{"query"} - queryArgs = append(queryArgs, args...) - stdoutBytes, err := d.exec.CommandContextSilent(ctx, "bazel", queryArgs...) - if err == nil { - return stdoutBytes, err - } - var cmderr *exec.ExitError - var stdout, stderr string - if len(stdoutBytes) > 0 { - stdout = fmt.Sprintf("stdout: \"%s\" ", string(stdoutBytes)) - } - if errors.As(err, &cmderr) && len(cmderr.Stderr) > 0 { - stderr = fmt.Sprintf("stderr: \"%s\" ", strings.TrimSpace(string(cmderr.Stderr))) - } - return nil, fmt.Errorf("failed to run `bazel %s` %s%s(%w)", - shellescape.QuoteCommand(queryArgs), stdout, stderr, err) - -} diff --git a/pkg/cmd/dev/testdata/bench.txt b/pkg/cmd/dev/testdata/bench.txt deleted file mode 100644 index 66c9bec5f577..000000000000 --- a/pkg/cmd/dev/testdata/bench.txt +++ /dev/null @@ -1,11 +0,0 @@ -dev bench pkg/util/... ----- -find pkg/util -type d -git grep -l '^func Benchmark' -- 'pkg/util/*_test.go' -bazel run --config=test --test_sharding_strategy=disabled //pkg/util:util_test -- -test.run=- -test.bench=. -bazel run --config=test --test_sharding_strategy=disabled //pkg/util/uuid:uuid_test -- -test.run=- -test.bench=. - -dev bench pkg/sql/parser --filter=BenchmarkParse ----- -find pkg/sql/parser -type d -bazel run --config=test --test_sharding_strategy=disabled //pkg/sql/parser:parser_test -- -test.run=- -test.bench=BenchmarkParse diff --git a/pkg/cmd/dev/testdata/build.txt b/pkg/cmd/dev/testdata/build.txt deleted file mode 100644 index 6feecd979c7a..000000000000 --- a/pkg/cmd/dev/testdata/build.txt +++ /dev/null @@ -1,90 +0,0 @@ -dev build cockroach-short --skip-generate ----- -bazel build //pkg/cmd/cockroach-short:cockroach-short -bazel info workspace --color=no -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short - -dev build cockroach-short --cpus=12 --skip-generate ----- -bazel build --local_cpu_resources=12 //pkg/cmd/cockroach-short:cockroach-short -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short - -dev build --debug short --skip-generate ----- -bazel build //pkg/cmd/cockroach-short:cockroach-short -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short - -dev build cockroach-short --remote-cache 127.0.0.1:9090 --skip-generate ----- -bazel build --remote_local_fallback --remote_cache=grpc://127.0.0.1:9090 --experimental_remote_downloader=grpc://127.0.0.1:9090 //pkg/cmd/cockroach-short:cockroach-short -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short - -dev build cockroach-short ----- -bazel build //pkg/cmd/cockroach-short:cockroach-short //:go_path -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short -git status --ignored --short go/src/github.com/cockroachdb/cockroach/pkg -rm pkg/file_to_delete.go -find /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach -name *.go -cat go/src/github.com/cockroachdb/cockroach/build/bazelutil/checked_in_genfiles.txt -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr.og.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator.og.go - -dev build short --skip-generate -- -s ----- -bazel build //pkg/cmd/cockroach-short:cockroach-short -s -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach-short -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short - -dev build --skip-generate -- --verbose_failures --sandbox_debug ----- -bazel run @nodejs//:yarn -- --check-files --cwd pkg/ui --offline -bazel build //pkg/cmd/cockroach:cockroach --config=with_ui --verbose_failures --sandbox_debug -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/cockroach -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach/cockroach_/cockroach go/src/github.com/cockroachdb/cockroach/cockroach - -dev build @com_github_cockroachdb_stress//:stress --skip-generate ----- -bazel query @com_github_cockroachdb_stress//:stress --output=label_kind -bazel build @com_github_cockroachdb_stress//:stress -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/bin/stress -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/external/com_github_cockroachdb_stress/stress_/stress go/src/github.com/cockroachdb/cockroach/bin/stress - -dev build pkg/roachpb:roachpb_test --skip-generate ----- -bazel query pkg/roachpb:roachpb_test --output=label_kind -bazel build //pkg/roachpb:roachpb_test --config=test -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no - -dev build pkg/foo/... --skip-generate ----- -bazel query pkg/foo/... --output=label_kind -bazel build //pkg/foo:bar //pkg/foo:baz --config=test -mkdir go/src/github.com/cockroachdb/cockroach/bin -bazel info bazel-bin --color=no -rm go/src/github.com/cockroachdb/cockroach/bin/bar -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/foo/bar_/bar go/src/github.com/cockroachdb/cockroach/bin/bar diff --git a/pkg/cmd/dev/testdata/builder.txt b/pkg/cmd/dev/testdata/builder.txt deleted file mode 100644 index af382ffcf39f..000000000000 --- a/pkg/cmd/dev/testdata/builder.txt +++ /dev/null @@ -1,15 +0,0 @@ -dev builder ----- -id -cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh -docker volume inspect bzlhome -mkdir go/src/github.com/cockroachdb/cockroach/artifacts -docker run --rm -it -v go/src/github.com/cockroachdb/cockroach:/cockroach --workdir=/cockroach -v go/src/github.com/cockroachdb/cockroach/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 1001:1002 mock_bazel_image:1234 - -dev builder echo hi ----- -id -cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh -docker volume inspect bzlhome -mkdir go/src/github.com/cockroachdb/cockroach/artifacts -docker run --rm -it -v go/src/github.com/cockroachdb/cockroach:/cockroach --workdir=/cockroach -v go/src/github.com/cockroachdb/cockroach/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 1001:1002 mock_bazel_image:1234 echo hi diff --git a/pkg/cmd/dev/testdata/datadriven/bench b/pkg/cmd/dev/testdata/datadriven/bench new file mode 100644 index 000000000000..778085f057bb --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/bench @@ -0,0 +1,15 @@ +dev bench pkg/spanconfig/... +---- +bazel test pkg/spanconfig/...:all --test_arg -test.bench=. --test_output errors + +dev bench pkg/sql/parser --filter=BenchmarkParse +---- +bazel test pkg/sql/parser:all --test_arg -test.bench=BenchmarkParse --test_output errors + +dev bench pkg/bench -f=BenchmarkTracing/1node/scan/trace=off --count=2 --bench-time=10x --bench-mem +---- +bazel test pkg/bench:all --test_arg -test.bench=BenchmarkTracing/1node/scan/trace=off --test_arg -test.count=2 --test_arg -test.benchtime=10x --test_arg -test.benchmem --test_output errors + +dev bench pkg/spanconfig/spanconfigkvsubscriber -f=BenchmarkSpanConfigDecoder --cpus=10 --ignore-cache -v --timeout=50s +---- +bazel test --local_cpu_resources=10 --test_timeout=50 pkg/spanconfig/spanconfigkvsubscriber:all --nocache_test_results --test_arg -test.bench=BenchmarkSpanConfigDecoder --test_arg -test.v --test_output all diff --git a/pkg/cmd/dev/testdata/datadriven/compose b/pkg/cmd/dev/testdata/datadriven/compose new file mode 100644 index 000000000000..4b04dd079efd --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/compose @@ -0,0 +1,7 @@ +dev compose +---- +bazel run //pkg/compose:compose_test --config=test + +dev compose --cpus 12 --short --timeout 1m -f TestComposeCompare +---- +bazel run //pkg/compose:compose_test --config=test --local_cpu_resources=12 --test_filter=TestComposeCompare --test_arg -test.short --test_timeout=60 diff --git a/pkg/cmd/dev/testdata/datadriven/dev-build b/pkg/cmd/dev/testdata/datadriven/dev-build new file mode 100644 index 000000000000..ab478ffe4598 --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/dev-build @@ -0,0 +1,54 @@ +dev build cockroach-short --skip-generate +---- +bazel build //pkg/cmd/cockroach-short:cockroach-short +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm cockroach-short +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short + +dev build cockroach-short --cpus=12 --skip-generate +---- +bazel build --local_cpu_resources=12 //pkg/cmd/cockroach-short:cockroach-short +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm cockroach-short +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short + +dev build --debug short --skip-generate +---- +bazel build //pkg/cmd/cockroach-short:cockroach-short +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm cockroach-short +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short + +dev build short --skip-generate -- -s +---- +bazel build //pkg/cmd/cockroach-short:cockroach-short -s +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm cockroach-short +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short + +dev build --skip-generate -- --verbose_failures --sandbox_debug +---- +bazel run @nodejs//:yarn -- --check-files --cwd pkg/ui --offline +bazel build //pkg/cmd/cockroach:cockroach --config=with_ui --verbose_failures --sandbox_debug +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm cockroach +ln -s pkg/cmd/cockroach/cockroach_/cockroach cockroach + +dev build stress --skip-generate +---- +bazel build @com_github_cockroachdb_stress//:stress +bazel info workspace --color=no +mkdir bin +bazel info bazel-bin --color=no +rm bin/stress +ln -s external/com_github_cockroachdb_stress/stress_/stress bin/stress diff --git a/pkg/cmd/dev/testdata/datadriven/generate b/pkg/cmd/dev/testdata/datadriven/generate new file mode 100644 index 000000000000..86f279c4e80f --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/generate @@ -0,0 +1,15 @@ +dev gen protobuf +---- +bazel run //pkg/gen:go_proto + +dev gen bazel +---- +bazel info workspace --color=no +build/bazelutil/bazel-generate.sh + +dev generate bazel --mirror --force +---- +bazel info workspace --color=no +export COCKROACH_BAZEL_CAN_MIRROR=1 +export COCKROACH_BAZEL_FORCE_GENERATE=1 +build/bazelutil/bazel-generate.sh diff --git a/pkg/cmd/dev/testdata/datadriven/lint b/pkg/cmd/dev/testdata/datadriven/lint new file mode 100644 index 000000000000..172eedae41d1 --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/lint @@ -0,0 +1,20 @@ +dev lint +---- +bazel run --config=test //build/bazelutil:lint -- -test.v + +dev lint --short --timeout=5m +---- +bazel run --config=test //build/bazelutil:lint -- -test.v -test.short -test.timeout 5m0s + +dev lint pkg/cmd/dev +---- +export PKG=./pkg/cmd/dev +bazel run --config=test //build/bazelutil:lint -- -test.v + +dev lint -f TestLowercaseFunctionNames --cpus 4 +---- +bazel run --config=test //build/bazelutil:lint --local_cpu_resources=4 -- -test.v -test.run Lint/TestLowercaseFunctionNames + +dev lint pkg/cmd/dev pkg/spanconfig +---- +err: can only lint a single package (found pkg/cmd/dev, pkg/spanconfig) diff --git a/pkg/cmd/dev/testdata/datadriven/test b/pkg/cmd/dev/testdata/datadriven/test new file mode 100644 index 000000000000..e6b49b48867d --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/test @@ -0,0 +1,68 @@ +dev test pkg/util/tracing +---- +bazel test pkg/util/tracing:all --test_env=GOTRACEBACK=all --test_output errors + +dev test pkg/util/tracing/... +---- +bazel test pkg/util/tracing/...:all --test_env=GOTRACEBACK=all --test_output errors + +dev test pkg/util/tracing -f TestStartChild* +---- +bazel test pkg/util/tracing:all --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors + +dev test pkg/util/tracing -f TestStartChild* -v --show-logs +---- +bazel test pkg/util/tracing:all --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_arg -test.v --test_arg -show-logs --test_output all + +dev test pkg/util/tracing -f TestStartChild* --remote-cache 127.0.0.1:9092 +---- +bazel test --remote_local_fallback --remote_cache=grpc://127.0.0.1:9092 --experimental_remote_downloader=grpc://127.0.0.1:9092 pkg/util/tracing:all --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors + +dev test pkg/util/tracing -f TestStartChild* --ignore-cache +---- +bazel test pkg/util/tracing:all --nocache_test_results --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors + +dev test --stress pkg/util/tracing --filter TestStartChild* --cpus=12 --timeout=25s +---- +bazel test --local_cpu_resources=12 --test_sharding_strategy=disabled pkg/util/tracing:all --test_env=GOTRACEBACK=all --test_timeout=85 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=25s -p=12 ' '--test_filter=TestStartChild*' --test_output streamed + +dev test //pkg/testutils --timeout=10s +---- +bazel test pkg/testutils:all --test_env=GOTRACEBACK=all --test_timeout=10 --test_output errors + +dev test pkg/util/tracing -- -s +---- +bazel test pkg/util/tracing:all --test_env=GOTRACEBACK=all --test_output errors -s + +dev test ./pkg/roachpb +---- +bazel test pkg/roachpb:all --test_env=GOTRACEBACK=all --test_output errors + +dev test pkg/roachpb:string_test +---- +bazel test pkg/roachpb:string_test --test_env=GOTRACEBACK=all --test_output errors + +dev test //pkg/testutils +---- +bazel test pkg/testutils:all --test_env=GOTRACEBACK=all --test_output errors + +dev test //pkg/testutils pkg/util/limit +---- +bazel test pkg/testutils:all pkg/util/limit:all --test_env=GOTRACEBACK=all --test_output errors + +dev test pkg/spanconfig --count 5 --race +---- +bazel test --config=race pkg/spanconfig:all --test_env=GOTRACEBACK=all --test_arg -test.count=5 --test_output errors + +dev test pkg/cmd/dev -f TestDataDriven/test --rewrite -v +---- +bazel info workspace --color=no +bazel test pkg/cmd/dev:all --test_env=GOTRACEBACK=all --test_env=COCKROACH_WORKSPACE= --test_arg -rewrite --sandbox_writable_path=pkg/cmd/dev --test_filter=TestDataDriven/test --test_arg -test.v --test_output all + +dev test pkg/server -f=TestSpanStatsResponse -v --count=5 --vmodule=raft=1 +---- +bazel test pkg/server:all --test_env=GOTRACEBACK=all --test_filter=TestSpanStatsResponse --test_arg -test.v --test_arg -test.count=5 --test_arg -vmodule=raft=1 --test_output all + +dev test --short +---- +bazel test pkg/...:all --test_env=GOTRACEBACK=all --test_arg -test.short --test_output errors diff --git a/pkg/cmd/dev/testdata/datadriven/testlogic b/pkg/cmd/dev/testdata/datadriven/testlogic new file mode 100644 index 000000000000..9b105b9a956d --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/testlogic @@ -0,0 +1,27 @@ +dev testlogic +---- +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/logictest:logictest_test --test_filter TestLogic/// +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/ccl/logictestccl:logictestccl_test --test_filter 'Test(CCL|Tenant)Logic///' +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/opt/exec/execbuilder:execbuilder_test --test_filter TestExecBuild/// + +dev testlogic ccl +---- +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/ccl/logictestccl:logictestccl_test --test_filter 'Test(CCL|Tenant)Logic///' + +dev testlogic ccl opt +---- +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/ccl/logictestccl:logictestccl_test --test_filter 'Test(CCL|Tenant)Logic///' +bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/opt/exec/execbuilder:execbuilder_test --test_filter TestExecBuild/// + +dev testlogic base --ignore-cache +---- +bazel test --test_env=GOTRACEBACK=all --nocache_test_results --test_output errors //pkg/sql/logictest:logictest_test --test_filter TestLogic/// + +dev testlogic base --files=prepare|fk --subtests=20042 --config=local +---- +bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_arg -config --test_arg local --test_output errors //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^prepare|fk$/20042' + +dev testlogic base --files=auto_span_config_reconciliation --config=local -v --show-logs --timeout=50s --rewrite +---- +bazel info workspace --color=no +bazel test --test_env=GOTRACEBACK=all --test_arg -test.v --test_arg -show-logs --test_timeout=50 --test_arg -show-sql --test_arg -config --test_arg local --test_output all --test_env=COCKROACH_WORKSPACE= --test_arg -rewrite --sandbox_writable_path=pkg/sql/logictest //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^auto_span_config_reconciliation$/' diff --git a/pkg/cmd/dev/testdata/datadriven/ui b/pkg/cmd/dev/testdata/datadriven/ui new file mode 100644 index 000000000000..51c5553b45f0 --- /dev/null +++ b/pkg/cmd/dev/testdata/datadriven/ui @@ -0,0 +1,39 @@ +dev ui watch +---- +bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl +which yarn +bazel info workspace --color=no +yarn --silent --cwd pkg/ui/workspaces/cluster-ui build:watch +yarn --silent --cwd pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 + +dev ui watch --oss +---- +bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client +which yarn +bazel info workspace --color=no +yarn --silent --cwd pkg/ui/workspaces/cluster-ui build:watch +yarn --silent --cwd pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=oss --env.target=http://localhost:8080 --port 3000 + +dev ui watch --secure +---- +bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl +which yarn +bazel info workspace --color=no +yarn --silent --cwd pkg/ui/workspaces/cluster-ui build:watch +yarn --silent --cwd pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 --https + +dev ui watch --db http://example.crdb.io:4848 +---- +bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl +which yarn +bazel info workspace --color=no +yarn --silent --cwd pkg/ui/workspaces/cluster-ui build:watch +yarn --silent --cwd pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://example.crdb.io:4848 --port 3000 + +dev ui watch --port 12345 +---- +bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl +which yarn +bazel info workspace --color=no +yarn --silent --cwd pkg/ui/workspaces/cluster-ui build:watch +yarn --silent --cwd pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 12345 diff --git a/pkg/cmd/dev/testdata/generate.txt b/pkg/cmd/dev/testdata/generate.txt deleted file mode 100644 index 5ca41f0e7472..000000000000 --- a/pkg/cmd/dev/testdata/generate.txt +++ /dev/null @@ -1,31 +0,0 @@ -dev gen bazel ----- -go/src/github.com/cockroachdb/cockroach/build/bazelutil/bazel-generate.sh - -dev gen docs ----- -cat go/src/github.com/cockroachdb/cockroach/docs/generated/bazel_targets.txt -bazel build //docs/generated:gen-logging-md //docs/generated/sql -bazel info bazel-bin --color=no -bazel query --output=xml //docs/generated:gen-logging-md -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/logging.md go/src/github.com/cockroachdb/cockroach/docs/generated/logging.md -bazel query --output=xml //docs/generated/sql -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/aggregates.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/aggregates.md -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/functions.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/functions.md -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/operators.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/operators.md -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/window_functions.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/window_functions.md -go/src/github.com/cockroachdb/cockroach/build/bazelutil/generate_redact_safe.sh -echo MOCK_REDACT_SAFE_OUTPUT > go/src/github.com/cockroachdb/cockroach/docs/generated/redact_safe.md - -dev gen go ----- -bazel build //:go_path --show_result=0 -bazel info bazel-bin --color=no -git status --ignored --short go/src/github.com/cockroachdb/cockroach/pkg -rm pkg/file_to_delete.go -find /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach -name *.go -cat go/src/github.com/cockroachdb/cockroach/build/bazelutil/checked_in_genfiles.txt -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr.og.go -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator.og.go diff --git a/pkg/cmd/dev/testdata/lint.txt b/pkg/cmd/dev/testdata/lint.txt deleted file mode 100644 index 3fc96a5483f5..000000000000 --- a/pkg/cmd/dev/testdata/lint.txt +++ /dev/null @@ -1,7 +0,0 @@ -dev lint ----- -bazel run --config=test //build/bazelutil:lint -- -test.v - -dev lint --short --timeout=5m ----- -bazel run --config=test //build/bazelutil:lint -- -test.v -test.short -test.timeout 5m0s diff --git a/pkg/cmd/dev/testdata/logic.txt b/pkg/cmd/dev/testdata/logic.txt deleted file mode 100644 index cacfb9cd4e96..000000000000 --- a/pkg/cmd/dev/testdata/logic.txt +++ /dev/null @@ -1,13 +0,0 @@ -dev testlogic ----- -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/logictest:logictest_test --test_filter TestLogic/// -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/ccl/logictestccl:logictestccl_test --test_filter 'Test(CCL|Tenant)Logic///' -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/opt/exec/execbuilder:execbuilder_test --test_filter TestExecBuild/// - -dev testlogic base --files=prepare|fk --subtests=20042 --config=local ----- -bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_arg -config --test_arg local --test_output errors //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^prepare|fk$/20042' - -dev testlogic base --files=auto_span_config_reconciliation_job --config=local -v --show-logs --timeout=50s --rewrite ----- -bazel test --test_env=GOTRACEBACK=all --test_arg -test.v --test_arg -show-logs --test_timeout=50 --test_arg -show-sql --test_arg -config --test_arg local --test_output all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/sql/logictest //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^auto_span_config_reconciliation_job$/' diff --git a/pkg/cmd/dev/testdata/recorderdriven/builder b/pkg/cmd/dev/testdata/recorderdriven/builder new file mode 100644 index 000000000000..cdf77030a072 --- /dev/null +++ b/pkg/cmd/dev/testdata/recorderdriven/builder @@ -0,0 +1,19 @@ +dev builder +---- +which docker +id +bazel info workspace --color=no +cat crdb-checkout/build/teamcity-bazel-support.sh +docker volume inspect bzlhome +mkdir crdb-checkout/artifacts +docker run --rm -i -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 503:503 cockroachdb/bazel:20220121-121551 + +dev builder echo hi +---- +which docker +id +bazel info workspace --color=no +cat crdb-checkout/build/teamcity-bazel-support.sh +docker volume inspect bzlhome +mkdir crdb-checkout/artifacts +docker run --rm -i -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 503:503 cockroachdb/bazel:20220121-121551 echo hi diff --git a/pkg/cmd/dev/testdata/recorderdriven/builder.rec b/pkg/cmd/dev/testdata/recorderdriven/builder.rec new file mode 100644 index 000000000000..0c41ef19354d --- /dev/null +++ b/pkg/cmd/dev/testdata/recorderdriven/builder.rec @@ -0,0 +1,278 @@ +which docker +---- +/usr/local/bin/docker + +id +---- +503:20 + +cat crdb-checkout/build/teamcity-bazel-support.sh +---- +---- +# FYI: You can run `./dev builder` to run this Docker image. :) +# `dev` depends on this variable! Don't change the name or format unless you +# also update `dev` accordingly. +BAZEL_IMAGE=cockroachdb/bazel:20220121-121551 + +# Call `run_bazel $NAME_OF_SCRIPT` to start an appropriately-configured Docker +# container with the `cockroachdb/bazel` image running the given script. +# BAZEL_SUPPORT_EXTRA_DOCKER_ARGS will be passed on to `docker run` unchanged. +run_bazel() { + if [ -z "${root:-}" ] + then + echo '$root is not set; please source teamcity-support.sh' + exit 1 + fi + + # Set up volumes. + # TeamCity uses git alternates, so make sure we mount the path to the real + # git objects. + teamcity_alternates="/home/agent/system/git" + vols="--volume ${teamcity_alternates}:${teamcity_alternates}:ro" + artifacts_dir=$root/artifacts + mkdir -p "$artifacts_dir" + vols="${vols} --volume ${artifacts_dir}:/artifacts" + cache=/home/agent/.bzlhome + mkdir -p $cache + vols="${vols} --volume ${root}:/go/src/github.com/cockroachdb/cockroach" + vols="${vols} --volume ${cache}:/home/roach" + + docker run -i ${tty-} --rm --init \ + -u "$(id -u):$(id -g)" \ + --workdir="/go/src/github.com/cockroachdb/cockroach" \ + ${BAZEL_SUPPORT_EXTRA_DOCKER_ARGS:+$BAZEL_SUPPORT_EXTRA_DOCKER_ARGS} \ + ${vols} \ + $BAZEL_IMAGE "$@" +} + +# local copy of tc_release_branch from teamcity-support.sh to avoid imports. +_tc_release_branch() { + [[ "$TC_BUILD_BRANCH" == master || "$TC_BUILD_BRANCH" == release-* || "$TC_BUILD_BRANCH" == provisional_* ]] +} + +# process_test_json processes logs and submits failures to GitHub +# Requires GITHUB_API_TOKEN set for the release branches. +# Accepts 5 arguments: +# testfilter: path to the `testfilter` executable, usually +# `$BAZEL_BIN/pkg/cmd/testfilter/testfilter_/testfilter` +# github_post: path to the `github-post` executable, usually +# `$BAZEL_BIN/pkg/cmd/github-post/github-post_/github-post` +# artifacts_dir: usually `/artifacts` +# test_json: path to test's JSON output, usually generated by `rules_go`'s and +# `GO_TEST_JSON_OUTPUT_FILE`. +# create_tarball: whether to create a tarball with full logs. If the test's +# exit code is passed, the tarball is generated on failures. +process_test_json() { + local testfilter=$1 + local github_post=$2 + local artifacts_dir=$3 + local test_json=$4 + local create_tarball=$5 + + $testfilter -mode=strip < "$test_json" | $testfilter -mode=omit | $testfilter -mode=convert > "$artifacts_dir"/failures.txt + failures_size=$(stat --format=%s "$artifacts_dir"/failures.txt) + if [ $failures_size = 0 ]; then + rm -f "$artifacts_dir"/failures.txt + fi + + if _tc_release_branch; then + if [ -z "${GITHUB_API_TOKEN-}" ]; then + # GITHUB_API_TOKEN must be in the env or github-post will barf if it's + # ever asked to post, so enforce that on all runs. + # The way this env var is made available here is quite tricky. The build + # calling this method is usually a build that is invoked from PRs, so it + # can't have secrets available to it (for the PR could modify + # build/teamcity-* to leak the secret). Instead, we provide the secrets + # to a higher-level job (Publish Bleeding Edge) and use TeamCity magic to + # pass that env var through when it's there. This means we won't have the + # env var on PR builds, but we'll have it for builds that are triggered + # from the release branches. + echo "GITHUB_API_TOKEN must be set" + exit 1 + else + $github_post < "$test_json" + fi + fi + + if [ "$create_tarball" -ne 0 ]; then + # Keep the debug file around for failed builds. Compress it to avoid + # clogging the agents with stuff we'll hopefully rarely ever need to + # look at. + # If the process failed, also save the full human-readable output. This is + # helpful in cases in which tests timed out, where it's difficult to blame + # the failure on any particular test. It's also a good alternative to poking + # around in test.json.txt itself when anything else we don't handle well happens, + # whatever that may be. + $testfilter -mode=convert < "$test_json" > "$artifacts_dir"/full_output.txt + (cd "$artifacts_dir" && tar --strip-components 1 -czf full_output.tgz full_output.txt $(basename $test_json)) + rm -rf "$artifacts_dir"/full_output.txt + fi + + # Some unit tests test automatic ballast creation. These ballasts can be + # larger than the maximum artifact size. Remove any artifacts with the + # EMERGENCY_BALLAST filename. + find "$artifacts_dir" -name "EMERGENCY_BALLAST" -delete +} + +---- +---- + +docker volume inspect bzlhome +---- +[ + { + "CreatedAt": "2022-02-04T03:10:06Z", + "Driver": "local", + "Labels": {}, + "Mountpoint": "/var/lib/docker/volumes/bzlhome/_data", + "Name": "bzlhome", + "Options": {}, + "Scope": "local" + } +] + +mkdir crdb-checkout/artifacts +---- + +docker run --rm -i -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 503:503 cockroachdb/bazel:20220121-121551 +---- + +which docker +---- +/usr/local/bin/docker + +id +---- +503:20 + +cat crdb-checkout/build/teamcity-bazel-support.sh +---- +---- +# FYI: You can run `./dev builder` to run this Docker image. :) +# `dev` depends on this variable! Don't change the name or format unless you +# also update `dev` accordingly. +BAZEL_IMAGE=cockroachdb/bazel:20220121-121551 + +# Call `run_bazel $NAME_OF_SCRIPT` to start an appropriately-configured Docker +# container with the `cockroachdb/bazel` image running the given script. +# BAZEL_SUPPORT_EXTRA_DOCKER_ARGS will be passed on to `docker run` unchanged. +run_bazel() { + if [ -z "${root:-}" ] + then + echo '$root is not set; please source teamcity-support.sh' + exit 1 + fi + + # Set up volumes. + # TeamCity uses git alternates, so make sure we mount the path to the real + # git objects. + teamcity_alternates="/home/agent/system/git" + vols="--volume ${teamcity_alternates}:${teamcity_alternates}:ro" + artifacts_dir=$root/artifacts + mkdir -p "$artifacts_dir" + vols="${vols} --volume ${artifacts_dir}:/artifacts" + cache=/home/agent/.bzlhome + mkdir -p $cache + vols="${vols} --volume ${root}:/go/src/github.com/cockroachdb/cockroach" + vols="${vols} --volume ${cache}:/home/roach" + + docker run -i ${tty-} --rm --init \ + -u "$(id -u):$(id -g)" \ + --workdir="/go/src/github.com/cockroachdb/cockroach" \ + ${BAZEL_SUPPORT_EXTRA_DOCKER_ARGS:+$BAZEL_SUPPORT_EXTRA_DOCKER_ARGS} \ + ${vols} \ + $BAZEL_IMAGE "$@" +} + +# local copy of tc_release_branch from teamcity-support.sh to avoid imports. +_tc_release_branch() { + [[ "$TC_BUILD_BRANCH" == master || "$TC_BUILD_BRANCH" == release-* || "$TC_BUILD_BRANCH" == provisional_* ]] +} + +# process_test_json processes logs and submits failures to GitHub +# Requires GITHUB_API_TOKEN set for the release branches. +# Accepts 5 arguments: +# testfilter: path to the `testfilter` executable, usually +# `$BAZEL_BIN/pkg/cmd/testfilter/testfilter_/testfilter` +# github_post: path to the `github-post` executable, usually +# `$BAZEL_BIN/pkg/cmd/github-post/github-post_/github-post` +# artifacts_dir: usually `/artifacts` +# test_json: path to test's JSON output, usually generated by `rules_go`'s and +# `GO_TEST_JSON_OUTPUT_FILE`. +# create_tarball: whether to create a tarball with full logs. If the test's +# exit code is passed, the tarball is generated on failures. +process_test_json() { + local testfilter=$1 + local github_post=$2 + local artifacts_dir=$3 + local test_json=$4 + local create_tarball=$5 + + $testfilter -mode=strip < "$test_json" | $testfilter -mode=omit | $testfilter -mode=convert > "$artifacts_dir"/failures.txt + failures_size=$(stat --format=%s "$artifacts_dir"/failures.txt) + if [ $failures_size = 0 ]; then + rm -f "$artifacts_dir"/failures.txt + fi + + if _tc_release_branch; then + if [ -z "${GITHUB_API_TOKEN-}" ]; then + # GITHUB_API_TOKEN must be in the env or github-post will barf if it's + # ever asked to post, so enforce that on all runs. + # The way this env var is made available here is quite tricky. The build + # calling this method is usually a build that is invoked from PRs, so it + # can't have secrets available to it (for the PR could modify + # build/teamcity-* to leak the secret). Instead, we provide the secrets + # to a higher-level job (Publish Bleeding Edge) and use TeamCity magic to + # pass that env var through when it's there. This means we won't have the + # env var on PR builds, but we'll have it for builds that are triggered + # from the release branches. + echo "GITHUB_API_TOKEN must be set" + exit 1 + else + $github_post < "$test_json" + fi + fi + + if [ "$create_tarball" -ne 0 ]; then + # Keep the debug file around for failed builds. Compress it to avoid + # clogging the agents with stuff we'll hopefully rarely ever need to + # look at. + # If the process failed, also save the full human-readable output. This is + # helpful in cases in which tests timed out, where it's difficult to blame + # the failure on any particular test. It's also a good alternative to poking + # around in test.json.txt itself when anything else we don't handle well happens, + # whatever that may be. + $testfilter -mode=convert < "$test_json" > "$artifacts_dir"/full_output.txt + (cd "$artifacts_dir" && tar --strip-components 1 -czf full_output.tgz full_output.txt $(basename $test_json)) + rm -rf "$artifacts_dir"/full_output.txt + fi + + # Some unit tests test automatic ballast creation. These ballasts can be + # larger than the maximum artifact size. Remove any artifacts with the + # EMERGENCY_BALLAST filename. + find "$artifacts_dir" -name "EMERGENCY_BALLAST" -delete +} + +---- +---- + +docker volume inspect bzlhome +---- +[ + { + "CreatedAt": "2022-02-04T03:10:06Z", + "Driver": "local", + "Labels": {}, + "Mountpoint": "/var/lib/docker/volumes/bzlhome/_data", + "Name": "bzlhome", + "Options": {}, + "Scope": "local" + } +] + +mkdir crdb-checkout/artifacts +---- + +docker run --rm -i -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 503:503 cockroachdb/bazel:20220121-121551 echo hi +---- + diff --git a/pkg/cmd/dev/testdata/recorderdriven/dev-build b/pkg/cmd/dev/testdata/recorderdriven/dev-build new file mode 100644 index 000000000000..43089f074760 --- /dev/null +++ b/pkg/cmd/dev/testdata/recorderdriven/dev-build @@ -0,0 +1,15 @@ +dev build pkg/roachpb:roachpb_test --skip-generate +---- +bazel query pkg/roachpb:roachpb_test --output=label_kind +bazel build //pkg/roachpb:roachpb_test --config=test +bazel info workspace --color=no +mkdir crdb-checkout/bin +bazel info bazel-bin --color=no + +# TODO(irfansharif): This test case is skipped -- it's too verbose given it +# scans through the sandbox for each generated file and copies them over +# one-by-one manually. Probably we want to push the logic down into bazel +# itself the same way we do now for protobufs. +# +# dev build cockroach-short +# ---- diff --git a/pkg/cmd/dev/testdata/recorderdriven/dev-build.rec b/pkg/cmd/dev/testdata/recorderdriven/dev-build.rec new file mode 100644 index 000000000000..65673788e72f --- /dev/null +++ b/pkg/cmd/dev/testdata/recorderdriven/dev-build.rec @@ -0,0 +1,10 @@ +bazel query pkg/roachpb:roachpb_test --output=label_kind +---- +go_test rule //pkg/roachpb:roachpb_test + +bazel build //pkg/roachpb:roachpb_test --config=test +---- + +mkdir crdb-checkout/bin +---- + diff --git a/pkg/cmd/dev/testdata/recorderdriven/generate b/pkg/cmd/dev/testdata/recorderdriven/generate new file mode 100644 index 000000000000..c6bd0add0448 --- /dev/null +++ b/pkg/cmd/dev/testdata/recorderdriven/generate @@ -0,0 +1,15 @@ +# TODO(irfansharif): This test case is skipped -- it's too verbose given it +# scans through the sandbox for each generated file and copies them over +# one-by-one manually. +# +# dev gen docs +# ---- + +# TODO(irfansharif): This test case is skipped -- it's too verbose given it +# scans through the sandbox for each generated file and copies them over +# one-by-one manually. Probably for this and above, we want to push the logic +# down into bazel itself the same way we do now for protobufs. Alternatively, +# stop checking in these generated doc files. +# +# dev gen go +# ---- diff --git a/pkg/cmd/dev/testdata/recorderdriven/generate.rec b/pkg/cmd/dev/testdata/recorderdriven/generate.rec new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pkg/cmd/dev/testdata/recording/bench.txt b/pkg/cmd/dev/testdata/recording/bench.txt deleted file mode 100644 index cc43393b5358..000000000000 --- a/pkg/cmd/dev/testdata/recording/bench.txt +++ /dev/null @@ -1,24 +0,0 @@ -find pkg/util -type d ----- -pkg/util -pkg/util/uuid - -git grep -l '^func Benchmark' -- 'pkg/util/*_test.go' ----- -pkg/util/topk_test.go -pkg/util/uuid/benchmark_fast_test.go -pkg/util/uuid/codec_test.go -pkg/util/uuid/generator_test.go - -bazel run --config=test --test_sharding_strategy=disabled //pkg/util:util_test -- -test.run=- -test.bench=. ----- - -bazel run --config=test --test_sharding_strategy=disabled //pkg/util/uuid:uuid_test -- -test.run=- -test.bench=. ----- - -find pkg/sql/parser -type d ----- -pkg/sql/parser - -bazel run --config=test --test_sharding_strategy=disabled //pkg/sql/parser:parser_test -- -test.run=- -test.bench=BenchmarkParse ----- diff --git a/pkg/cmd/dev/testdata/recording/build.txt b/pkg/cmd/dev/testdata/recording/build.txt deleted file mode 100644 index c2a9d09667f4..000000000000 --- a/pkg/cmd/dev/testdata/recording/build.txt +++ /dev/null @@ -1,223 +0,0 @@ -bazel build //pkg/cmd/cockroach-short:cockroach-short ----- - -bazel info workspace --color=no ----- -go/src/github.com/cockroachdb/cockroach - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -bazel build --local_cpu_resources=12 //pkg/cmd/cockroach-short:cockroach-short ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -bazel build //pkg/cmd/cockroach-short:cockroach-short ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -bazel build --remote_local_fallback --remote_cache=grpc://127.0.0.1:9090 --experimental_remote_downloader=grpc://127.0.0.1:9090 //pkg/cmd/cockroach-short:cockroach-short ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -bazel build //pkg/cmd/cockroach-short:cockroach-short //:go_path ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -git status --ignored --short go/src/github.com/cockroachdb/cockroach/pkg ----- ----- - M pkg/some_modified_file.go -?? pkg/some_unknown_file.go -!! pkg/file_to_delete.go -!! pkg/zcgo_flags_file_to_ignore.go -!! pkg/ui/node_modules/ ----- ----- - -rm pkg/file_to_delete.go ----- - -find /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach -name *.go ----- ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go ----- ----- - -cat go/src/github.com/cockroachdb/cockroach/build/bazelutil/checked_in_genfiles.txt ----- ----- -# Comment -//pkg/roachpb:gen-batch-generated|batch_generated-gen.go|batch_generated.go -//pkg/sql/opt/optgen/lang:gen-expr|expr-gen.og.go|expr.og.go -//pkg/sql/opt/optgen/lang:gen-operator|operator-gen.og.go|operator.og.go ----- ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr.og.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator.og.go ----- - -bazel build //pkg/cmd/cockroach-short:cockroach-short -s ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short go/src/github.com/cockroachdb/cockroach/cockroach-short ----- - -bazel run @nodejs//:yarn -- --check-files --cwd pkg/ui --offline ----- - -bazel build //pkg/cmd/cockroach:cockroach --config=with_ui --verbose_failures --sandbox_debug ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/cockroach ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/cmd/cockroach/cockroach_/cockroach go/src/github.com/cockroachdb/cockroach/cockroach ----- - -bazel query @com_github_cockroachdb_stress//:stress --output=label_kind ----- -go_binary rule @com_github_cockroachdb_stress//:stress - -bazel build @com_github_cockroachdb_stress//:stress ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/bin/stress ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/external/com_github_cockroachdb_stress/stress_/stress go/src/github.com/cockroachdb/cockroach/bin/stress ----- - -bazel query pkg/roachpb:roachpb_test --output=label_kind ----- -go_test rule //pkg/roachpb:roachpb_test - -bazel build //pkg/roachpb:roachpb_test --config=test ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -bazel query pkg/foo/... --output=label_kind ----- ----- -go_binary rule //pkg/foo:bar -go_test rule //pkg/foo:baz -go_proto_library rule //pkg/foo:bar_proto_library ----- ----- - -bazel build //pkg/foo:bar //pkg/foo:baz --config=test ----- - -mkdir go/src/github.com/cockroachdb/cockroach/bin ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -rm go/src/github.com/cockroachdb/cockroach/bin/bar ----- - -ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/pkg/foo/bar_/bar go/src/github.com/cockroachdb/cockroach/bin/bar ----- diff --git a/pkg/cmd/dev/testdata/recording/builder.txt b/pkg/cmd/dev/testdata/recording/builder.txt deleted file mode 100644 index 4739fb3f9ae1..000000000000 --- a/pkg/cmd/dev/testdata/recording/builder.txt +++ /dev/null @@ -1,33 +0,0 @@ -id ----- -1001:1002 - -cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh ----- -BAZEL_IMAGE=mock_bazel_image:1234 - -docker volume inspect bzlhome ----- - -mkdir go/src/github.com/cockroachdb/cockroach/artifacts ----- - -docker run --rm -it -v go/src/github.com/cockroachdb/cockroach:/cockroach --workdir=/cockroach -v go/src/github.com/cockroachdb/cockroach/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 1001:1002 mock_bazel_image:1234 ----- - -id ----- -1001:1002 - -cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh ----- -BAZEL_IMAGE=mock_bazel_image:1234 - -docker volume inspect bzlhome ----- - -mkdir go/src/github.com/cockroachdb/cockroach/artifacts ----- - -docker run --rm -it -v go/src/github.com/cockroachdb/cockroach:/cockroach --workdir=/cockroach -v go/src/github.com/cockroachdb/cockroach/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 1001:1002 mock_bazel_image:1234 echo hi ----- diff --git a/pkg/cmd/dev/testdata/recording/generate.txt b/pkg/cmd/dev/testdata/recording/generate.txt deleted file mode 100644 index 24222cb86aa1..000000000000 --- a/pkg/cmd/dev/testdata/recording/generate.txt +++ /dev/null @@ -1,149 +0,0 @@ -go/src/github.com/cockroachdb/cockroach/build/bazelutil/bazel-generate.sh ----- - -cat go/src/github.com/cockroachdb/cockroach/docs/generated/bazel_targets.txt ----- ----- -This line is ignored. - -//docs/generated:gen-logging-md -//docs/generated/sql ----- ----- - -bazel build //docs/generated:gen-logging-md //docs/generated/sql ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - -bazel query --output=xml //docs/generated:gen-logging-md ----- ----- - - - - - - - - - - - - - - - - - - ----- ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/logging.md go/src/github.com/cockroachdb/cockroach/docs/generated/logging.md ----- - -bazel query --output=xml //docs/generated/sql ----- ----- - - - - - - - - - - - - - - - - - - - - - ----- ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/aggregates.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/aggregates.md ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/functions.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/functions.md ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/operators.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/operators.md ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/docs/generated/sql/window_functions.md go/src/github.com/cockroachdb/cockroach/docs/generated/sql/window_functions.md ----- - -go/src/github.com/cockroachdb/cockroach/build/bazelutil/generate_redact_safe.sh ----- -MOCK_REDACT_SAFE_OUTPUT - -echo MOCK_REDACT_SAFE_OUTPUT > go/src/github.com/cockroachdb/cockroach/docs/generated/redact_safe.md ----- - -bazel build //:go_path --show_result=0 ----- - -bazel info bazel-bin --color=no ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin - - -git status --ignored --short go/src/github.com/cockroachdb/cockroach/pkg ----- ----- - M pkg/some_modified_file.go -?? pkg/some_unknown_file.go -!! pkg/file_to_delete.go -!! pkg/zcgo_flags_file_to_ignore.go -!! pkg/ui/node_modules/ ----- ----- - -rm pkg/file_to_delete.go ----- - -find /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach -name *.go ----- ----- -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go -/private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go ----- ----- - -cat go/src/github.com/cockroachdb/cockroach/build/bazelutil/checked_in_genfiles.txt ----- ----- -# Comment -//pkg/roachpb:gen-batch-generated|batch_generated-gen.go|batch_generated.go -//pkg/sql/opt/optgen/lang:gen-expr|expr-gen.og.go|expr.og.go -//pkg/sql/opt/optgen/lang:gen-operator|operator-gen.og.go|operator.og.go ----- ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/storage_services.pb.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated-gen.go go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/expr.og.go ----- - -cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/bazel-out/darwin-fastbuild/bin/go_path/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator-gen.og.go go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang/operator.og.go ----- diff --git a/pkg/cmd/dev/testdata/recording/lint.txt b/pkg/cmd/dev/testdata/recording/lint.txt deleted file mode 100644 index 1f53e2e199f3..000000000000 --- a/pkg/cmd/dev/testdata/recording/lint.txt +++ /dev/null @@ -1,5 +0,0 @@ -bazel run --config=test //build/bazelutil:lint -- -test.v ----- - -bazel run --config=test //build/bazelutil:lint -- -test.v -test.short -test.timeout 5m0s ----- diff --git a/pkg/cmd/dev/testdata/recording/logic.txt b/pkg/cmd/dev/testdata/recording/logic.txt deleted file mode 100644 index e19a7b132797..000000000000 --- a/pkg/cmd/dev/testdata/recording/logic.txt +++ /dev/null @@ -1,14 +0,0 @@ -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/logictest:logictest_test --test_filter TestLogic/// ----- - -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/ccl/logictestccl:logictestccl_test --test_filter 'Test(CCL|Tenant)Logic///' ----- - -bazel test --test_env=GOTRACEBACK=all --test_output errors //pkg/sql/opt/exec/execbuilder:execbuilder_test --test_filter TestExecBuild/// ----- - -bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_arg -config --test_arg local --test_output errors //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^prepare|fk$/20042' ----- - -bazel test --test_env=GOTRACEBACK=all --test_arg -test.v --test_arg -show-logs --test_timeout=50 --test_arg -show-sql --test_arg -config --test_arg local --test_output all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/sql/logictest //pkg/sql/logictest:logictest_test --test_filter 'TestLogic/^local$/^auto_span_config_reconciliation_job$/' ----- diff --git a/pkg/cmd/dev/testdata/recording/test.txt b/pkg/cmd/dev/testdata/recording/test.txt deleted file mode 100644 index 884f6cbc3985..000000000000 --- a/pkg/cmd/dev/testdata/recording/test.txt +++ /dev/null @@ -1,268 +0,0 @@ -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors ----- ----- -//pkg/util/tracing:tracing_test PASSED in 0.2s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing/...)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors ----- ----- -//pkg/util/tracing:tracing_test (cached) PASSED in 0.2s - -Executed 0 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors ----- ----- -//pkg/util/tracing:tracing_test PASSED in 0.1s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_arg -test.v --test_arg -show-logs --test_output all ----- ----- -==================== Test output for //pkg/util/tracing:tracing_test: -testing: warning: no tests to run -PASS -================================================================================ -//pkg/util/tracing:tracing_test PASSED in 0.1s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test --remote_local_fallback --remote_cache=grpc://127.0.0.1:9092 --experimental_remote_downloader=grpc://127.0.0.1:9092 //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors ----- ----- -//pkg/util/tracing:tracing_test (cached) PASSED in 0.0s - -Executed 0 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --nocache_test_results --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors ----- ----- -//pkg/util/tracing:tracing_test PASSED in 0.1s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' '--test_filter=TestStartChild*' --test_output streamed ----- ----- -//pkg/util/tracing:tracing_test PASSED in 12.3s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test --local_cpu_resources=12 --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -p=12 ' '--test_filter=TestStartChild*' --test_output streamed ----- ----- -//pkg/util/tracing:tracing_test PASSED in 12.3s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=70 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=10s ' '--test_filter=TestStartChild*' --test_arg -test.v --test_output streamed ----- ----- -==================== Test output for //pkg/util/tracing:tracing_test: -232 runs so far, 0 failures, over 5s -528 runs so far, 0 failures, over 10s -528 runs completed, 0 failures, over 10s -SUCCESS -================================================================================ -//pkg/util/tracing:tracing_test PASSED in 10.1s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/testutils -type d ----- -pkg/testutils - -bazel query 'kind(go_test, //pkg/testutils:all)' ----- -//pkg/testutils:testutils_test - -bazel test //pkg/testutils:testutils_test --test_env=GOTRACEBACK=all --test_timeout=10 --test_output errors ----- ----- -Loading: -Loading: 0 packages loaded -INFO: Build option --test_timeout has changed, discarding analysis cache. -Analyzing: target //pkg/testutils:testutils_test (0 packages loaded, 0 targets configured) -INFO: Analyzed target //pkg/testutils:testutils_test (0 packages loaded, 11870 targets configured). -INFO: Found 1 test target... -[0 / 2] [Prepa] BazelWorkspaceStatusAction stable-status.txt -[1,220 / 1,221] GoLink pkg/testutils/testutils_test_/testutils_test; 0s darwin-sandbox -[1,221 / 1,222] Testing //pkg/testutils:testutils_test; 0s darwin-sandbox -Target //pkg/testutils:testutils_test up-to-date: - _bazel/bin/pkg/testutils/testutils_test_/testutils_test -INFO: Elapsed time: 4.336s, Critical Path: 2.79s -INFO: 3 processes: 1 internal, 2 darwin-sandbox. -INFO: Build completed successfully, 3 total actions -//pkg/testutils:testutils_test PASSED in 0.8s - -Executed 1 out of 1 test: 1 test passes. -INFO: Build completed successfully, 3 total actions - ----- ----- - -find pkg/util/tracing -type d ----- -pkg/util/tracing - -bazel query 'kind(go_test, //pkg/util/tracing:all)' ----- -//pkg/util/tracing:tracing_test - -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors -s ----- ----- -//pkg/util/tracing:tracing_test PASSED in 0.2s - -Executed 1 out of 1 test: 1 test passes. ----- ----- - -find pkg/roachpb -type d ----- -pkg/roachpb - -bazel query 'kind(go_test, //pkg/roachpb:all)' ----- ----- -//pkg/roachpb:roachpb_test -//pkg/roachpb:string_test ----- ----- - -bazel test //pkg/roachpb:roachpb_test //pkg/roachpb:string_test --test_env=GOTRACEBACK=all --test_output errors ----- - -find pkg/roachpb -type d ----- -pkg/roachpb - -bazel query 'kind(go_test, //pkg/roachpb:string_test)' ----- -//pkg/roachpb:string_test - -bazel test //pkg/roachpb:string_test --test_env=GOTRACEBACK=all --test_output errors ----- - -find pkg/testutils -type d ----- -pkg/testutils - -bazel query 'kind(go_test, //pkg/testutils:all)' ----- -//pkg/testutils:testutils_test - -bazel test //pkg/testutils:testutils_test --test_env=GOTRACEBACK=all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/testutils --test_output errors ----- - -find pkg/testutils -type d ----- -pkg/testutils - -bazel query 'kind(go_test, //pkg/testutils:all)' ----- -//pkg/testutils:testutils_test - -find pkg/other/test -type d ----- -pkg/other/test - -bazel query 'kind(go_test, //pkg/other/test:all)' ----- -//pkg/other/test:test_test - -bazel test //pkg/testutils:testutils_test //pkg/other/test:test_test --test_env=GOTRACEBACK=all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/testutils --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/other/test --test_output errors ----- diff --git a/pkg/cmd/dev/testdata/recording/ui.txt b/pkg/cmd/dev/testdata/recording/ui.txt deleted file mode 100644 index 04704e30e230..000000000000 --- a/pkg/cmd/dev/testdata/recording/ui.txt +++ /dev/null @@ -1,48 +0,0 @@ -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 ----- - - -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=oss --env.target=http://localhost:8080 --port 3000 ----- - - -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 --https ----- - - -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://example.crdb.io:4848 --port 3000 ----- - - -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch ----- - -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 12345 ----- diff --git a/pkg/cmd/dev/testdata/test.txt b/pkg/cmd/dev/testdata/test.txt deleted file mode 100644 index 16f78ef0c326..000000000000 --- a/pkg/cmd/dev/testdata/test.txt +++ /dev/null @@ -1,91 +0,0 @@ -dev test pkg/util/tracing ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors - -dev test pkg/util/tracing/... ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing/...)' -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors - -dev test pkg/util/tracing -f TestStartChild* ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors - -dev test pkg/util/tracing -f TestStartChild* -v --show-logs ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_arg -test.v --test_arg -show-logs --test_output all - -dev test pkg/util/tracing -f TestStartChild* --remote-cache 127.0.0.1:9092 ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test --remote_local_fallback --remote_cache=grpc://127.0.0.1:9092 --experimental_remote_downloader=grpc://127.0.0.1:9092 //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors - -dev test pkg/util/tracing -f TestStartChild* --ignore-cache ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test //pkg/util/tracing:tracing_test --nocache_test_results --test_env=GOTRACEBACK=all '--test_filter=TestStartChild*' --test_output errors - -dev test --stress pkg/util/tracing --filter TestStartChild* ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' '--test_filter=TestStartChild*' --test_output streamed - -dev test --stress pkg/util/tracing --filter TestStartChild* --cpus=12 ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test --local_cpu_resources=12 --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -p=12 ' '--test_filter=TestStartChild*' --test_output streamed - -dev test --stress pkg/util/tracing --filter TestStartChild* --timeout=10s -v ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_timeout=70 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=10s ' '--test_filter=TestStartChild*' --test_arg -test.v --test_output streamed - -dev test //pkg/testutils --timeout=10s ----- -find pkg/testutils -type d -bazel query 'kind(go_test, //pkg/testutils:all)' -bazel test //pkg/testutils:testutils_test --test_env=GOTRACEBACK=all --test_timeout=10 --test_output errors - -dev test pkg/util/tracing -- -s ----- -find pkg/util/tracing -type d -bazel query 'kind(go_test, //pkg/util/tracing:all)' -bazel test //pkg/util/tracing:tracing_test --test_env=GOTRACEBACK=all --test_output errors -s - -dev test ./pkg/roachpb ----- -find pkg/roachpb -type d -bazel query 'kind(go_test, //pkg/roachpb:all)' -bazel test //pkg/roachpb:roachpb_test //pkg/roachpb:string_test --test_env=GOTRACEBACK=all --test_output errors - -dev test pkg/roachpb:string_test ----- -find pkg/roachpb -type d -bazel query 'kind(go_test, //pkg/roachpb:string_test)' -bazel test //pkg/roachpb:string_test --test_env=GOTRACEBACK=all --test_output errors - -dev test //pkg/testutils --rewrite ----- -find pkg/testutils -type d -bazel query 'kind(go_test, //pkg/testutils:all)' -bazel test //pkg/testutils:testutils_test --test_env=GOTRACEBACK=all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/testutils --test_output errors - -dev test //pkg/testutils pkg/other/test --rewrite ----- -find pkg/testutils -type d -bazel query 'kind(go_test, //pkg/testutils:all)' -find pkg/other/test -type d -bazel query 'kind(go_test, //pkg/other/test:all)' -bazel test //pkg/testutils:testutils_test //pkg/other/test:test_test --test_env=GOTRACEBACK=all --test_env=COCKROACH_WORKSPACE=go/src/github.com/cockroachdb/cockroach --test_arg -rewrite --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/testutils --sandbox_writable_path=go/src/github.com/cockroachdb/cockroach/pkg/other/test --test_output errors diff --git a/pkg/cmd/dev/testdata/ui.txt b/pkg/cmd/dev/testdata/ui.txt deleted file mode 100644 index 4ba163682570..000000000000 --- a/pkg/cmd/dev/testdata/ui.txt +++ /dev/null @@ -1,29 +0,0 @@ -dev ui watch ----- -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 - -dev ui watch --oss ----- -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=oss --env.target=http://localhost:8080 --port 3000 - -dev ui watch --secure ----- -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 3000 --https - -dev ui watch --db http://example.crdb.io:4848 ----- -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://example.crdb.io:4848 --port 3000 - -dev ui watch --port 12345 ----- -bazel build //pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client //pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/cluster-ui build:watch -yarn --silent --cwd go/src/github.com/cockroachdb/cockroach/pkg/ui/workspaces/db-console webpack-dev-server --config webpack.app.js --mode development --env.WEBPACK_SERVE --env.dist=ccl --env.target=http://localhost:8080 --port 12345 diff --git a/pkg/cmd/dev/ui.go b/pkg/cmd/dev/ui.go index 7e85044b51a5..fc3c56eac456 100644 --- a/pkg/cmd/dev/ui.go +++ b/pkg/cmd/dev/ui.go @@ -174,11 +174,6 @@ Replaces 'make ui-watch'.`, return err } - // Wait for OS signals to cancel if we're not in test-mode - if !isTesting { - <-ctx.Done() - } - return nil }, } diff --git a/pkg/cmd/dev/util.go b/pkg/cmd/dev/util.go index 71beb608abe8..564c1aac04a3 100644 --- a/pkg/cmd/dev/util.go +++ b/pkg/cmd/dev/util.go @@ -36,9 +36,6 @@ var ( // Shared flags. remoteCacheAddr string numCPUs int - - // To be turned on for tests. Turns off some deeper checks for reproducibility. - isTesting bool ) func mustGetFlagString(cmd *cobra.Command, name string) string { @@ -112,31 +109,26 @@ func (d *dev) getBazelInfo(ctx context.Context, key string) (string, error) { } -var workspace string - func (d *dev) getWorkspace(ctx context.Context) (string, error) { - if workspace == "" { - if _, err := os.Stat("WORKSPACE"); err == nil { - w, err := os.Getwd() - if err != nil { - return "", err - } - workspace = w - } else { - w, err := d.getBazelInfo(ctx, "workspace") - if err != nil { - return "", err - } - workspace = w - } + if _, err := os.Stat("WORKSPACE"); err == nil { + return os.Getwd() } - return workspace, nil + + return d.getBazelInfo(ctx, "workspace") } func (d *dev) getBazelBin(ctx context.Context) (string, error) { return d.getBazelInfo(ctx, "bazel-bin") } +// getDevBin returns the path to the running dev executable. +func (d *dev) getDevBin() string { + if d.knobs.devBinOverride != "" { + return d.knobs.devBinOverride + } + return os.Args[0] +} + func addCommonBuildFlags(cmd *cobra.Command) { cmd.Flags().IntVar(&numCPUs, "cpus", 0, "cap the number of cpu cores used") // This points to the grpc endpoint of a running `buchr/bazel-remote` @@ -154,10 +146,8 @@ func addCommonTestFlags(cmd *cobra.Command) { } func (d *dev) ensureBinaryInPath(bin string) error { - if !isTesting { - if _, err := d.exec.LookPath(bin); err != nil { - return fmt.Errorf("could not find %s in PATH", bin) - } + if _, err := d.exec.LookPath(bin); err != nil { + return fmt.Errorf("could not find %s in PATH", bin) } return nil } @@ -238,66 +228,9 @@ func splitArgsAtDash(cmd *cobra.Command, args []string) (before, after []string) return } -// parsePkg decomposes and validates a "pkg/.*" argument passed to the test or -// the bench commands. -func (d *dev) parsePkg(pkg string) (dir string, isRecursive bool, tag string, _ error) { - dir = pkg - - // Trim left. - dir = strings.TrimPrefix(dir, "//") - dir = strings.TrimPrefix(dir, "./") - if !strings.HasPrefix(dir, "pkg/") { - return "", false, "", fmt.Errorf( - "malformed package %q, expecting %q", pkg, "pkg/{...}") - } - - // Trim right. - dir = strings.TrimRight(dir, "/") - { - parts := strings.Split(dir, ":") - switch len(parts) { - case 0: - return "", false, "", fmt.Errorf( - "malformed package %q, expecting %q", pkg, "pkg/{...}") - case 1: - break - case 2: - dir = parts[0] - tag = parts[1] - default: - return "", false, "", fmt.Errorf( - "malformed package %q, expected at most one ':'", pkg) - } - } - const recursiveSuffix = "/..." - isRecursive = strings.HasSuffix(dir, recursiveSuffix) - if isRecursive { - dir = dir[:len(dir)-len(recursiveSuffix)] - if tag != "" { - return "", false, "", fmt.Errorf( - "malformed package %q, cannot end in %q and be followed by a tag", pkg, recursiveSuffix) - } - } - - // Check directory existence. - if ok, err := d.os.IsDir(dir); err != nil || !ok { - return "", false, "", fmt.Errorf( - "malformed package %q, %q is not an existing directory", pkg, dir) - } - return dir, isRecursive, tag, nil -} - func logCommand(cmd string, args ...string) { var fullArgs []string fullArgs = append(fullArgs, cmd) fullArgs = append(fullArgs, args...) log.Printf("$ %s", shellescape.QuoteCommand(fullArgs)) } - -// getDevBin returns the path to the running dev executable. -func getDevBin() string { - if isTesting { - return "dev" - } - return os.Args[0] -} diff --git a/pkg/testutils/lint/lint_test.go b/pkg/testutils/lint/lint_test.go index a204987ea9f4..987000d9c0ce 100644 --- a/pkg/testutils/lint/lint_test.go +++ b/pkg/testutils/lint/lint_test.go @@ -2192,6 +2192,7 @@ func TestLint(t *testing.T) { }) t.Run("CODEOWNERS", func(t *testing.T) { + skip.UnderBazel(t, "doesn't work under bazel") co, err := codeowners.DefaultLoadCodeOwners() require.NoError(t, err) const verbose = false diff --git a/pkg/testutils/skip/skip.go b/pkg/testutils/skip/skip.go index 6be83ff2bb5f..932fc7e308f8 100644 --- a/pkg/testutils/skip/skip.go +++ b/pkg/testutils/skip/skip.go @@ -89,6 +89,14 @@ func UnderRaceWithIssue(t SkippableTest, githubIssueID int, args ...interface{}) } } +// UnderBazel skips this test if run under bazel. +func UnderBazel(t SkippableTest, args ...interface{}) { + t.Helper() + if bazel.BuiltWithBazel() { + t.Skip(append([]interface{}{"disabled under bazel"}, args...)) + } +} + // UnderBazelWithIssue skips this test if we are building inside bazel, // logging the given issue ID as the reason. func UnderBazelWithIssue(t SkippableTest, githubIssueID int, args ...interface{}) { diff --git a/vendor b/vendor index b983eaeec06c..1474933a93ac 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit b983eaeec06c55f94be2047b53c8528dc617e6d7 +Subproject commit 1474933a93ac2c005a5c8455b5a0bac6a584933b