From 6f020100d3adbf3e31ebeb6e04c09fa889bec556 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 17 Mar 2025 17:05:56 +0800 Subject: [PATCH] build: add command `make quick-test` to save test time --- Makefile | 4 ++++ build/ci.go | 4 ++-- internal/build/util.go | 15 ++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4e71322262..7a63bf119c 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,10 @@ all: test: all go run build/ci.go test +#? quick-test: Run the tests except time-consuming tests. +quick-test: all + go run build/ci.go test --quick + #? lint: Run certain pre-selected linters. lint: ## Run linters. $(GORUN) build/ci.go lint diff --git a/build/ci.go b/build/ci.go index 355f1fb8f2..750ede2421 100644 --- a/build/ci.go +++ b/build/ci.go @@ -219,10 +219,10 @@ func goToolArch(arch string, cc string, subcmd string, args ...string) *exec.Cmd // Running The Tests // // "tests" also includes static analysis tools such as vet. - func doTest(cmdline []string) { coverage := flag.Bool("coverage", false, "Whether to record code coverage") verbose := flag.Bool("v", false, "Whether to log verbosely") + quick := flag.Bool("quick", false, "Whether to skip long time test") flag.CommandLine.Parse(cmdline) env := build.Env() @@ -231,7 +231,7 @@ func doTest(cmdline []string) { packages = flag.CommandLine.Args() } else { // added all files in all packages (except vendor) to coverage report files count, even there is no test file in the package - packages = build.ExpandPackagesNoVendor(packages) + packages = build.ExpandPackages(packages, *quick) } // Run analysis tools before the tests. diff --git a/internal/build/util.go b/internal/build/util.go index 42f57a4681..4ba5135dd3 100644 --- a/internal/build/util.go +++ b/internal/build/util.go @@ -136,9 +136,9 @@ func GoTool(tool string, args ...string) *exec.Cmd { return exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...) } -// ExpandPackagesNoVendor expands a cmd/go import path pattern, skipping -// vendored packages. -func ExpandPackagesNoVendor(patterns []string) []string { +// ExpandPackages expands a cmd/go import path pattern, skip vendor +// packages, and skip time-consuming tests according to quick flag. +func ExpandPackages(patterns []string, quick bool) []string { expand := false for _, pkg := range patterns { if strings.Contains(pkg, "...") { @@ -153,9 +153,14 @@ func ExpandPackagesNoVendor(patterns []string) []string { } var packages []string for _, line := range strings.Split(string(out), "\n") { - if !strings.Contains(line, "/vendor/") { - packages = append(packages, strings.TrimSpace(line)) + if strings.Contains(line, "/vendor/") { + continue } + if quick && strings.Contains(line, "/consensus/tests/engine_v2_tests") { + continue + } + packages = append(packages, strings.TrimSpace(line)) + } return packages }