package main

import (
	"os/exec"
	"testing"
)

func TestGolangciLint(t *testing.T) {
	cmd := exec.Command("golangci-lint", "run", "./...")
	cmd.Dir = "."
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Errorf("golangci-lint failed:\n%s", out)
	}
}

func TestGoFmt(t *testing.T) {
	cmd := exec.Command("go", "fmt", "./...")
	cmd.Dir = "."
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Errorf("go fmt failed: %v\n%s", err, out)
	}
	if len(out) > 0 {
		t.Errorf("go fmt produced output (files needed formatting). Run 'go fmt ./...' to fix:\n%s", out)
	}
}

func TestDeadcode(t *testing.T) {
	cmd := exec.Command("deadcode", "./...")
	cmd.Dir = "."
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Errorf("deadcode failed:\n%s", out)
	}
}