Skip to content

Commit 00a8bf6

Browse files
committed
ci: update CI scaffolding
1 parent 71a2bf6 commit 00a8bf6

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

‎ci/run-tests.go‎

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright 2018 The go-python Authors. All rights reserved.
1+
// Copyright ©2018 The go-python Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build ignore
56
// +build ignore
67

78
package main
@@ -10,32 +11,33 @@ import (
1011
"bufio"
1112
"bytes"
1213
"flag"
13-
"io/ioutil"
14+
"fmt"
1415
"log"
1516
"os"
1617
"os/exec"
1718
"strings"
19+
"time"
1820
)
1921

2022
funcmain(){
2123
log.SetPrefix("ci: ")
2224
log.SetFlags(0)
2325

26+
start:=time.Now()
27+
deferfunc(){
28+
log.Printf("elapsed time: %v\n", time.Since(start))
29+
}()
30+
2431
var (
25-
race=flag.Bool("race", false, "enable race detector")
26-
cover=flag.Bool("cover", false, "enable code coverage")
27-
tags=flag.String("tags", "", "build tags")
32+
race=flag.Bool("race", false, "enable race detector")
33+
cover=flag.String("coverpkg", "", "apply coverage analysis in each test to packages matching the patterns.")
34+
tags=flag.String("tags", "", "build tags")
35+
verbose=flag.Bool("v", false, "enable verbose output")
2836
)
2937

3038
flag.Parse()
3139

32-
out:=new(bytes.Buffer)
33-
cmd:=exec.Command("go", "list", "./...")
34-
cmd.Stdout=out
35-
cmd.Stderr=os.Stderr
36-
cmd.Stdin=os.Stdin
37-
38-
err:=cmd.Run()
40+
pkgs, err:=pkgList()
3941
iferr!=nil{
4042
log.Fatal(err)
4143
}
@@ -48,23 +50,24 @@ func main(){
4850

4951
args:= []string{"test"}
5052

51-
if*cover{
52-
args=append(args, "-coverprofile=profile.out", "-covermode=atomic")
53+
if*verbose{
54+
args=append(args, "-v")
55+
}
56+
if*cover!=""{
57+
args=append(args, "-coverprofile=profile.out", "-covermode=atomic", "-coverpkg="+*cover)
5358
}
5459
if*tags!=""{
5560
args=append(args, "-tags="+*tags)
5661
}
57-
if*race{
58-
args=append(args, "-race")
62+
switch{
63+
case*race:
64+
args=append(args, "-race", "-timeout=20m")
65+
default:
66+
args=append(args, "-timeout=10m")
5967
}
6068
args=append(args, "")
6169

62-
scan:=bufio.NewScanner(out)
63-
forscan.Scan(){
64-
pkg:=scan.Text()
65-
ifstrings.Contains(pkg, "vendor"){
66-
continue
67-
}
70+
for_, pkg:=rangepkgs{
6871
args[len(args)-1] =pkg
6972
cmd:=exec.Command("go", args...)
7073
cmd.Stdin=os.Stdin
@@ -74,8 +77,8 @@ func main(){
7477
iferr!=nil{
7578
log.Fatal(err)
7679
}
77-
if*cover{
78-
profile, err:=ioutil.ReadFile("profile.out")
80+
if*cover!=""{
81+
profile, err:=os.ReadFile("profile.out")
7982
iferr!=nil{
8083
log.Fatal(err)
8184
}
@@ -92,3 +95,28 @@ func main(){
9295
log.Fatal(err)
9396
}
9497
}
98+
99+
funcpkgList() ([]string, error){
100+
out:=new(bytes.Buffer)
101+
cmd:=exec.Command("go", "list", "./...")
102+
cmd.Stdout=out
103+
cmd.Stderr=os.Stderr
104+
cmd.Stdin=os.Stdin
105+
106+
err:=cmd.Run()
107+
iferr!=nil{
108+
returnnil, fmt.Errorf("could not get package list: %w", err)
109+
}
110+
111+
varpkgs []string
112+
scan:=bufio.NewScanner(out)
113+
forscan.Scan(){
114+
pkg:=scan.Text()
115+
ifstrings.Contains(pkg, "vendor"){
116+
continue
117+
}
118+
pkgs=append(pkgs, pkg)
119+
}
120+
121+
returnpkgs, nil
122+
}

0 commit comments

Comments
(0)