gotest.tools/gotestsum@v1.11.0/contrib/notify/notify_darwin.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  	"os/exec"
     8  	"strconv"
     9  )
    10  
    11  func main() {
    12  	total := envInt("TOTAL")
    13  	skipped := envInt("SKIPPED")
    14  	failed := envInt("FAILED")
    15  	errors := envInt("ERRORS")
    16  
    17  	emoji := "✅"
    18  	title := "Passed"
    19  	switch {
    20  	case errors > 0:
    21  		emoji = "⚠️"
    22  		title = "Errored"
    23  	case failed > 0:
    24  		emoji = "❌"
    25  		title = "Failed"
    26  	case skipped > 0:
    27  		title = "Passed with skipped"
    28  	}
    29  
    30  	subtitle := fmt.Sprintf("%d Tests Run", total)
    31  	if errors > 0 {
    32  		subtitle += fmt.Sprintf(", %d Errored", errors)
    33  	}
    34  	if failed > 0 {
    35  		subtitle += fmt.Sprintf(", %d Failed", failed)
    36  	}
    37  	if skipped > 0 {
    38  		subtitle += fmt.Sprintf(", %d Skipped", skipped)
    39  	}
    40  
    41  	args := []string{
    42  		"-title", emoji + " " + title,
    43  		"-group", "gotestsum",
    44  		"-subtitle", subtitle,
    45  	}
    46  	cmd := exec.Command("terminal-notifier", args...)
    47  	log.Printf("%#v", cmd.Args)
    48  	cmd.Stdout = os.Stdout
    49  	cmd.Stderr = os.Stderr
    50  	if err := cmd.Run(); err != nil {
    51  		log.Fatalf("Failed to exec: %v", err)
    52  	}
    53  }
    54  
    55  func envInt(name string) int {
    56  	val := os.Getenv("TESTS_" + name)
    57  	n, err := strconv.Atoi(val)
    58  	if err != nil {
    59  		return 0
    60  	}
    61  	return n
    62  }