This repository has been archived by the owner on May 11, 2022. It is now read-only.
generated from octomation/go-tool
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"go.octolab.org/safe" | ||
"go.octolab.org/unsafe" | ||
) | ||
|
||
func Golang() *cobra.Command { | ||
main := cobra.Command{ | ||
Use: "go", | ||
Short: "`go test` proxy with extra features", | ||
Long: "`go test` proxy with extra features.", | ||
|
||
Args: cobra.NoArgs, | ||
} | ||
|
||
compile := cobra.Command{ | ||
Use: "compile", | ||
Short: "make sure that all code is compiled.", | ||
Long: "Make sure that all code is compiled.", | ||
|
||
Args: cobra.NoArgs, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
bin := exec.CommandContext(cmd.Context(), "go", "test", "-run", "^Fake$$", "./...") | ||
bin.Stderr = cmd.ErrOrStderr() | ||
reader, err := bin.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
go safe.Do(bin.Run, func(err error) {}) | ||
scanner := bufio.NewScanner(reader) | ||
scanner.Split(bufio.ScanLines) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
|
||
if strings.Contains(line, "no test files") { | ||
continue | ||
} | ||
if strings.Contains(line, "no tests to run") { | ||
continue | ||
} | ||
|
||
unsafe.DoSilent(io.Copy(cmd.OutOrStdout(), strings.NewReader(line))) | ||
unsafe.DoSilent(fmt.Fprintln(cmd.OutOrStdout())) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
main.AddCommand(&compile) | ||
|
||
return &main | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters