Skip to content

Commit 6e6162d

Browse files
Pulling back some changes to run.go
1 parent a52c6c1 commit 6e6162d

File tree

1 file changed

+20
-105
lines changed

1 file changed

+20
-105
lines changed

tests/gorepo/run.go

Lines changed: 20 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"sort"
3838
"strconv"
3939
"strings"
40-
"sync"
4140
"time"
4241
"unicode"
4342

@@ -193,15 +192,11 @@ type failReason struct {
193192
// -----------------------------------------------------------------------------
194193

195194
var (
196-
// GOPHERJS: Doesn't support `allCodegen` or `force`.
197195
verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.")
198-
keep = flag.Bool("k", false, "keep. keep temporary directory.")
199196
numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
200197
summary = flag.Bool("summary", false, "show summary of results")
201198
showSkips = flag.Bool("show_skips", false, "show skipped tests")
202-
runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)")
203-
linkshared = flag.Bool("linkshared", false, "")
204-
showKnownFails = flag.Bool("show_known_fails", false, "show full error output of known fails") // GOPHERJS: Added
199+
showKnownFails = flag.Bool("show_known_fails", false, "show full error output of known fails")
205200
updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output")
206201
runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run")
207202

@@ -248,16 +243,14 @@ func main() {
248243
findExecCmd()
249244

250245
// Disable parallelism if using a simulator.
251-
// GOPHERJS: Do not disable parallelism in verbose mode, since Go's file IO had internal
246+
// Do not disable parallelism in verbose mode, since Go's file IO had internal
252247
// r/w locking, which should make significant output garbling very unlikely.
253-
// GOPHERJS: CI setup runs these tests in verbose mode, but it can benefit from
248+
// GopherJS CI setup runs these tests in verbose mode, but it can benefit from
254249
// parallelism a lot.
255250
if len(findExecCmd()) > 0 {
256251
*numParallel = 1
257-
*runoutputLimit = 1
258252
}
259253

260-
// GOPHERJS: Additional verbose output
261254
if *verbose {
262255
fmt.Printf("goos: %q, goarch: %q\n", goos, goarch)
263256
fmt.Printf("parallel: %d\n", *numParallel)
@@ -322,7 +315,6 @@ func main() {
322315
status = "FAIL"
323316
}
324317
if test.err != nil {
325-
// GOPHERJS: Ignore expectFail, see initExpectFail in original go/test/run.go
326318
status = "FAIL"
327319
errStr = test.err.Error()
328320
}
@@ -334,7 +326,6 @@ func main() {
334326
failed = true
335327
}
336328
resCount[status]++
337-
// GOPHERJS.
338329
if status == "skip" && !*verbose && !*showSkips {
339330
continue
340331
}
@@ -369,22 +360,6 @@ func main() {
369360
}
370361
}
371362

372-
// goTool reports the path of the go tool to use to run the tests.
373-
// If possible, use the same Go used to run run.go, otherwise
374-
// fallback to the go version found in the PATH.
375-
func goTool() string {
376-
var exeSuffix string
377-
if runtime.GOOS == "windows" {
378-
exeSuffix = ".exe"
379-
}
380-
path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
381-
if _, err := os.Stat(path); err == nil {
382-
return path
383-
}
384-
// Just run "go" from PATH
385-
return "go"
386-
}
387-
388363
func shardMatch(name string) bool {
389364
if *shards == 0 {
390365
return true
@@ -396,14 +371,10 @@ func shardMatch(name string) bool {
396371

397372
func goFiles(dir string) []string {
398373
f, err := os.Open(dir)
399-
if err != nil {
400-
log.Fatal(err)
401-
}
374+
check(err)
402375
dirnames, err := f.Readdirnames(-1)
403376
f.Close()
404-
if err != nil {
405-
log.Fatal(err)
406-
}
377+
check(err)
407378
names := []string{}
408379
for _, name := range dirnames {
409380
if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") && shardMatch(name) {
@@ -416,80 +387,21 @@ func goFiles(dir string) []string {
416387

417388
type runCmd func(...string) ([]byte, error)
418389

419-
func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
420-
cmd := []string{goTool(), "tool", "compile", "-e", "-p=p", "-importcfg=" + stdlibImportcfgFile()}
421-
cmd = append(cmd, flags...)
422-
if *linkshared {
423-
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
424-
}
425-
cmd = append(cmd, longname)
426-
return runcmd(cmd...)
390+
func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
391+
return runcmd("go", "tool", "compile", "-e", longname)
427392
}
428393

429-
func compileInDir(runcmd runCmd, dir string, flags []string, importcfg string, pkgname string, names ...string) (out []byte, err error) {
430-
if importcfg == "" {
431-
importcfg = stdlibImportcfgFile()
432-
}
433-
cmd := []string{goTool(), "tool", "compile", "-e", "-D", "test", "-importcfg=" + importcfg}
434-
if pkgname == "main" {
435-
cmd = append(cmd, "-p=main")
436-
} else {
437-
pkgname = path.Join("test", strings.TrimSuffix(names[0], ".go"))
438-
cmd = append(cmd, "-o", pkgname+".a", "-p", pkgname)
439-
}
440-
cmd = append(cmd, flags...)
441-
if *linkshared {
442-
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
443-
}
394+
func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) {
395+
cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."}
444396
for _, name := range names {
445397
cmd = append(cmd, filepath.Join(dir, name))
446398
}
447399
return runcmd(cmd...)
448400
}
449401

450-
var stdlibImportcfgString string
451-
var stdlibImportcfgFilename string
452-
var cfgonce sync.Once
453-
var fileonce sync.Once
454-
455-
func stdlibImportcfg() string {
456-
cfgonce.Do(func() {
457-
output, err := exec.Command(goTool(), "list", "-export", "-f", "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}", "std").Output()
458-
if err != nil {
459-
log.Fatal(err)
460-
}
461-
stdlibImportcfgString = string(output)
462-
})
463-
return stdlibImportcfgString
464-
}
465-
466-
func stdlibImportcfgFile() string {
467-
fileonce.Do(func() {
468-
tmpdir, err := os.MkdirTemp("", "importcfg")
469-
if err != nil {
470-
log.Fatal(err)
471-
}
472-
filename := filepath.Join(tmpdir, "importcfg")
473-
os.WriteFile(filename, []byte(stdlibImportcfg()), 0644)
474-
stdlibImportcfgFilename = filename
475-
})
476-
return stdlibImportcfgFilename
477-
}
478-
479-
func linkFile(runcmd runCmd, goname string, importcfg string, ldflags []string) (err error) {
480-
if importcfg == "" {
481-
importcfg = stdlibImportcfgFile()
482-
}
402+
func linkFile(runcmd runCmd, goname string) (err error) {
483403
pfile := strings.Replace(goname, ".go", ".o", -1)
484-
cmd := []string{goTool(), "tool", "link", "-w", "-o", "a.exe", "-importcfg=" + importcfg}
485-
if *linkshared {
486-
cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
487-
}
488-
if ldflags != nil {
489-
cmd = append(cmd, ldflags...)
490-
}
491-
cmd = append(cmd, pfile)
492-
_, err = runcmd(cmd...)
404+
_, err = runcmd("go", "tool", "link", "-w", "-o", "a.exe", "-L", ".", pfile)
493405
return
494406
}
495407

@@ -498,6 +410,12 @@ type skipError string
498410

499411
func (s skipError) Error() string { return string(s) }
500412

413+
func check(err error) {
414+
if err != nil {
415+
log.Fatal(err)
416+
}
417+
}
418+
501419
// test holds the state of a test.
502420
type test struct {
503421
dir, gofile string
@@ -509,10 +427,9 @@ type test struct {
509427

510428
tempDir string
511429
err error
512-
513-
// GOPHERJS: Skipping expectFail, see initExpectFail in go/test/run.go
514430
}
515431

432+
// startTest
516433
func startTest(dir, gofile string) *test {
517434
t := &test{
518435
dir: dir,
@@ -555,7 +472,7 @@ func (t *test) goDirName() string {
555472
}
556473

557474
func goDirFiles(longdir string) (filter []os.DirEntry, err error) {
558-
files, dirErr := os.ReadDir(longdir) // GOPHERJS: Updated to not use deprecated ioutil.ReadDir
475+
files, dirErr := os.ReadDir(longdir)
559476
if dirErr != nil {
560477
return nil, dirErr
561478
}
@@ -615,8 +532,6 @@ func goDirPackages(longdir string, singlefilepkgs bool) ([]*goDirPkg, error) {
615532
type context struct {
616533
GOOS string
617534
GOARCH string
618-
// GOPHERJS: Doesn't support `cgoEnabled` related to CGO_ENABLED
619-
// GOPHERJS: Doesn't support `noOptEnv` related to GO_GCFLAGS
620535
}
621536

622537
// shouldTest looks for build tags in a source file and returns
@@ -702,7 +617,7 @@ func (t *test) run() {
702617
return
703618
}
704619

705-
srcBytes, err := os.ReadFile(t.goFileName()) // GOPHERJS: Updated to no use deprecated ioutil.ReadFile
620+
srcBytes, err := os.ReadFile(t.goFileName())
706621
if err != nil {
707622
t.err = err
708623
return

0 commit comments

Comments
 (0)