Esempio n. 1
0
func (agent *rephraseRefactorer) performRefactoringOn(specs []*parser.Specification, conceptDictionary *parser.ConceptDictionary) *refactoringResult {
	specsRefactored, conceptFilesRefactored := agent.rephraseInSpecsAndConcepts(&specs, conceptDictionary)

	result := &refactoringResult{Success: false, Errors: make([]string, 0), warnings: make([]string, 0)}
	if !agent.isConcept {
		var runner *runner.TestRunner
		select {
		case runner = <-agent.startChan.RunnerChan:
		case err := <-agent.startChan.ErrorChan:
			result.Errors = append(result.Errors, "Cannot perform refactoring: Unable to connect to runner."+err.Error())
			return result
		}
		defer runner.Kill(execLogger.Current())
		stepName, err, warning := agent.getStepNameFromRunner(runner)
		if err != nil {
			result.Errors = append(result.Errors, err.Error())
			return result
		}
		if warning == nil {
			runnerFilesChanged, err := agent.requestRunnerForRefactoring(runner, stepName)
			if err != nil {
				result.Errors = append(result.Errors, fmt.Sprintf("Cannot perform refactoring: %s", err))
				return result
			}
			result.runnerFilesChanged = runnerFilesChanged
		} else {
			result.warnings = append(result.warnings, warning.Message)
		}
	}
	specFiles, conceptFiles := writeToConceptAndSpecFiles(specs, conceptDictionary, specsRefactored, conceptFilesRefactored)
	result.specsChanged = specFiles
	result.Success = true
	result.conceptsChanged = conceptFiles
	return result
}
Esempio n. 2
0
func printError(execResult *gauge_messages.ProtoExecutionResult) {
	if execResult.GetFailed() {
		console := execLogger.Current()
		console.PrintError(execResult.GetErrorMessage() + "\n")
		console.PrintError(execResult.GetStackTrace() + "\n")
	}
}
Esempio n. 3
0
func printHookError(hook *gauge_messages.ProtoHookFailure) {
	if hook != nil {
		console := execLogger.Current()
		console.PrintError(hook.GetErrorMessage())
		console.PrintError(hook.GetStackTrace())
	}
}
Esempio n. 4
0
func (writer *pluginLogger) Write(b []byte) (int, error) {
	message := string(b)
	prefixedMessage := util.AddPrefixToEachLine(message, fmt.Sprintf("[%s Plugin] : ", writer.pluginName))
	gaugeConsoleWriter := execLogger.Current()
	_, err := gaugeConsoleWriter.Write([]byte(prefixedMessage))
	return len(message), err
}
Esempio n. 5
0
func printConceptFailure(concept *gauge_messages.ProtoConcept) {
	conceptExecResult := concept.ConceptExecutionResult
	if conceptExecResult != nil && conceptExecResult.GetExecutionResult().GetFailed() {
		execLogger.Current().PrintError(fmt.Sprintf("\t %s\n", concept.ConceptStep.GetActualText()))
		printError(conceptExecResult.ExecutionResult)
	}
}
Esempio n. 6
0
func validateSpecs(manifest *manifest.Manifest, specsToExecute []*parser.Specification, runner *runner.TestRunner, conceptDictionary *parser.ConceptDictionary) {
	validator := newValidator(manifest, specsToExecute, runner, conceptDictionary)
	validationErrors := validator.validate()
	if len(validationErrors) > 0 {
		printValidationFailures(validationErrors)
		runner.Kill(execLogger.Current())
		os.Exit(1)
	}
}
Esempio n. 7
0
func printValidationFailures(validationErrors executionValidationErrors) {
	logger.Log.Warning("Validation failed. The following steps have errors")
	for _, stepValidationErrors := range validationErrors {
		for _, stepValidationError := range stepValidationErrors {
			s := stepValidationError.step
			execLogger.Current().PrintError(fmt.Sprintf("%s:%d: %s. %s\n", stepValidationError.fileName, s.LineNo, stepValidationError.message, s.LineText))
		}
	}
}
Esempio n. 8
0
func printStepFailure(step *gauge_messages.ProtoStep) {
	stepExecResult := step.StepExecutionResult
	if stepExecResult != nil && stepExecResult.ExecutionResult.GetFailed() {
		execLogger.Current().PrintError(fmt.Sprintf("\t %s\n", step.GetActualText()))
		printHookError(stepExecResult.GetPreHookFailure())
		printError(stepExecResult.ExecutionResult)
		printHookError(stepExecResult.GetPostHookFailure())
	}
}
Esempio n. 9
0
func runAPIServiceIndefinitely(port int, wg *sync.WaitGroup) {
	wg.Add(1)
	startChan := &runner.StartChannels{RunnerChan: make(chan *runner.TestRunner), ErrorChan: make(chan error), KillChan: make(chan bool)}
	go StartAPIService(port, startChan)
	select {
	case runner := <-startChan.RunnerChan:
		runner.Kill(execLogger.Current())
	case <-startChan.ErrorChan:
	}
}
Esempio n. 10
0
func printScenarioFailure(scenario *gauge_messages.ProtoScenario) {
	if scenario.GetFailed() {
		execLogger.Current().PrintError(fmt.Sprintf(" %s: \n", scenario.GetScenarioHeading()))
		printHookError(scenario.GetPreHookFailure())

		for _, scenarioItem := range scenario.GetScenarioItems() {
			if scenarioItem.GetItemType() == gauge_messages.ProtoItem_Step {
				printStepFailure(scenarioItem.GetStep())
			} else if scenarioItem.GetItemType() == gauge_messages.ProtoItem_Concept {
				printConceptFailure(scenarioItem.GetConcept())
			}
		}
		printHookError(scenario.GetPostHookFailure())
	}

}
Esempio n. 11
0
func printSpecFailure(specResult *result.SpecResult) {
	if specResult.IsFailed {
		execLogger.Current().PrintError(fmt.Sprintf("%s : %s \n", specResult.ProtoSpec.GetFileName(), specResult.ProtoSpec.GetSpecHeading()))
		printHookError(specResult.ProtoSpec.GetPreHookFailure())

		for _, specItem := range specResult.ProtoSpec.Items {
			if specItem.GetItemType() == gauge_messages.ProtoItem_Scenario {
				printScenarioFailure(specItem.GetScenario())
			} else if specItem.GetItemType() == gauge_messages.ProtoItem_TableDrivenScenario {
				printTableDrivenScenarioFailure(specItem.GetTableDrivenScenario())
			}
		}

		printHookError(specResult.ProtoSpec.GetPostHookFailure())
	}
}
Esempio n. 12
0
// Gets all steps list from the runner
func (specInfoGatherer *SpecInfoGatherer) getStepsFromRunner(killChannel chan bool) (*runner.TestRunner, error) {
	steps := make([]string, 0)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		execLogger.CriticalError(err)
	}
	testRunner, connErr := runner.StartRunnerAndMakeConnection(manifest, execLogger.Current(), killChannel)
	if connErr == nil {
		steps = append(steps, requestForSteps(testRunner)...)
		logger.ApiLog.Debug("Steps got from runner: %v", steps)
	} else {
		logger.ApiLog.Error("Runner connection failed: %s", connErr)
	}
	specInfoGatherer.runnerStepValues = specInfoGatherer.convertToStepValues(steps)
	return testRunner, connErr
}
Esempio n. 13
0
func installPluginsFromManifest(manifest *manifest.Manifest) {
	writer := execLogger.Current()
	pluginsMap := make(map[string]bool, 0)
	pluginsMap[manifest.Language] = true
	for _, plugin := range manifest.Plugins {
		pluginsMap[plugin] = false
	}

	for pluginName, isRunner := range pluginsMap {
		if !isCompatiblePluginInstalled(pluginName, "", isRunner) {
			writer.Info("Compatible version of plugin %s not found. Installing plugin %s...", pluginName, pluginName)
			installResult := InstallPlugin(pluginName, "")
			if installResult.Success {
				writer.Info("Successfully installed the plugin %s.", pluginName)
			} else {
				writer.Error("Failed to install the %s plugin.", pluginName)
			}
		} else {
			writer.Info("Plugin %s is already installed.", pluginName)
		}
	}
}
Esempio n. 14
0
func ExecuteSpecs(inParallel bool, args []string) {
	env.LoadEnv(false)
	conceptsDictionary, conceptParseResult := parser.CreateConceptsDictionary(false)
	parser.HandleParseResult(conceptParseResult)
	specsToExecute, specsSkipped := filter.GetSpecsToExecute(conceptsDictionary, args)
	if len(specsToExecute) == 0 {
		printExecutionStatus(nil, 0)
	}
	parallelInfo := &parallelInfo{inParallel: inParallel, numberOfStreams: NumberOfExecutionStreams}
	if !parallelInfo.isValid() {
		os.Exit(1)
	}
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		execLogger.CriticalError(err)
	}
	runner := startApi()
	validateSpecs(manifest, specsToExecute, runner, conceptsDictionary)
	pluginHandler := plugin.StartPlugins(manifest)
	execution := newExecution(manifest, specsToExecute, runner, pluginHandler, parallelInfo, execLogger.Current())
	result := execution.start()
	execution.finish()
	exitCode := printExecutionStatus(result, specsSkipped)
	os.Exit(exitCode)
}