Exemple #1
0
func printSummary(summary map[string]error, printAllLogs bool) {
	allPassed := true

	if !printAllLogs {
		buflog.Buf().Activate()
		defer func() {
			if !allPassed {
				buflog.Buf().PrintLogs()
			}
			buflog.Buf().Deactivate()
		}()
	}

	log.Info("Run %d test files.", len(summary))
	for testFile, err := range summary {
		if err != nil {
			log.Error(fmt.Sprintf("\tFAIL\t%s: %s", testFile, err.Error()))
			allPassed = false
		} else if printAllLogs {
			log.Notice("\tOK\t%s", testFile)
		}
	}

	if allPassed {
		log.Notice("All tests have passed.")
	}
}
Exemple #2
0
func (runner *TestRunner) runTest(testName string, env *Environment) (err error) {
	if !runner.printAllLogs {
		buflog.Buf().Activate()
		defer func() {
			if err != nil {
				buflog.Buf().PrintLogs()
			}
			buflog.Buf().Deactivate()
		}()
	}

	defer func() {
		runner.printTestResult(testName, err)
	}()

	err = env.InitializeEnvironment()
	if err != nil {
		return metaError{err}
	}
	defer env.ClearEnvironment()

	if runner.setUp {
		_, err = env.VM.Call("setUp", nil)
		if err != nil {
			return
		}
	}

	defer func() {
		if failed := recover(); failed != nil {
			if _, ok := failed.(error); ok {
				err = failed.(error)
			} else {
				err = fmt.Errorf("%v", failed)
			}
		}
	}()

	if runner.tearDown {
		defer func() {
			_, tearDownError := env.VM.Call("tearDown", nil)
			if tearDownError != nil && err == nil {
				err = tearDownError
			}
		}()
	}

	_, err = env.VM.Call(testName, nil)
	if err != nil {
		if ottoError, ok := err.(*otto.Error); ok {
			err = fmt.Errorf(ottoError.String())
		}
	}
	mockError := env.CheckAllMockCallsMade()
	if err == nil {
		err = mockError
	}
	return
}