// Condition reports whether the given condition cond is satisfied or not. This
// function is called after the builtin testscript conditions which are
// documented in the testscript package, examples include:
//
// [short]
// [go1.14]
//
// Example conditions:
//
// [golang.org/issues/1234]
// Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches
// the condition string
//
// [github.com/govim/govim/issues/4321]
// Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches
// the condition string
//
// [vim]
// Satisfied if we are testing with vim
//
// [gvim]
// Satisfied if we are testing with gvim
//
// [v1.2.3]
// Satisfied if we are running vim/gvim/whatever version >=v1.2.3
//
Condition reports whether the given condition cond is satisfied or not. This
function is called after the builtin testscript conditions which are
documented in the testscript package, examples include.



Example conditions.

[golang.org/issues/1234]
Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches
the condition string

[github.com/govim/govim/issues/4321]
Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches
the condition string

[vim]
Satisfied if we are testing with vim

[gvim]
Satisfied if we are testing with gvim

[v1.2.3]
Satisfied if we are running vim/gvim/whatever version >=v1.2.3
// Condition reports whether the given condition cond is satisfied or not . This // function is called after the builtin testscript conditions which are // documented in the testscript package examples include : // // [ short ] // [ go1 . 14 ] // // Example conditions : // // [ golang . org / issues / 1234 ] // Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches // the condition string // // [ github . com / govim / govim / issues / 4321 ] // Satisfied if GOVIM_TESTSCRIPT_ISSUES does not contain a regexp that matches // the condition string // // [ vim ] // Satisfied if we are testing with vim // // [ gvim ] // Satisfied if we are testing with gvim // // [ v1 . 2 . 3 ] // Satisfied if we are running vim / gvim / whatever version > = v1 . 2 . 3 //
func Condition(cond string) (bool, error) {
	var issuesCond *regexp.Regexp
	if v := os.Getenv(testsetup.EnvTestscriptIssues); v != "" {
		r, err := regexp.Compile(v)
		if err != nil {
			return false, fmt.Errorf("failed to compile regexp %q specified via %v: %v", v, testsetup.EnvTestscriptIssues, err)
		}
		issuesCond = r
	}
	for _, r := range issuesConditions {
		if r.MatchString(cond) {
			if issuesCond != nil && issuesCond.MatchString(cond) {
				return false, nil
			}
			return true, nil
		}
	}
	envf, cmd, err := testsetup.EnvLookupFlavorCommand()
	if err != nil {
		return false, err
	}
	if semver.IsValid(cond) {
		version, err := getVimFlavourVersion(cmd)
		if err != nil {
			return false, err
		}
		return semver.Compare(version, cond) >= 0, nil
	}
	var f govim.Flavor
	switch cond {
	case govim.FlavorVim.String():
		f = govim.FlavorVim
	case govim.FlavorGvim.String():
		f = govim.FlavorGvim
	default:
		return false, fmt.Errorf("unknown condition %v", cond)
	}
	return envf == f, nil
}
func Condition ( cond string ) ( bool , error ) { var issuesCond * regexp . Regexp if v := os . Getenv ( testsetup . EnvTestscriptIssues ) ; v != " " { r , err := regexp . Compile ( v ) if err != nil { return false , fmt . Errorf ( " " , v , testsetup . EnvTestscriptIssues , err ) } issuesCond = r } for _ , r := range issuesConditions { if r . MatchString ( cond ) { if issuesCond != nil && issuesCond . MatchString ( cond ) { return false , nil } return true , nil } } envf , cmd , err := testsetup . EnvLookupFlavorCommand ( ) if err != nil { return false , err } if semver . IsValid ( cond ) { version , err := getVimFlavourVersion ( cmd ) if err != nil { return false , err } return semver . Compare ( version , cond ) >= 0 , nil } var f govim . Flavor switch cond { case govim . FlavorVim . String ( ) : f = govim . FlavorVim case govim . FlavorGvim . String ( ) : f = govim . FlavorGvim default : return false , fmt . Errorf ( " " , cond ) } return envf == f , nil }
Condition reports whether the given condition cond is satisfied or not.
Condition reports whether the given condition cond is satisfied or not .
// Does this condition match any of the issue tracker regexps? If so, return // true unless the GOVIM_TESTSCRIPT_ISSUES specifies a regexp that matches // the condition. // Derive environment // Is the condition a semver version? If so, check // against the version of vim running // Fallthrough to the final mode of checking the flavour // If we don't match a flavour we're done: error