@@ -616,6 +616,8 @@ func (t *test) run() {
616
616
t .err = fmt .Errorf ("unimplemented action %q" , action )
617
617
618
618
case "asmcheck" :
619
+ // Compile Go file and match the generated assembly
620
+ // against a set of regexps in comments.
619
621
ops := t .wantedAsmOpcodes (long )
620
622
for _ , env := range ops .Envs () {
621
623
cmdline := []string {"build" , "-gcflags" , "-S" }
@@ -640,6 +642,9 @@ func (t *test) run() {
640
642
return
641
643
642
644
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.
643
648
// TODO(gri) remove need for -C (disable printing of columns in error messages)
644
649
cmdline := []string {goTool (), "tool" , "compile" , "-C" , "-e" , "-o" , "a.o" }
645
650
// No need to add -dynlink even if linkshared if we're just checking for errors...
@@ -664,10 +669,11 @@ func (t *test) run() {
664
669
return
665
670
666
671
case "compile" :
672
+ // Compile Go file.
667
673
_ , t .err = compileFile (runcmd , long , flags )
668
674
669
675
case "compiledir" :
670
- // Compile all files in the directory in lexicographic order.
676
+ // Compile all files in the directory as packages in lexicographic order.
671
677
longdir := filepath .Join (cwd , t .goDirName ())
672
678
pkgs , err := goDirPackages (longdir , singlefilepkgs )
673
679
if err != nil {
@@ -682,8 +688,9 @@ func (t *test) run() {
682
688
}
683
689
684
690
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.
687
694
longdir := filepath .Join (cwd , t .goDirName ())
688
695
pkgs , err := goDirPackages (longdir , singlefilepkgs )
689
696
if err != nil {
@@ -725,8 +732,10 @@ func (t *test) run() {
725
732
fallthrough
726
733
727
734
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.
730
739
longdir := filepath .Join (cwd , t .goDirName ())
731
740
pkgs , err := goDirPackages (longdir , singlefilepkgs )
732
741
if err != nil {
@@ -763,14 +772,15 @@ func (t *test) run() {
763
772
}
764
773
765
774
case "build" :
775
+ // Build Go file.
766
776
_ , err := runcmd (goTool (), "build" , goGcflags (), "-o" , "a.exe" , long )
767
777
if err != nil {
768
778
t .err = err
769
779
}
770
780
771
781
case "builddir" , "buildrundir" :
772
782
// 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.
774
784
longdir := filepath .Join (cwd , t .goDirName ())
775
785
files , dirErr := ioutil .ReadDir (longdir )
776
786
if dirErr != nil {
@@ -839,9 +849,10 @@ func (t *test) run() {
839
849
}
840
850
}
841
851
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.
843
855
// TODO: not supported on NaCl
844
- useTmp = true
845
856
cmd := []string {goTool (), "build" , goGcflags (), "-o" , "a.exe" }
846
857
if * linkshared {
847
858
cmd = append (cmd , "-linkshared" )
@@ -866,6 +877,9 @@ func (t *test) run() {
866
877
}
867
878
868
879
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.
869
883
useTmp = false
870
884
var out []byte
871
885
var err error
@@ -908,6 +922,8 @@ func (t *test) run() {
908
922
}
909
923
910
924
case "runoutput" :
925
+ // Run Go file and write its output into temporary Go file.
926
+ // Run generated Go file and verify its output.
911
927
rungatec <- true
912
928
defer func () {
913
929
<- rungatec
@@ -943,6 +959,8 @@ func (t *test) run() {
943
959
}
944
960
945
961
case "errorcheckoutput" :
962
+ // Run Go file and write its output into temporary Go file.
963
+ // Compile and errorCheck generated Go file.
946
964
useTmp = false
947
965
cmd := []string {goTool (), "run" , goGcflags ()}
948
966
if * linkshared {
@@ -1038,6 +1056,17 @@ func splitOutput(out string, wantAuto bool) []string {
1038
1056
return res
1039
1057
}
1040
1058
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.
1041
1070
func (t * test ) errorCheck (outStr string , wantAuto bool , fullshort ... string ) (err error ) {
1042
1071
defer func () {
1043
1072
if * verbose && err != nil {
0 commit comments