Пример #1
0
func loadWire(r *gocuc.Runner) error {
	wire_root := "features/step_definitions/"
	files, err := ioutil.ReadDir(wire_root)
	if err != nil {
		return err
	}

	for _, f := range files {
		matched, _ := filepath.Match("*.wire", f.Name())
		if matched {
			return r.LoadWire(wire_root + f.Name())
		}
	}
	return fmt.Errorf("No wire file found")
}
Пример #2
0
func main() {
	flag.Parse()
	var readers []featureFile

	var cmd *exec.Cmd
	var timeout *time.Timer

	if *launchPath != "" {
		args := strings.Split(*launchArgs, ",")
		cmd = exec.Command(*launchPath, args...)
		cmd.Dir = *launchDir
		log.Printf("Launching: %s", *launchPath)
		err := cmd.Start()
		if err != nil {
			log.Fatal("Launch Path specifed, but unable to launch process: %s %+v %+v", *launchPath, args, err)
		}
		time.Sleep(time.Second)
		timeout = time.AfterFunc(time.Hour, func() {
			destroyProcess(cmd)
			panic("THIS TEST RAN FOR AN HOUR, LETS STOP NOW")
		})
	}
	r := gocuc.Runner{}

	err := loadWire(&r)
	if err != nil {
		r.SetWire(*wireHost, *wirePort)
	}

	for _, l := range strings.Split(*outputMode, ",") {
		err = r.AddLogger(l)
		if err != nil {
			log.Fatalf("Unable to set output logger: %+v", err)
		}
	}
	r.Init()

	if len(os.Args) <= 1 {
		readers = append(readers, featureFile{os.Stdin, "STDIN"})
	} else {
		for i := range flag.Args() {
			path := flag.Arg(i)
			fmt.Printf("Running test: %s\n", path)
			matches, err := filepath.Glob(path)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Error: %s\n", err)
				os.Exit(1)
				return
			}
			for _, m := range matches {
				file, err := os.Open(m)
				if err != nil {
					fmt.Fprintf(os.Stderr, "Error: %s\n", err)
					os.Exit(1)
					return
				}
				defer file.Close()
				name := filepath.Base(m)
				readers = append(readers, featureFile{file, name})
			}
		}
	}

	startTime := time.Now().UnixNano() / 1e6
	for i := range readers {
		//err := GenerateAstJson(readers[i], os.Stdout, true)
		err := r.RunFeature(readers[i].r, readers[i].name)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
		}
	}
	endTime := time.Now().UnixNano() / 1e6
	if os.Getenv("GHERKIN_PERF") != "" {
		fmt.Fprintf(os.Stderr, "%d\n", endTime-startTime)
	}
	r.Shutdown()

	destroyProcess(cmd)
	if timeout != nil {
		timeout.Stop()
	}

}