2
0
mirror of synced 2025-02-24 23:38:22 +00:00
mobile/cmd/gomobile/build_test.go
Hyang-Ah Hana Kim ab5e5f68d8 cmd/gomobile: update init/bind/build for multiple android archs
init command installs std for all the architectures supported by the
current go tool version (as listed in androidEnv).

build and bind commands pass the list of architectures to the underlying
functions. The list is currently hard-coded []string{"arm"}. In a
separate CL, the list will be populated from the -target flag value.

Still targets arm devices only.

For golang/go#10743

Change-Id: I62b5899859e76ad78a2dc55111e87aa13a68a1f9
Reviewed-on: https://go-review.googlesource.com/17749
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-12-14 21:21:36 +00:00

104 lines
2.4 KiB
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"os"
"path/filepath"
"testing"
"text/template"
)
func TestRFC1034Label(t *testing.T) {
tests := []struct {
in, want string
}{
{"a", "a"},
{"123", "-23"},
{"a.b.c", "a-b-c"},
{"a-b", "a-b"},
{"a:b", "a-b"},
{"a?b", "a-b"},
{"αβγ", "---"},
{"💩", "--"},
{"My App", "My-App"},
{"...", ""},
{".-.", "--"},
}
for _, tc := range tests {
if got := rfc1034Label(tc.in); got != tc.want {
t.Errorf("rfc1034Label(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}
func TestAndroidPkgName(t *testing.T) {
tests := []struct {
in, want string
}{
{"a", "a"},
{"a123", "a123"},
{"a.b.c", "a_b_c"},
{"a-b", "a_b"},
{"a:b", "a_b"},
{"a?b", "a_b"},
{"αβγ", "go___"},
{"💩", "go_"},
{"My App", "My_App"},
{"...", "go___"},
{".-.", "go___"},
{"abstract", "abstract_"},
{"Abstract", "Abstract"},
}
for _, tc := range tests {
if got := androidPkgName(tc.in); got != tc.want {
t.Errorf("len %d", len(tc.in))
t.Errorf("androidPkgName(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}
func TestAndroidBuild(t *testing.T) {
buf := new(bytes.Buffer)
defer func() {
xout = os.Stderr
buildN = false
buildX = false
}()
xout = buf
buildN = true
buildX = true
buildO = "basic.apk"
buildTarget = "android"
gopath = filepath.ToSlash(filepath.SplitList(os.Getenv("GOPATH"))[0])
if goos == "windows" {
os.Setenv("HOMEDRIVE", "C:")
}
cmdBuild.flag.Parse([]string{"golang.org/x/mobile/example/basic"})
ctx.BuildTags = []string{"tag1"}
err := runBuild(cmdBuild)
if err != nil {
t.Log(buf.String())
t.Fatal(err)
}
diff, err := diffOutput(buf.String(), androidBuildTmpl)
if err != nil {
t.Fatalf("computing diff failed: %v", err)
}
if diff != "" {
t.Errorf("unexpected output:\n%s", diff)
}
}
var androidBuildTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
WORK=$WORK
mkdir -p $WORK/lib/armeabi-v7a
GOOS=android GOARCH=arm CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} CGO_ENABLED=1 GOARM=7 go build -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_android_arm -tags="tag1" -x -buildmode=c-shared -o $WORK/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic
`))