Skip to content

Commit 7c1f361

Browse files
Yury Smolskybradfitz
Yury Smolsky
authored andcommitted
test: add comments for all test actions
Every action has a short annotation. The errorCheck function has a comment adapted from errchk script. Removed redundant assigments to tmpDir. Change-Id: Ifdd1284de046a0ce2aad26bd8da8a8e6a7707a8e Reviewed-on: https://go-review.googlesource.com/115856 Run-TryBot: Yury Smolsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 88dc4ae commit 7c1f361

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

test/run.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ func (t *test) run() {
616616
t.err = fmt.Errorf("unimplemented action %q", action)
617617

618618
case "asmcheck":
619+
// Compile Go file and match the generated assembly
620+
// against a set of regexps in comments.
619621
ops := t.wantedAsmOpcodes(long)
620622
for _, env := range ops.Envs() {
621623
cmdline := []string{"build", "-gcflags", "-S"}
@@ -640,6 +642,9 @@ func (t *test) run() {
640642
return
641643

642644
case "errorcheck":
645+
// Compile Go file.
646+
// Fail if wantError is true and compilation was successful and vice versa.
647+
// Match errors produced by gc against errors in comments.
643648
// TODO(gri) remove need for -C (disable printing of columns in error messages)
644649
cmdline := []string{goTool(), "tool", "compile", "-C", "-e", "-o", "a.o"}
645650
// No need to add -dynlink even if linkshared if we're just checking for errors...
@@ -664,10 +669,11 @@ func (t *test) run() {
664669
return
665670

666671
case "compile":
672+
// Compile Go file.
667673
_, t.err = compileFile(runcmd, long, flags)
668674

669675
case "compiledir":
670-
// Compile all files in the directory in lexicographic order.
676+
// Compile all files in the directory as packages in lexicographic order.
671677
longdir := filepath.Join(cwd, t.goDirName())
672678
pkgs, err := goDirPackages(longdir, singlefilepkgs)
673679
if err != nil {
@@ -682,8 +688,9 @@ func (t *test) run() {
682688
}
683689

684690
case "errorcheckdir", "errorcheckandrundir":
685-
// errorcheck all files in lexicographic order
686-
// useful for finding importing errors
691+
// Compile and errorCheck all files in the directory as packages in lexicographic order.
692+
// If errorcheckdir and wantError, compilation of the last package must fail.
693+
// If errorcheckandrundir and wantError, compilation of the package prior the last must fail.
687694
longdir := filepath.Join(cwd, t.goDirName())
688695
pkgs, err := goDirPackages(longdir, singlefilepkgs)
689696
if err != nil {
@@ -725,8 +732,10 @@ func (t *test) run() {
725732
fallthrough
726733

727734
case "rundir":
728-
// Compile all files in the directory in lexicographic order.
729-
// then link as if the last file is the main package and run it
735+
// Compile all files in the directory as packages in lexicographic order.
736+
// In case of errorcheckandrundir, ignore failed compilation of the package before the last.
737+
// Link as if the last file is the main package, run it.
738+
// Verify the expected output.
730739
longdir := filepath.Join(cwd, t.goDirName())
731740
pkgs, err := goDirPackages(longdir, singlefilepkgs)
732741
if err != nil {
@@ -763,14 +772,15 @@ func (t *test) run() {
763772
}
764773

765774
case "build":
775+
// Build Go file.
766776
_, err := runcmd(goTool(), "build", goGcflags(), "-o", "a.exe", long)
767777
if err != nil {
768778
t.err = err
769779
}
770780

771781
case "builddir", "buildrundir":
772782
// Build an executable from all the .go and .s files in a subdirectory.
773-
useTmp = true
783+
// Run it and verify its output in the buildrundir case.
774784
longdir := filepath.Join(cwd, t.goDirName())
775785
files, dirErr := ioutil.ReadDir(longdir)
776786
if dirErr != nil {
@@ -839,9 +849,10 @@ func (t *test) run() {
839849
}
840850
}
841851

842-
case "buildrun": // build binary, then run binary, instead of go run. Useful for timeout tests where failure mode is infinite loop.
852+
case "buildrun":
853+
// Build an executable from Go file, then run it, verify its output.
854+
// Useful for timeout tests where failure mode is infinite loop.
843855
// TODO: not supported on NaCl
844-
useTmp = true
845856
cmd := []string{goTool(), "build", goGcflags(), "-o", "a.exe"}
846857
if *linkshared {
847858
cmd = append(cmd, "-linkshared")
@@ -866,6 +877,9 @@ func (t *test) run() {
866877
}
867878

868879
case "run":
880+
// Run Go file if no special go command flags are provided;
881+
// otherwise build an executable and run it.
882+
// Verify the output.
869883
useTmp = false
870884
var out []byte
871885
var err error
@@ -908,6 +922,8 @@ func (t *test) run() {
908922
}
909923

910924
case "runoutput":
925+
// Run Go file and write its output into temporary Go file.
926+
// Run generated Go file and verify its output.
911927
rungatec <- true
912928
defer func() {
913929
<-rungatec
@@ -943,6 +959,8 @@ func (t *test) run() {
943959
}
944960

945961
case "errorcheckoutput":
962+
// Run Go file and write its output into temporary Go file.
963+
// Compile and errorCheck generated Go file.
946964
useTmp = false
947965
cmd := []string{goTool(), "run", goGcflags()}
948966
if *linkshared {
@@ -1038,6 +1056,17 @@ func splitOutput(out string, wantAuto bool) []string {
10381056
return res
10391057
}
10401058

1059+
// errorCheck matches errors in outStr against comments in source files.
1060+
// For each line of the source files which should generate an error,
1061+
// there should be a comment of the form // ERROR "regexp".
1062+
// If outStr has an error for a line which has no such comment,
1063+
// this function will report an error.
1064+
// Likewise if outStr does not have an error for a line which has a comment,
1065+
// or if the error message does not match the <regexp>.
1066+
// The <regexp> syntax is Perl but its best to stick to egrep.
1067+
//
1068+
// Sources files are supplied as fullshort slice.
1069+
// It consists of pairs: full path to source file and it's base name.
10411070
func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err error) {
10421071
defer func() {
10431072
if *verbose && err != nil {

0 commit comments

Comments
 (0)