diff options
author | 2018-01-13 13:23:39 -0800 | |
---|---|---|
committer | 2018-01-17 13:42:24 -0800 | |
commit | 8e0f32eb5421d71846700ffe4f11d2958a33f1b1 (patch) | |
tree | 33603cfe7125d0b142565b590afdfd9ea4420919 /platforms_test.go | |
parent | feat(main): implement []string flag valuer (diff) | |
download | bakelite-8e0f32eb5421d71846700ffe4f11d2958a33f1b1.tar.xz |
feat(main): support modifying built platformsv0.1.0
Bakelite now accepts a platform modification string vita the -platform
flag. This string format for adding and removing the built platforms,
including removing the default platforms entirely. It is processed left
to right.
bakelite -platform '-windows +linux/s390x' [packages]
Would now build [packages] for all of the default platforms, except for
Windows, and also build for the linux/s390x platform.
bakelite -platform '- +linux +darwin' [packages]
Would now build [packages] for the default platforms of only the Linux
and Darwin operating systems.
The platform modification string is parsed and turned into calls to
a structure following the builder pattern.
As the user can now modify the built platforms, Bakelite now exits with
a non-zero exit code if any of the platforms fail to build.
Change-Id: Iade51e17bbfda4e916394343a5f8cb3208f2b160
Diffstat (limited to 'platforms_test.go')
-rw-r--r-- | platforms_test.go | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/platforms_test.go b/platforms_test.go new file mode 100644 index 0000000..b2fcacc --- /dev/null +++ b/platforms_test.go @@ -0,0 +1,117 @@ +package main + +import ( + "fmt" + "sort" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" +) + +func ExampleNewPlatformBuilder() { + plb, _ := NewPlatformBuilder() + + plb = plb. + WithOS(OS("windows")). + WithoutPlatform(Platform{OS("windows"), Arch("amd64")}). + WithPlatform(Platform{OS("plan9"), Arch("amd64")}) + + pl := plb.Build() + sort.SliceStable(pl, func(i, j int) bool { + return lessPlatforms(pl[i], pl[j]) + }) + + fmt.Println(pl) + + // Output: + // [{plan9 amd64} {windows 386}] +} + +func TestWithOS(t *testing.T) { + plb, _ := NewPlatformBuilder() + + plb = plb.WithOS(OS("windows")) + + pl := plb.Build() + expected := defaultWindows() + + if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" { + t.Errorf("manifest differs. (-got +want):\n%s", diff) + } +} + +func TestWithoutOS(t *testing.T) { + plb, _ := NewPlatformBuilder() + + plb = plb. + WithPlatform( + Platform{OS("windows"), Arch("amd64")}, + ). + WithPlatform( + Platform{OS("plan9"), Arch("amd64")}, + ). + WithoutOS(OS("windows")) + + pl := plb.Build() + expected := []Platform{{OS("plan9"), Arch("amd64")}} + + if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" { + t.Errorf("manifest differs. (-got +want):\n%s", diff) + } +} + +func TestWithPlatform(t *testing.T) { + plb, _ := NewPlatformBuilder() + + plb = plb.WithPlatform(Platform{OS("windows"), Arch("arm64")}) + + pl := plb.Build() + expected := []Platform{{OS("windows"), Arch("arm64")}} + + if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" { + t.Errorf("manifest differs. (-got +want):\n%s", diff) + } +} + +func TestWithoutPlaform(t *testing.T) { + plb, _ := NewPlatformBuilder() + + plb = plb. + WithOS(OS("windows")). + WithOS(OS("plan9")). + WithoutPlatform(Platform{OS("windows"), Arch("386")}) + + pl := plb.Build() + expected := []Platform{ + {OS("windows"), Arch("amd64")}, + {OS("plan9"), Arch("386")}, + {OS("plan9"), Arch("amd64")}, + } + + if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" { + t.Errorf("manifest differs. (-got +want):\n%s", diff) + } +} + +func TestWithDefaults(t *testing.T) { + plb, _ := NewPlatformBuilder() + + plb = plb.WithDefaults() + + pl := plb.Build() + + if len(pl) == 0 { + t.Errorf("expected more defaults!") + } +} + +func lessPlatforms(x, y Platform) bool { + if x.OS < y.OS { + return true + } + if x.OS > y.OS { + return false + } + return x.Arch < y.Arch +} |