Exemple #1
0
//Test tests problems.
func Test(dir string, problems []string, isConcurrent bool) {
	contest := Load(dir)
	logger := Logger.WithField("state", "test_problems")
	var tests []Problem
	if problems == nil || len(problems) == 0 {
		tests = contest.Problems
	} else {

		for _, s := range problems {
			hit := false
			for _, x := range contest.Problems {
				if s == x.Name {
					tests = append(tests, x)
					hit = true
					break
				}
			}
			if !hit {
				logger.WithFields(logrus.Fields{
					"type":  "error",
					"error": libra.IE.String(),
					"info":  "problem not found",
				}).Warnf("problem %s not found", s)
			}
		}
	}
	logger.WithFields(logrus.Fields{
		"type": "info",
		"info": "test problems start",
	}).Infof("test problems start: %v", tests)

	for _, x := range tests {
		libra.Test(filepath.Join(dir, x.Name), isConcurrent, logger)
	}

	logger.WithFields(logrus.Fields{
		"type": "info",
		"info": "test problems end",
	}).Info("test problems end")
}
Exemple #2
0
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: "show debug message",
		},
		cli.BoolFlag{
			Name:  "concurrent, c",
			Usage: "concurrent testing",
		},
	},
	Action: func(c *cli.Context) {
		if c.Bool("json") {
			Logger.Formatter = &logrus.JSONFormatter{}
		}
		if c.Bool("debug") {
			Logger.Level = logrus.DebugLevel
		}
		logger := logrus.NewEntry(Logger)
		dir, err := os.Getwd()
		if err != nil {
			logger.Panic(err)
		}
		_, err = os.Stat(filepath.Join(dir, "config.toml"))
		if err == nil {
			libra.Init(dir, logger)
		} else {
			libra.Init("", logger)
		}

		libra.Test(dir, c.Bool("concurrent"), logger)
	}}