示例#1
0
文件: test.go 项目: litixsoft/lxb
// test all packages without vendor
func test(c *taskRunner.Context) {

	// Get all packages without vendor
	pkgs, err := utils.GetAllPackages("/vendor/")
	if err != nil {
		log.Fatal(err)
	}

	// Add packages to command args
	cmdArgs := append([]string{"test"}, pkgs...)

	// If arguments are available to attach to cmdArgs.
	if len(c.Args) > 0 {
		cmdArgs = append(cmdArgs, c.Args...)
	}

	// Run test for all packages without vendor
	if err := utils.CmdRun("go", cmdArgs...); err != nil {
		log.Fatal(err)
	}
}
示例#2
0
文件: coverage.go 项目: litixsoft/lxb
// Coverage packages and create report
// // Example for coverage all packages with html report
// $lxb coverage -html
func coverageTask(c *taskRunner.Context) {

	report := ""
	reportPath := filepath.Join("_build", "reports")
	packages := []string{}

	// Clean reports
	if err := utils.CleanDirectory(reportPath); err != nil {
		log.Fatal(err)
	}

	// Check arguments for package or report options
	if len(c.Args) > 0 {

		// If the first argument a package name?
		// Check this by loading with getPackage.
		pkgName, err := utils.GetPackage(c.Args[0])
		if err != nil {
			log.Fatal(err)
		}

		// Check loaded package name
		if pkgName != "" {

			// First argument is valid package name.
			// Check report argument
			if len(c.Args) > 1 {

				// Overwrite with html report settings
				if c.Args[1] == "-html" || c.Args[1] == "-xml" {
					report = c.Args[1][1:]
				}
			}

			// Add the package name to packages for coverage.
			packages = append(packages, pkgName)

		} else {

			// First argument is not valid package name
			// Check if first argument a report setting
			if c.Args[0] == "-html" || c.Args[0] == "-xml" {

				// Set report
				report = c.Args[0][1:]

				// First argument is not valid package name but
				// a valid report setting. Set all packages for coverage
				packages, err = utils.GetAllPackages("/vendor/")
				if err != nil {
					log.Fatal(err)
				}

			} else {

				// First argument is not valid package name and
				// not a valid report setting. Exit with error.
				log.Fatalf("package %s not found", c.Args[0])
			}
		}
	} else {

		// Pass no arguments, use all packages
		var err error
		packages, err = utils.GetAllPackages("/vendor/")
		if err != nil {
			log.Fatal(err)
		}
	}

	// Start coverage and create report
	if err := lxCoverage.GocovCoverage(report, packages, reportPath, OpenHtmlReport); err != nil {
		log.Fatal(err)
	}
}