Files
hakurei/internal/rosa/rosa_test.go
T
cat 869820ec6d
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 3m36s
Test / Hakurei (push) Successful in 6m11s
Test / Sandbox (race detector) (push) Successful in 7m44s
Test / Hakurei (race detector) (push) Successful in 9m57s
Test / ShareFS (push) Successful in 10m35s
Test / Flake checks (push) Successful in 1m30s
cmd/mbf: enable output colouring
This respects the de facto standards, on top of checking stderr.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-07-30 05:16:39 +09:00

108 lines
2.1 KiB
Go

package rosa_test
import (
"context"
"log"
"os"
"os/signal"
"sync"
"syscall"
"testing"
"hakurei.app/check"
"hakurei.app/container"
"hakurei.app/internal/pkg"
"hakurei.app/internal/rosa"
"hakurei.app/message"
)
var (
// skipBuildTest caches whether build tests are skipped.
skipBuildTest bool
// buildTestCache is populated by getCache and must not be accessed directly.
buildTestCache *pkg.Cache
// buildTestCacheCancel cancels buildTestCache.
buildTestCacheCancel context.CancelFunc
// buildTestCacheOnce synchronises access to buildTestCache.
buildTestCacheOnce sync.Once
)
func TestMain(m *testing.M) {
rosa.Native().DropCaches("", rosa.OptLLVMNoLTO)
container.TryArgv0(nil)
code := m.Run()
if buildTestCache != nil {
buildTestCacheCancel()
buildTestCache.Close()
}
os.Exit(code)
}
func getCache(t *testing.T) *pkg.Cache {
t.Helper()
const env = "ROSA_BUILD_TEST_CACHE_DIR"
if !testing.Verbose() {
t.Skip("verbose flag not set")
}
buildTestCacheOnce.Do(func() {
if p, ok := os.LookupEnv(env); !ok {
skipBuildTest = true
return
} else if a, err := check.NewAbs(p); err != nil {
t.Fatal(err)
} else {
var ctx context.Context
ctx, buildTestCacheCancel = signal.NotifyContext(context.Background(),
syscall.SIGINT, syscall.SIGTERM)
msg := message.New(log.New(os.Stderr, "\x1b[2mrosa: \x1b[0m", 0))
msg.SwapVerbose(true)
if buildTestCache, err = pkg.Open(ctx, msg, a, &pkg.CacheAttr{
Flags: pkg.CSuppressInit | pkg.CColourOutput,
}); err != nil {
t.Fatal(err)
}
}
})
if skipBuildTest {
t.Skip(env + " not set")
}
return buildTestCache
}
func TestCureAll(t *testing.T) {
cache := getCache(t)
t.Parallel()
for _, p := range rosa.Native().CollectAll() {
_, a := rosa.Native().Std().MustLoad(p)
t.Run(p.String(), func(t *testing.T) {
t.Parallel()
if pathname, _, err := cache.Cure(a); err != nil {
t.Fatal(err)
} else {
t.Log(pathname)
}
})
}
}
func BenchmarkStage3(b *testing.B) {
t := rosa.Native().Clone().Std()
llvm := rosa.H("llvm")
for b.Loop() {
t.MustLoad(llvm)
b.StopTimer()
t.DropCaches("", 0)
b.StartTimer()
}
}