github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/cmd/gomobile/build_test.go (about)

     1  // Copyright 2015 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"path/filepath"
    11  	"testing"
    12  	"text/template"
    13  )
    14  
    15  func TestRFC1034Label(t *testing.T) {
    16  	tests := []struct {
    17  		in, want string
    18  	}{
    19  		{"a", "a"},
    20  		{"123", "-23"},
    21  		{"a.b.c", "a-b-c"},
    22  		{"a-b", "a-b"},
    23  		{"a:b", "a-b"},
    24  		{"a?b", "a-b"},
    25  		{"αβγ", "---"},
    26  		{"💩", "--"},
    27  		{"My App", "My-App"},
    28  		{"...", ""},
    29  		{".-.", "--"},
    30  	}
    31  
    32  	for _, tc := range tests {
    33  		if got := rfc1034Label(tc.in); got != tc.want {
    34  			t.Errorf("rfc1034Label(%q) = %q, want %q", tc.in, got, tc.want)
    35  		}
    36  	}
    37  }
    38  
    39  func TestAndroidBuild(t *testing.T) {
    40  	buf := new(bytes.Buffer)
    41  	defer func() {
    42  		xout = os.Stderr
    43  		buildN = false
    44  		buildX = false
    45  	}()
    46  	xout = buf
    47  	buildN = true
    48  	buildX = true
    49  	buildO = "basic.apk"
    50  	buildTarget = "android"
    51  	gopath = filepath.ToSlash(filepath.SplitList(os.Getenv("GOPATH"))[0])
    52  	if goos == "windows" {
    53  		os.Setenv("HOMEDRIVE", "C:")
    54  	}
    55  	cmdBuild.flag.Parse([]string{"github.com/c-darwin/mobile/example/basic"})
    56  	err := runBuild(cmdBuild)
    57  	if err != nil {
    58  		t.Log(buf.String())
    59  		t.Fatal(err)
    60  	}
    61  
    62  	diff, err := diffOutput(buf.String(), androidBuildTmpl)
    63  	if err != nil {
    64  		t.Fatalf("computing diff failed: %v", err)
    65  	}
    66  	if diff != "" {
    67  		t.Errorf("unexpected output:\n%s", diff)
    68  	}
    69  }
    70  
    71  var androidBuildTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
    72  WORK=$WORK
    73  GOOS=android GOARCH=arm GOARM=7 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 go build -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_android_arm -tags="" -x -buildmode=c-shared -o $WORK/libbasic.so github.com/c-darwin/mobile/example/basic
    74  `))