summaryrefslogtreecommitdiff
path: root/Magefile.go
blob: 0d355cde3b9527d8e55365adb1942ed805fc212b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//go:build mage

package main

import (
	"fmt"
	"os"

	"github.com/magefile/mage/sh"
)

var Default = Build

// Build compiles the totalrecall binary
func Build() error {
	return sh.RunV("go", "build", "-o", "totalrecall", "./cmd/totalrecall")
}

// Run executes the application without building
func Run() error {
	return sh.RunV("go", "run", "./cmd/totalrecall")
}

// Test runs all tests
func Test() error {
	return sh.RunV("go", "test", "./...")
}

// TestVerbose runs all tests with verbose output
func TestVerbose() error {
	return sh.RunV("go", "test", "-v", "./...")
}

// TestCoverage runs all tests with coverage report
func TestCoverage() error {
	return sh.RunV("go", "test", "-cover", "./...")
}

// TestCoverageHtml runs all tests and generates HTML coverage report
func TestCoverageHtml() error {
	if err := sh.RunV("go", "test", "-coverprofile=coverage.out", "./..."); err != nil {
		return err
	}
	if err := sh.RunV("go", "tool", "cover", "-html=coverage.out", "-o", "coverage.html"); err != nil {
		return err
	}
	fmt.Println("Coverage report generated at coverage.html")
	return nil
}

// TestRace runs all tests with race detector
func TestRace() error {
	return sh.RunV("go", "test", "-race", "./...")
}

// TestShort runs only short tests (skip integration tests)
func TestShort() error {
	return sh.RunV("go", "test", "-short", "./...")
}

// TestAll runs comprehensive test suite with coverage and race detection
func TestAll() error {
	fmt.Println("Running comprehensive test suite...")
	return sh.RunV("go", "test", "-v", "-race", "-cover", "./...")
}

// Install installs the binary to Go bin directory
func Install() error {
	return sh.RunV("go", "install", "./cmd/totalrecall")
}

// Clean removes build artifacts and test coverage files
func Clean() error {
	files := []string{"totalrecall", "coverage.out", "coverage.html"}
	for _, f := range files {
		if err := os.Remove(f); err != nil && !os.IsNotExist(err) {
			return err
		}
	}
	return sh.RunV("go", "clean", "-testcache")
}