github.com/tiagovtristao/plz@v13.4.0+incompatible/src/test/surefire.go (about)

     1  package test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"path/filepath"
     6  
     7  	"github.com/thought-machine/please/src/core"
     8  	"github.com/thought-machine/please/src/fs"
     9  )
    10  
    11  // CopySurefireXmlFilesToDir copies all the XML test results files into the given directory.
    12  func CopySurefireXmlFilesToDir(state *core.BuildState, surefireDir string) {
    13  	for _, label := range state.ExpandOriginalLabels() {
    14  		target := state.Graph.TargetOrDie(label)
    15  		if state.ShouldInclude(target) && target.IsTest && !target.NoTestOutput {
    16  			if path := target.TestResultsFile(); fs.PathExists(path) {
    17  				fs.Walk(path, func(path string, isDir bool) error {
    18  					if !isDir {
    19  						if bytes, _ := ioutil.ReadFile(path); looksLikeJUnitXMLTestResults(bytes) {
    20  							surefireResult := filepath.Join(surefireDir, filepath.Base(path))
    21  							if err := fs.CopyOrLinkFile(path, surefireResult, 0644, true, true); err != nil {
    22  								log.Errorf("Error linking %s to %s - %s", surefireResult, path, err)
    23  							}
    24  						}
    25  					}
    26  					return nil
    27  				})
    28  			}
    29  		}
    30  	}
    31  }