Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds build tags #12

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ef4ce31
added quiet flag
Jul 15, 2019
c52ec75
fixed import paths
Jul 15, 2019
e4a68fd
tidied, fixed
Jul 15, 2019
95ed88e
removed binary (oops) and made more quiet, much more quiet
Jul 15, 2019
8d295b5
Update README.md
fishybell Jul 16, 2019
0d282fd
Update README.md
fishybell Jul 16, 2019
8ea6307
added full flag
Jul 16, 2019
345357a
better log output, no panic on files getting deleted (vim be stupid s…
Jul 31, 2019
c94345f
header at the top of the test runner
Aug 16, 2019
917bf2c
pass any extra arguments directly to "go test"
Feb 3, 2020
ab42b14
less trimming of output
Apr 14, 2020
d21f5fa
bump version correctly
Apr 14, 2020
1d1d4ea
fix issues with cutting off first chars
Apr 16, 2020
b022cec
adds new flags for Smart and Once
Apr 27, 2020
4392639
no longer blows up the screen with too wide of header, updates readme
Apr 27, 2020
81a4ca0
new for 1.5.0: summary and minimal output on an "all" test
Jun 23, 2020
7002f48
allow recursing into other directories to test files not part of the …
Jul 14, 2020
9b77442
fixes bug with too strict of regex
Jul 14, 2020
69e26b1
allows going into any subdirectory
Jul 16, 2020
62b1561
allows running full tests in a subdirectory
Jul 16, 2020
2e13770
removes debug prints
Jul 16, 2020
a86ee6c
bugfix introduced in last push
Jul 16, 2020
af0c30e
better recursing, support go1.14
Aug 25, 2020
3836fcb
better debug output
Aug 25, 2020
c3f3e28
change default mod mode to mod (from readonly)
Aug 26, 2020
7d0a2ff
updates tags to be single build tag string
rochinworks Aug 4, 2021
1a22f6d
updates go.sum
rochinworks Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adds new flags for Smart and Once
  • Loading branch information
Nathan Bell committed Apr 27, 2020
commit b022cec6a91dbd711610bf474855a43ffff0f93c
56 changes: 40 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ type FileInfo map[string]time.Time

var (
notifier platform.Notifier
version = "v1.3.2"
version = "v1.4.0"
pass = color.New(color.FgGreen)
fail = color.New(color.FgHiRed)
)
@@ -35,12 +35,14 @@ func main() {
log.Fatal("could not get current directory: ", err)
}

versionFlag := flag.Bool("v", false, "Print the current version and exit")
rootPath := flag.String("path", defaultPath, "the root path to be watched")
interval := flag.Duration("interval", 1*time.Second, "the interval (in seconds) for scanning files")
quietFlag := flag.Bool("q", true, "Only print failing tests (quiet)")
notifyFlag := flag.Bool("n", false, "Use system notifications")
fullFlag := flag.Bool("f", false, "Always run entire build")
versionFlag := flag.Bool("v", false, "[v]ersion: Print the current version and exit")
rootPath := flag.String("path", defaultPath, "The root path to be watched")
interval := flag.Duration("interval", 1*time.Second, "The interval (in seconds) for scanning files")
quietFlag := flag.Bool("q", true, "[q]uiet: Only print failing tests (use -q=false to be noisy again)")
notifyFlag := flag.Bool("n", false, "[n]otify: Use system notifications")
onceFlag := flag.Bool("o", false, "[o]nce: Only fail once, don't run subsequent tests")
fullFlag := flag.Bool("f", false, "[f]ull: Always run entire build")
smartFlag := flag.Bool("s", false, "[s]mart: Run entire build when no test files are found")
flag.Parse()
remainder := flag.Args()

@@ -60,15 +62,15 @@ func main() {
log.Print("Snitch started for", *rootPath)
watchedFiles := walk(rootPath)
for range time.NewTicker(*interval).C {
scan(rootPath, watchedFiles, *quietFlag, *notifyFlag, *fullFlag, remainder)
scan(rootPath, watchedFiles, *quietFlag, *notifyFlag, *onceFlag, *fullFlag, *smartFlag, remainder)
}
}

func printVersion() {
log.Printf("Current build version: %s", version)
}

func scan(rootPath *string, watchedFiles FileInfo, quiet bool, notify bool, full bool, remainder []string) {
func scan(rootPath *string, watchedFiles FileInfo, quiet bool, notify bool, once bool, full bool, smart bool, remainder []string) {
modifiedDirs := make(map[string]bool, 0)
for filePath, mostRecentModTime := range walk(rootPath) {
lastModTime, found := watchedFiles[filePath]
@@ -82,6 +84,14 @@ func scan(rootPath *string, watchedFiles FileInfo, quiet bool, notify bool, full
if shouldRunTests(filePath, watchedFiles) {
pkgDir := path.Dir(filePath)
modifiedDirs[pkgDir] = true
} else {
if smart {
fmt.Println("running all tests....")
modifiedDirs["something"] = true
full = true
} else {
sadClear(filePath)
}
}
continue
}
@@ -101,13 +111,15 @@ func scan(rootPath *string, watchedFiles FileInfo, quiet bool, notify bool, full

dedup := make([]string, 0)
if full {
clear(" Running all tests")
dedup = append(dedup, "./...")
} else {
clear(" Running tests")
for dir := range modifiedDirs {
dedup = append(dedup, dir)
}
}
test(dedup, quiet, notify, remainder)
test(dedup, quiet, notify, once, remainder)
}

func walk(rootPath *string) FileInfo {
@@ -155,11 +167,13 @@ func hasTestFile(filePath string, watchedFiles FileInfo) bool {
return false
}

func test(dirs []string, quiet bool, notify bool, remainder []string) {
clear()
func test(dirs []string, quiet bool, notify bool, once bool, remainder []string) {
for _, dir := range dirs {
// build up our command
args := []string{"test", "-v"}
if once {
args = append(args, "-failfast")
}
args = append(args, remainder...)
args = append(args, dir)

@@ -175,13 +189,23 @@ func test(dirs []string, quiet bool, notify bool, remainder []string) {
}
}

func clear() {
func clear(msg string) {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
pass.Println("-------------------------------------------------------------------------------")
fmt.Println(msg)
pass.Println("-------------------------------------------------------------------------------")
}

func sadClear(filePath string) {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
pass.Println("---------------")
fmt.Println(" Running tests")
pass.Println("---------------")
fail.Println("-------------------------------------------------------------------------------")
fmt.Println(" No tests found for file:\n", filePath)
fmt.Println("\n Use `snitch -s` to instead run all tests")
fail.Println("-------------------------------------------------------------------------------")
}

func prettyPrint(result string, quiet bool) {