Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #2: implement testit go compile
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jan 28, 2021
1 parent 4ec7e88 commit 5f48eed
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
63 changes: 63 additions & 0 deletions internal/cmd/golang.go
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
}
13 changes: 8 additions & 5 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import "github.com/spf13/cobra"
// New returns the new root command.
func New() *cobra.Command {
command := cobra.Command{
Use: "%template%",
Short: "%template%",
Long: "%template%",
Use: "testit",
Short: "extended `go test` for better experience",
Long: "Extended `go test` for better experience.",

Args: cobra.NoArgs,

SilenceErrors: false,
SilenceUsage: true,
}
/* configure instance */
command.AddCommand( /* related commands */ )

command.AddCommand(
Golang(),
)

return &command
}

0 comments on commit 5f48eed

Please sign in to comment.