1
- // Copyright 2018 The go-python Authors. All rights reserved.
1
+ // Copyright © 2018 The go-python Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
+ //go:build ignore
5
6
// +build ignore
6
7
7
8
package main
@@ -10,32 +11,33 @@ import (
10
11
"bufio"
11
12
"bytes"
12
13
"flag"
13
- "io/ioutil "
14
+ "fmt "
14
15
"log"
15
16
"os"
16
17
"os/exec"
17
18
"strings"
19
+ "time"
18
20
)
19
21
20
22
func main () {
21
23
log .SetPrefix ("ci: " )
22
24
log .SetFlags (0 )
23
25
26
+ start := time .Now ()
27
+ defer func () {
28
+ log .Printf ("elapsed time: %v\n " , time .Since (start ))
29
+ }()
30
+
24
31
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" )
28
36
)
29
37
30
38
flag .Parse ()
31
39
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 ()
39
41
if err != nil {
40
42
log .Fatal (err )
41
43
}
@@ -48,23 +50,24 @@ func main() {
48
50
49
51
args := []string {"test" }
50
52
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 )
53
58
}
54
59
if * tags != "" {
55
60
args = append (args , "-tags=" + * tags )
56
61
}
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" )
59
67
}
60
68
args = append (args , "" )
61
69
62
- scan := bufio .NewScanner (out )
63
- for scan .Scan () {
64
- pkg := scan .Text ()
65
- if strings .Contains (pkg , "vendor" ) {
66
- continue
67
- }
70
+ for _ , pkg := range pkgs {
68
71
args [len (args )- 1 ] = pkg
69
72
cmd := exec .Command ("go" , args ... )
70
73
cmd .Stdin = os .Stdin
@@ -74,8 +77,8 @@ func main() {
74
77
if err != nil {
75
78
log .Fatal (err )
76
79
}
77
- if * cover {
78
- profile , err := ioutil .ReadFile ("profile.out" )
80
+ if * cover != "" {
81
+ profile , err := os .ReadFile ("profile.out" )
79
82
if err != nil {
80
83
log .Fatal (err )
81
84
}
@@ -92,3 +95,28 @@ func main() {
92
95
log .Fatal (err )
93
96
}
94
97
}
98
+
99
+ func pkgList () ([]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
+ if err != nil {
108
+ return nil , fmt .Errorf ("could not get package list: %w" , err )
109
+ }
110
+
111
+ var pkgs []string
112
+ scan := bufio .NewScanner (out )
113
+ for scan .Scan () {
114
+ pkg := scan .Text ()
115
+ if strings .Contains (pkg , "vendor" ) {
116
+ continue
117
+ }
118
+ pkgs = append (pkgs , pkg )
119
+ }
120
+
121
+ return pkgs , nil
122
+ }
0 commit comments