1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 16:10:08 +00:00
Files
Mole/cmd/analyze/test_helpers_test.go
Tw93 cb2eb1097a fix(analyze): add darwin build tag to all platform-specific files
All files in cmd/analyze/ are macOS-only but several were missing the
//go:build darwin constraint. On Linux (e.g. CodeQL CI), Go compiled
these files without the types defined in main.go (which had the tag),
causing undefined symbol errors for dirEntry, fileEntry, scanResult,
cacheEntry, historyEntry and model.

- Add //go:build darwin to heap.go, cache.go, scanner.go, cleanable.go,
  delete.go, format.go, constants.go and all *_test.go files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-14 07:46:32 +08:00

47 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build darwin
package main
import (
"context"
"os"
"os/exec"
"strings"
"testing"
"time"
)
func skipIfFinderUnavailable(t *testing.T) {
t.Helper()
if os.Getenv("CI") != "" {
t.Skip("Skipping Finder-dependent test in CI")
}
if os.Getenv("MOLE_SKIP_FINDER_TESTS") == "1" {
t.Skip("Skipping Finder-dependent test via MOLE_SKIP_FINDER_TESTS")
}
if _, err := exec.LookPath("osascript"); err != nil {
t.Skipf("Skipping Finder-dependent test, osascript unavailable: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "osascript", "-e", `tell application "Finder" to get name`)
output, err := cmd.CombinedOutput()
text := strings.ToLower(string(output))
if ctx.Err() == context.DeadlineExceeded {
t.Skip("Skipping Finder-dependent test, Finder probe timed out")
}
if strings.Contains(text, "connection invalid") || strings.Contains(text, "cant get application \"finder\"") || strings.Contains(text, "can't get application \"finder\"") {
t.Skipf("Skipping Finder-dependent test, Finder probe indicates unavailable session: %s", strings.TrimSpace(string(output)))
}
if err != nil {
reason := strings.TrimSpace(string(output))
if reason == "" {
reason = err.Error()
}
t.Skipf("Skipping Finder-dependent test, Finder unavailable: %s", reason)
}
}