-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post-run-command notify implementation for windows
Requires notify-send.exe: http://vaskovsky.net/notify-send Only tested with GOOS=windows and wine, but seems to work.
- Loading branch information
1 parent
e7e66e9
commit 57554cb
Showing
2 changed files
with
63 additions
and
0 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
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,60 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
total := envInt("TOTAL") | ||
skipped := envInt("SKIPPED") | ||
failed := envInt("FAILED") | ||
errors := envInt("ERRORS") | ||
|
||
icon := "info" // Info 🛈 | ||
title := "Passed" | ||
switch { | ||
case errors > 0: | ||
icon = "important" // Warning ⚠ | ||
title = "Errored" | ||
case failed > 0: | ||
icon = "error" // Error ⮾ | ||
title = "Failed" | ||
case skipped > 0: | ||
title = "Passed with skipped" | ||
} | ||
|
||
subtitle := fmt.Sprintf("%d Tests Run", total) | ||
if errors > 0 { | ||
subtitle += fmt.Sprintf(", %d Errored", errors) | ||
} | ||
if failed > 0 { | ||
subtitle += fmt.Sprintf(", %d Failed", failed) | ||
} | ||
if skipped > 0 { | ||
subtitle += fmt.Sprintf(", %d Skipped", skipped) | ||
} | ||
|
||
args := []string{ | ||
"-i", icon, | ||
title, | ||
subtitle, | ||
} | ||
log.Printf("notify-send %#v", args) | ||
err := exec.Command("notify-send.exe", args...).Run() | ||
if err != nil { | ||
log.Fatalf("Failed to exec: %v", err) | ||
} | ||
} | ||
|
||
func envInt(name string) int { | ||
val := os.Getenv("TESTS_" + name) | ||
n, err := strconv.Atoi(val) | ||
if err != nil { | ||
return 0 | ||
} | ||
return n | ||
} |