23 testPattern = regexp.MustCompile(`test[/\\]test-([a-z\-]+)\.sh$`)
26 func mainIntegration() {
27 if len(os.Getenv("DEBUG")) > 0 {
33 if max, _ := strconv.Atoi(os.Getenv("GIT_LFS_TEST_MAXPROCS")); max > 0 {
37 fmt.Println("Running this maxprocs", maxprocs)
42 fmt.Println("no tests to run")
47 tests := make(chan string, len(files))
48 output := make(chan string, len(files))
50 for _, file := range files {
55 outputDone := make(chan bool)
57 for out := range output {
63 for i := 0; i < maxprocs; i++ {
65 go worker(tests, output, &wg)
77 func runTest(output chan string, testname string) {
78 buf := &bytes.Buffer{}
79 cmd := exec.Command(bashPath, testname)
85 sendTestOutput(output, testname, buf, err)
89 done := make(chan error)
91 if err := cmd.Wait(); err != nil {
99 sendTestOutput(output, testname, buf, err)
101 case <-time.After(3 * time.Minute):
102 sendTestOutput(output, testname, buf, errors.New("Timed out"))
108 func sendTestOutput(output chan string, testname string, buf *bytes.Buffer, err error) {
109 cli := strings.TrimSpace(buf.String())
111 cli = fmt.Sprintf("<no output for %s>", testname)
117 basetestname := filepath.Base(testname)
119 fmt.Printf("Error on %s: %s\n", basetestname, err)
122 output <- fmt.Sprintf("error: %s => %s\n%s", basetestname, err, cli)
126 func worker(tests <-chan string, output chan string, wg *sync.WaitGroup) {
130 case testname, ok := <-tests:
134 runTest(output, testname)
139 func testFiles() []string {
140 if len(os.Args) < 4 {
141 return allTestFiles()
144 fileMap := make(map[string]bool)
145 for _, file := range allTestFiles() {
149 files := make([]string, 0, len(os.Args)-3)
150 for _, arg := range os.Args {
151 fullname := "test/test-" + arg + ".sh"
152 if fileMap[fullname] {
153 files = append(files, fullname)
160 func allTestFiles() []string {
161 files := make([]string, 0, 100)
162 filepath.Walk("test", func(path string, info os.FileInfo, err error) error {
164 fmt.Println("FOUND:", path)
166 if err != nil || info.IsDir() || !testPattern.MatchString(path) {
171 fmt.Println("MATCHING:", path)
173 files = append(files, path)
181 if runtime.GOOS == "windows" {
182 // Can't use paths returned from which even if it's on PATH in Windows
183 // Because our Go binary is a separate Windows app & not MinGW, it
184 // can't understand paths like '/usr/bin/bash', needs Windows version
188 out, err := exec.Command(findcmd, "bash").Output()
190 fmt.Println("Unable to find bash:", err)
194 fmt.Printf("No output from '%s bash'\n", findcmd)
198 bashPath = strings.TrimSpace(strings.Split(string(out), "\n")[0])
200 fmt.Println("Using", bashPath)
204 _, err = exec.Command(bashPath, "--version").CombinedOutput()
206 fmt.Println("Error calling bash:", err)