当前位置: 首页>>代码示例>>Golang>>正文


Golang Change.Indirect方法代码示例

本文整理汇总了Golang中github.com/maruel/pre-commit-go/scm.Change.Indirect方法的典型用法代码示例。如果您正苦于以下问题:Golang Change.Indirect方法的具体用法?Golang Change.Indirect怎么用?Golang Change.Indirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/maruel/pre-commit-go/scm.Change的用法示例。


在下文中一共展示了Change.Indirect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

// Run implements Check.
func (c *Coverage) Run(change scm.Change, options *Options) error {
	profile, err := c.RunProfile(change, options)
	if err != nil {
		return err
	}

	if c.UseGlobalInference {
		out, err := ProcessProfile(profile, &c.Global)
		if out != "" {
			log.Printf("coverage for %s:\n%s\n", change.Repo().Root(), out)
		}
		if err != nil {
			return fmt.Errorf("coverage for %s: %s", change.Repo().Root(), err)
		}
	} else {
		for _, testPkg := range change.Indirect().TestPackages() {
			p := profile.Subset(pkgToDir(testPkg))
			settings := c.SettingsForPkg(testPkg)
			if settings.MinCoverage == 0 {
				continue
			}
			out, err := ProcessProfile(p, settings)
			if out != "" {
				log.Printf("%s:\n%s\n", testPkg, out)
			}
			if err != nil {
				return fmt.Errorf("coverage for %s: %s", testPkg, err)
			}
		}
	}
	return nil
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:33,代码来源:coverage.go

示例2: RunProfile

// RunProfile runs a coverage run according to the settings and return results.
func (c *Coverage) RunProfile(change scm.Change, options *Options) (profile CoverageProfile, err error) {
	// go test accepts packages, not files.
	var testPkgs []string
	if c.UseGlobalInference {
		testPkgs = change.All().TestPackages()
	} else {
		testPkgs = change.Indirect().TestPackages()
	}
	if len(testPkgs) == 0 {
		// Sir, there's no test.
		return nil, nil
	}

	tmpDir, err2 := ioutil.TempDir("", "pre-commit-go")
	if err2 != nil {
		return nil, err2
	}
	defer func() {
		err2 := internal.RemoveAll(tmpDir)
		if err == nil {
			err = err2
		}
	}()

	if c.UseGlobalInference {
		profile, err = c.RunGlobal(change, options, tmpDir)
	} else {
		profile, err = c.RunLocal(change, options, tmpDir)
	}
	if err != nil {
		return nil, err
	}

	if c.isGoverallsEnabled() {
		// Please send a pull request if the following doesn't work for you on your
		// favorite CI system.
		out, _, _, err2 := options.Capture(change.Repo(), "goveralls", "-coverprofile", filepath.Join(tmpDir, "profile.cov"))
		// Don't fail the build.
		if err2 != nil {
			fmt.Printf("%s", out)
		}
	}
	return profile, nil
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:45,代码来源:coverage.go

示例3: RunLocal

// RunLocal runs all tests and reports the merged coverage of each individual
// covered package.
func (c *Coverage) RunLocal(change scm.Change, options *Options, tmpDir string) (CoverageProfile, error) {
	testPkgs := change.Indirect().TestPackages()
	type result struct {
		file string
		err  error
	}
	results := make(chan *result)
	for i, tp := range testPkgs {
		go func(index int, testPkg string) {
			settings := c.SettingsForPkg(testPkg)
			// Skip coverage if disabled for this directory.
			if settings.MinCoverage == 0 {
				results <- nil
				return
			}

			p := filepath.Join(tmpDir, fmt.Sprintf("test%d.cov", index))
			args := []string{
				"go", "test", "-v", "-covermode=count",
				"-coverprofile", p,
				"-timeout", fmt.Sprintf("%ds", options.MaxDuration),
				testPkg,
			}
			out, exitCode, duration, _ := options.Capture(change.Repo(), args...)
			if duration > time.Second {
				log.Printf("%s was slow: %s", args, round(duration, time.Millisecond))
			}
			if exitCode != 0 {
				results <- &result{err: fmt.Errorf("%s %s failed:\n%s", strings.Join(args, " "), testPkg, processStackTrace(out))}
				return
			}
			results <- &result{file: p}
		}(i, tp)
	}

	// Sends to coveralls.io if applicable. Do not write to disk unless needed.
	var f readWriteSeekCloser
	var err error
	if c.isGoverallsEnabled() {
		if f, err = os.Create(filepath.Join(tmpDir, "profile.cov")); err != nil {
			return nil, err
		}
	} else {
		f = &buffer{}
	}

	// Aggregate all results.
	counts := map[string]int{}
	for i := 0; i < len(testPkgs); i++ {
		result := <-results
		if err != nil {
			continue
		}
		if result == nil {
			continue
		}
		if result.err != nil {
			err = result.err
			continue
		}
		if err2 := loadRawCoverage(result.file, counts); err == nil {
			// Wait for all tests to complete before returning.
			err = err2
		}
	}
	if err != nil {
		f.Close()
		return nil, err
	}
	return loadMergeAndClose(f, counts, change)
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:73,代码来源:coverage.go


注:本文中的github.com/maruel/pre-commit-go/scm.Change.Indirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。