예제 #1
0
// NAME
//    clean - Clean all generated files
//
// DESCRIPTION
//    Clean all generated files and paths.
//
// OPTIONS
//    --backup, -b
//        clean all backup files (*~, #*)
//    --verbose, -v
//        run in verbose mode
func TaskClean(t *tasking.T) {
	var paths []string

	paths = append(
		paths,
		ARMBinaryPath,
		"pkg",
		filepath.Join("bin", ProjectName),
		filepath.Join(AndroidPath, "bin"),
		filepath.Join(AndroidPath, "gen"),
		filepath.Join(AndroidPath, "libs"),
		filepath.Join(AndroidPath, "obj"),
	)

	// Actually remove files using rm
	for _, path := range paths {
		err := rm_rf(t, path)
		if err != nil {
			t.Error(err)
		}
	}

	if t.Flags.Bool("backup") {
		err := t.Exec(`sh -c`, `"find ./ -name '*~' -print0 | xargs -0 rm -f"`)
		if err != nil {
			t.Error(err)
		}
	}

	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
}
예제 #2
0
// NAME
//    clean - Clean all generated files
//
// DESCRIPTION
//    Clean all generated files and paths.
//
func TaskClean(t *tasking.T) {
	var paths []string

	paths = append(
		paths,
		ARMBinaryPath,
		"pkg",
		filepath.Join("bin"),
		filepath.Join(AndroidPath, "bin"),
		filepath.Join(AndroidPath, "gen"),
		filepath.Join(AndroidPath, "libs"),
		filepath.Join(AndroidPath, "obj"),
	)

	// Actually remove files using rm
	for _, path := range paths {
		err := rm_rf(t, path)
		if err != nil {
			t.Error(err)
		}
	}
	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
}
예제 #3
0
func deployAndroid(t *tasking.T) {
	buildAndroid(t)
	err := t.Exec("ant -f android/build.xml clean debug")
	if err != nil {
		t.Error(err)
	}
	uploadAndroid(t)
}
예제 #4
0
func runXorg(t *tasking.T, flags string) {
	err := t.Exec(
		filepath.Join("bin", LibName),
		flags,
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #5
0
func runXorg(t *tasking.T) {
	err := t.Exec(
		filepath.Join("bin", LibName),
		t.Flags.String("flags"),
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #6
0
func runXorg(t *tasking.T) {
	buildXorg(t)
	err := t.Exec(
		filepath.Join("bin", ProjectName),
		t.Flags.String("flags"),
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #7
0
func buildXorg(t *tasking.T) {
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go get`, t.Flags.String("flags"),
		LibName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #8
0
파일: test_task.go 프로젝트: kebo/gorgasm
func buildXorg(t *tasking.T) {
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go install`, t.Flags.String("buildflags"),
		ProjectName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #9
0
파일: test_task.go 프로젝트: kebo/gorgasm
// NAME
//    build - Build the tests
//
// DESCRIPTION
//    Build the tests for the given platforms (xorg/android).
//
// OPTIONS
//    --buildflags=
//        pass the given flags to the compiler
//    --verbose, -v
//        run in verbose mode
func TaskBuild(t *tasking.T) {
	if len(t.Args) == 0 {
		t.Error("At least a platform name must be specified!")
	}
	if f, ok := buildFun[t.Args[0]]; ok {
		f(t)
	}
	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Build the tests for the given platforms.")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Build the tests for the given platforms.")
}
예제 #10
0
// NAME
//    build - Build the application
//
// DESCRIPTION
//    Build the application for the given platforms.
//
// OPTIONS
//    --flags=<FLAGS>
//        pass FLAGS to the compiler
//    --verbose, -v
//        run in verbose mode
func TaskBuild(t *tasking.T) {
	if len(t.Args) < 1 {
		t.Error("You must specify a build platform!")
	} else {
		for _, platform := range t.Args {
			buildFun[platform](t)
		}
	}
	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.")
}
예제 #11
0
// NAME
//   init - Initialize a new Mandala application
//
// DESCRIPTION
//    Initialize a new Mandala application based on application.json
//
func TaskInit(t *tasking.T) {
	var err error

	// read application.json
	app, err := readJSON(jsonPath)
	if err != nil {
		t.Error(err)
	}

	var paths []string

	// execute templates and copy the files
	err = filepath.Walk(
		"templates",
		func(path string, info os.FileInfo, err error) error {
			if !info.IsDir() {
				paths = append(paths, path)
			}
			return nil
		},
	)
	if err != nil {
		t.Error(err)
	}

	for _, path := range paths {
		var dstPath string
		splits := strings.Split(path, "/")
		if len(splits) > 1 {
			dstPath = filepath.Join(splits[1:]...)
		} else {
			dstPath = filepath.Base(path)
		}
		if err = copyFile(path, dstPath, app); err != nil {
			t.Error(err)
		}
	}

	// Rename paths accordly to app.LibName
	if err = os.Rename("_task.go", strings.ToLower(app.LibName)+"_task.go"); err != nil {
		t.Error(err)
	}
	if err = os.Rename("src/_app", filepath.Join("src", strings.ToLower(app.LibName))); err != nil {
		t.Error(err)
	}

	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Initialize a new Mandala application")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Initialize a new Mandala application")
}
예제 #12
0
// NAME
//   test-sqlite - check data generated from ModSQL into a SQLite database
func TaskTestSQLite(t *tasking.T) {
	filename := dbname + ".db"
	defer func() {
		if err := os.Remove(filename); err != nil {
			t.Error(err)
		}
	}()

	db, err := sql.Open("sqlite3", filename)
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.SQLite)

		if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}
예제 #13
0
func buildXorg(t *tasking.T, buildAll bool) {
	allFlagString := ""
	if buildAll {
		allFlagString = "-a"
	}
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go install`, allFlagString,
		LibName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
예제 #14
0
func runAndroid(t *tasking.T) {
	buildAndroid(t)
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n net.mandala.%s/android.app.NativeActivity",
			ProjectName,
		))
	if err != nil {
		t.Error(err)
	}
	err = t.Exec("adb shell logcat", "Mandala:* stdout:* stderr:* *:S")
	if err != nil {
		t.Error(err)
	}
}
예제 #15
0
func buildAndroid(t *tasking.T, buildMode ...bool) {
	// Build mode for ant:
	// buildMode not specified or false => ant debug
	// buildMode true => ant release
	antBuildParam := "debug"
	if len(buildMode) > 0 && buildMode[0] == true {
		antBuildParam = "release"
	}

	// Generate AdmobActivity using the UnitId in admob.json
	err := generateAdmobActivity()
	if err != nil {
		t.Error(err)
	}

	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	err = t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go get", t.Flags.String("flags"),
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		LibName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, LibName),
			filepath.Join(path, "lib"+LibName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}

	if err == nil {
		err = t.Exec("ant -f android/build.xml clean", antBuildParam)
		if err != nil {
			t.Error(err)
		}
	}

}
예제 #16
0
func runAndroid(t *tasking.T, flags string) {
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity",
			Domain,
			LibName,
		))
	if err != nil {
		t.Error(err)
	}
	if t.Flags.Bool("logcat") {
		err = t.Exec("adb shell logcat")
		if err != nil {
			t.Error(err)
		}
	}
}
예제 #17
0
func runAndroid(t *tasking.T) {
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity",
			Domain,
			LibName,
		))
	if err != nil {
		t.Error(err)
	}
	if tags := t.Flags.String("logcat"); tags != "" {
		err = t.Exec("adb", "shell", "logcat", tags)
		if err != nil {
			t.Error(err)
		}
	}
}
예제 #18
0
// NAME
//    gh-user - Get URL for a given GitHub user login
//
// DESCRIPTION
//    Given a GitHub user login, call the GitHub API to get this user and print out the user page URL.
//
//    For example
//
//    $ gotask git-hub-user jingweno
//
// OPTIONS
//    --verbose, -v
//        run in verbose mode
func TaskGitHubUser(t *tasking.T) {
	if len(t.Args) == 0 {
		t.Error("No GitHub user login is provided!")
		return
	}

	login := t.Args[0]
	data, err := fetchGitHubUser(login)
	if err != nil {
		t.Error(err)
		return
	}

	url, ok := data["html_url"]
	if !ok {
		t.Errorf("No URL found for user login %s\n", login)
		return
	}

	t.Logf("The URL for user %s is %s\n", login, url)
}
예제 #19
0
파일: mysql_task.go 프로젝트: robfig/modsql
// NAME
//   test-mysql - check data generated from ModSQL into a MySQL database
//
// DESCRIPTION
//
//   To create the database:
//
//     mysql -p
//     mysql> create database modsql_test;
//     mysql> GRANT ALL PRIVILEGES ON modsql_test.* to USER@localhost;
//
//   Note: substitute "USER" by your user name.
//
//   To remove it:
//
//     mysql> drop database modsql_test;
func TaskTestMySQL(t *tasking.T) {
	// Format used in "github.com/serbaut/go-mysql"
	//db, err := sql.Open("mysql", fmt.Sprintf("mysql://%s@(unix)/%s?socket=%s",
	//username, dbname, host.mysql))
	db, err := sql.Open("mysql", fmt.Sprintf("%s@unix(%s)/%s?parseTime=true",
		username, host.mysql, dbname))
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.MySQL)

		if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}
예제 #20
0
// NAME
//   check data generated from ModSQL into a Postgre database
//
// DESCRIPTION
//
//   To create the database:
//
//     sudo -u postgres createuser USER --no-superuser --no-createrole --no-createdb
//     sudo -u postgres createdb modsql_test --owner USER
//
//   Note: substitute "USER" by your user name.
//
//   To remove it:
//
//     sudo -u postgres dropdb modsql_test
func TaskTestPostgres(t *tasking.T) {
	db, err := sql.Open("postgres", fmt.Sprintf("user=%s dbname=%s host=%s sslmode=disable",
		username, dbname, host.postgres))
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.Postgres)

		if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}
예제 #21
0
func buildAndroid(t *tasking.T) {
	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	err := t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go install", t.Flags.String("flags"),
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		ProjectName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	os.MkdirAll(ARMBinaryPath, 0777)

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, ProjectName),
			filepath.Join(path, "lib"+ProjectName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}
}
예제 #22
0
func buildAndroid(t *tasking.T, buildAll bool) {
	allFlagString := ""

	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	if buildAll {
		allFlagString = "-a"
	}

	err := t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go install", allFlagString,
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		LibName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, LibName),
			filepath.Join(path, "lib"+LibName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}

	if err == nil {
		err = t.Exec("ant -f android/build.xml clean debug")
		if err != nil {
			t.Error(err)
		}
	}

}
예제 #23
0
// Sign and zipalign Android application.
func signAndroid(t *tasking.T) {
	unsignedAppPath := fmt.Sprintf("android/bin/%s-release-unsigned.apk", LibName)
	// Sign app
	cmdJarsigner := "jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore %s %s %s"
	if err := t.Exec(fmt.Sprintf(cmdJarsigner, KeyStore, unsignedAppPath, KeyAlias)); err != nil {
		t.Error(err)
	}
	// Verify sign
	cmdJarsignerVerify := "jarsigner -verify -verbose -certs %s"
	if err := t.Exec(fmt.Sprintf(cmdJarsignerVerify, unsignedAppPath)); err != nil {
		t.Error(err)
	}
	// Align app
	cmdZipAlign := "zipalign -v 4 %s android/bin/%s.apk"
	if err := t.Exec(fmt.Sprintf(cmdZipAlign, unsignedAppPath, LibName)); err != nil {
		t.Error(err)
	}
}
예제 #24
0
func deployAndroid(t *tasking.T) {
	err := t.Exec(fmt.Sprintf("adb install -r android/bin/%s-debug.apk", LibName))
	if err != nil {
		t.Error(err)
	}
}
예제 #25
0
// testInsert checks SQL statements generated from Go model.
func testInsert(t *tasking.T, db *sql.DB, eng modsql.Engine) {
	modsql.InitStatements(db, eng, model.Insert)
	defer func() {
		if err := modsql.CloseStatements(); err != nil {
			t.Error(err)
		}
	}()

	// insert inserts data without transaction
	insert := func(model modsql.Modeler) {
		if _, err := model.StmtInsert().Exec(model.Args()...); err != nil {
			t.Error(err)
		}
	}

	// To remove nanoseconds in timestamps since the drivers return fewer digits.
	nsec := regexp.MustCompilePOSIX(`\.[0-9]+ \+`)

	// scan checks that output data is the same than input data.
	scan := func(query string, input, output modsql.Modeler) {
		rows := db.QueryRow(modsql.SQLReplacer(eng, query))

		if err := rows.Scan(output.Args()...); err != nil {
			t.Errorf("query: %q\n%s", query, err)
		} else {
			in := fmt.Sprintf("%v", input)
			out := fmt.Sprintf("%v", output)

			if strings.Contains(out, "UTC") { // Field DateTime
				in = nsec.ReplaceAllLiteralString(in, " +")
				out = nsec.ReplaceAllLiteralString(out, " +")
			}

			if in != out {
				t.Errorf("got different data\ninput:  %v\noutput: %v\n", in, out)
			}
		}
	}

	// Transaction

	inputTx := &model.Catalog{0, "a", "b", 1.32}

	err := insertFromTx(db, inputTx)
	if err != nil {
		modsql.CloseStatements()
		t.Error(err)
	}

	scan("SELECT * FROM catalog WHERE catalog_id = 0", inputTx, &model.Catalog{})

	// Check data input from SQL files

	inputTypes := &model.Types{0, 8, 16, 32, 64, 1.32, 1.64, "one", []byte("12"), 'A', 'Z', true}
	scan("SELECT * FROM types WHERE int_ = 0", inputTypes, &model.Types{})

	inputDef := &model.Default_value{0, 10, 10.10, "foo", []byte{'1', '2'}, 'a', 'z', false}
	scan("SELECT * FROM default_value WHERE Id = 0", inputDef, &model.Default_value{})

	inputTimes0 := &model.Times{0, time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)}
	scan("SELECT * FROM times WHERE typeId = 0", inputTimes0, &model.Times{})
	if inputTimes0.Datetime.IsZero() {
		t.Error("inputTimes0.Datetime: should not be zero:", inputTimes0.Datetime)
	}

	inputTimes1 := &model.Times{1, time.Time{}}
	scan("SELECT * FROM times WHERE typeId = 1", inputTimes1, &model.Times{})
	if !inputTimes1.Datetime.IsZero() {
		t.Error("inputTimes1.Datetime: should be zero:", inputTimes1.Datetime)
	}

	// Direct insert

	input0 := &model.Types{1, 8, -16, -32, 64, -1.32, -1.64, "a", []byte{1, 2}, 8, 'r', true}
	insert(input0)
	scan("SELECT * FROM types WHERE int_ = 1", input0, &model.Types{})

	input1 := &model.Default_value{1, 8, 1.32, "a", []byte{1, 2}, 8, 'r', false}
	insert(input1)
	scan("SELECT * FROM default_value WHERE id = 1", input1, &model.Default_value{})

	input2 := &model.Times{2, time.Now().UTC()}
	insert(input2)
	scan("SELECT * FROM times WHERE typeId = 2", input2, &model.Times{})
	if input2.Datetime.IsZero() {
		t.Error("input2.Datetime: should not be zero:", input2.Datetime)
	}

	input3 := &model.Account{11, 22, "a"}
	insert(input3)
	scan("SELECT * FROM account WHERE acc_num = 11", input3, &model.Account{})

	input4 := &model.Sub_account{1, 11, 22, "a"}
	insert(input4)
	scan("SELECT * FROM sub_account WHERE sub_acc = 1", input4, &model.Sub_account{})

	input5 := &model.Catalog{33, "a", "b", 1.32}
	insert(input5)
	scan("SELECT * FROM catalog WHERE catalog_id = 33", input5, &model.Catalog{})

	input6 := &model.Magazine{33, "a"}
	insert(input6)
	scan("SELECT * FROM magazine WHERE catalog_id = 33", input6, &model.Magazine{})

	input7 := &model.Mp3{33, 1, 1.32, "a"}
	insert(input7)
	scan("SELECT * FROM mp3 WHERE catalog_id = 33", input7, &model.Mp3{})

	input8 := &model.Book{44, "a", "b"}
	insert(input8)
	scan("SELECT * FROM book WHERE book_id = 44", input8, &model.Book{})

	input9 := &model.Chapter{1, "a", 44}
	insert(input9)
	scan("SELECT * FROM chapter WHERE chapter_id = 1", input9, &model.Chapter{})

	input10 := &model.User{55, "a", "b"}
	insert(input10)
	scan("SELECT * FROM {Q}user{Q} WHERE user_id = 55", input10, &model.User{})

	input11 := &model.Address{66, "a", "b", "c", "d"}
	insert(input11)
	scan("SELECT * FROM address WHERE address_id = 66", input11, &model.Address{})

	input12 := &model.User_address{55, 66}
	insert(input12)
	scan("SELECT * FROM user_address WHERE user_id = 55", input12, &model.User_address{})
}
예제 #26
0
func uploadAndroid(t *tasking.T) {
	err := t.Exec(fmt.Sprintf("adb install -r android/bin/%s-debug.apk", ProjectName))
	if err != nil {
		t.Error(err)
	}
}