Glasgow City's Counter-Attacking Threats:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package cmd
import (
"github.com/microsoft/terminal-diagnostics/vttest/diagnostics"
"github.com/spf13/cobra"
)
var testPowershellAllCmd = &cobra.Command{
Use: "all",
Short: "Run all tests from Powershell",
RunE: func(cmd *cobra.Command, args []string) error {
return runTestPowershellAll()
},
}
func init() {
testPowershellCmd.AddCommand(testPowershellAllCmd)
}
func runTestPowershellAll() error {
diag := diagnostics.New()
// Test process exit code
err := runTestProcessExitCode(diag)
if err != nil {
return err
}
// Test process output
err = runTestProcessOutput(diag)
if err != nil {
return err
}
// Test VT100 sequences
err = runTestVT100Sequences(diag)
if err != nil {
return err
}
return diag.Report()
}
<|file_sep|>// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package vttest
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
func RunTestPowerShellWithArgs(command string) error {
args := []string{"powershell", "-NoLogo", "-NoProfile", "-Command", command}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running %q: %w", args[0], err)
}
return nil
}
func RunTestPowerShell(command string) error {
return RunTestPowerShellWithArgs(command)
}
func RunTestPowershellWithArgsAndStdin(command string, stdin string) error {
args := []string{"powershell", "-NoLogo", "-NoProfile", "-Command", command}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = strings.NewReader(stdin)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running %q: %w", args[0], err)
}
return nil
}
func RunTestPowershellWithArgsAndFile(command string, inputFilename string) error {
blobBytes, err := ioutil.ReadFile(inputFilename)
if err != nil {
return fmt.Errorf("error reading file %q: %w", inputFilename, err)
}
blobString := string(blobBytes)
args := []string{"powershell", "-NoLogo", "-NoProfile", "-Command", command}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = strings.NewReader(blobString)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running %q: %w", args[0], err)
}
return nil
}
<|repo_name|>Microsoft/terminal-diagnostics<|file_sep|>/diagnostics/diagnostics.go
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package diagnostics
import (
"context"
"fmt"
"strings"
)
type Diagnostics struct {
prefix string // prefix before every line written by Diagnostics methods
report bool // whether or not we should report diagnostics results at end-of-run; default is true; set false via NewDiagnostics(false)
warnings int64 // count number of warnings generated so far; incremented via Warn()
errors int64 // count number of errors generated so far; incremented via Error()
hasErrors bool // true if any errors have been reported; set via Error()
hasWarnings bool // true if any warnings have been reported; set via Warn()
}
func New(prefix string) *Diagnostics {
diag := &Diagnostics{
prefix: prefix,
}
diag.report = true // report diagnostics results at end-of-run by default
return diag
}
func NewSilent() *Diagnostics {
diag := &Diagnostics{
prefix: "",
}
diag.report = false // do not report diagnostics results at end-of-run
return diag
}
// Report prints diagnostics summary if we're supposed to report it.
func (diag *Diagnostics) Report() error {
if diag.report == false || diag.hasErrors == false && diag.hasWarnings == false {
return nil
}
fmt.Println("")
fmt.Printf("%s%s:nn", diag