all: Add build constants for runtime.GOOS comparisons (#8442)
all: Add package runtimeos for runtime.GOOS comparisons I grew tired of hand written string comparisons. This adds generated constants for the GOOS values, and predefined Is$OS constants that can be iffed on. In a couple of places I rewrote trivial switch:es to if:s, and added Illumos where we checked for Solaris (because they are effectively the same, and if we're going to target one of them that would be Illumos...).
This commit is contained in:
@@ -13,12 +13,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/osutil"
|
||||
"github.com/syncthing/syncthing/lib/sha256"
|
||||
@@ -35,7 +35,7 @@ const (
|
||||
var defaultResult Result = resultInclude
|
||||
|
||||
func init() {
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
||||
if build.IsDarwin || build.IsWindows {
|
||||
defaultResult |= resultFoldCase
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/osutil"
|
||||
)
|
||||
@@ -210,10 +210,9 @@ func TestCaseSensitivity(t *testing.T) {
|
||||
match := []string{"test"}
|
||||
dontMatch := []string{"foo"}
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "windows":
|
||||
if build.IsDarwin || build.IsWindows {
|
||||
match = append(match, "TEST", "Test", "tESt")
|
||||
default:
|
||||
} else {
|
||||
dontMatch = append(dontMatch, "TEST", "Test", "tESt")
|
||||
}
|
||||
|
||||
@@ -618,7 +617,7 @@ func TestHashOfEmpty(t *testing.T) {
|
||||
func TestWindowsPatterns(t *testing.T) {
|
||||
// We should accept patterns as both a/b and a\b and match that against
|
||||
// both kinds of slash as well.
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skip("Windows specific test")
|
||||
return
|
||||
}
|
||||
@@ -643,7 +642,7 @@ func TestWindowsPatterns(t *testing.T) {
|
||||
|
||||
func TestAutomaticCaseInsensitivity(t *testing.T) {
|
||||
// We should do case insensitive matching by default on some platforms.
|
||||
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
|
||||
if !build.IsWindows && !build.IsDarwin {
|
||||
t.Skip("Windows/Mac specific test")
|
||||
return
|
||||
}
|
||||
@@ -1205,7 +1204,7 @@ func TestEmptyPatterns(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWindowsLineEndings(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skip("Windows specific")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user