github.com/getgauge/gauge@v1.6.9/reporter/consoleFormatter.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package reporter
     8  
     9  import (
    10  	"fmt"
    11  	"strings"
    12  
    13  	"github.com/getgauge/gauge/util"
    14  )
    15  
    16  const (
    17  	scenarioIndentation = 2
    18  	stepIndentation     = 4
    19  	errorIndentation    = 2
    20  	successSymbol       = "✔"
    21  	failureSymbol       = "✘"
    22  	successChar         = "P"
    23  	failureChar         = "F"
    24  )
    25  
    26  func formatScenario(scenarioHeading string) string {
    27  	return fmt.Sprintf("## %s", scenarioHeading)
    28  }
    29  
    30  func formatSpec(specHeading string) string {
    31  	return fmt.Sprintf("# %s", specHeading)
    32  }
    33  
    34  func indent(text string, indentation int) string {
    35  	return spaces(indentation) + strings.Replace(text, newline, newline+spaces(indentation), -1)
    36  }
    37  
    38  func spaces(numOfSpaces int) string {
    39  	if numOfSpaces <= 0 {
    40  		return ""
    41  	}
    42  	return strings.Repeat(" ", numOfSpaces)
    43  }
    44  
    45  func getFailureSymbol() string {
    46  	if util.IsWindows() {
    47  		return spaces(1) + failureChar
    48  	}
    49  	return spaces(1) + failureSymbol
    50  }
    51  
    52  func getSuccessSymbol() string {
    53  	if util.IsWindows() {
    54  		return spaces(1) + successChar
    55  	}
    56  	return spaces(1) + successSymbol
    57  }
    58  
    59  func prepErrorMessage(msg string) string {
    60  	return fmt.Sprintf("Error Message: %s", msg)
    61  }
    62  
    63  func prepStepMsg(msg string) string {
    64  	return fmt.Sprintf("\nFailed Step: %s", msg)
    65  }
    66  
    67  func prepSpecInfo(fileName string, lineNo int, excludeLineNo bool) string {
    68  	if excludeLineNo {
    69  		return fmt.Sprintf("Specification: %s", util.RelPathToProjectRoot(fileName))
    70  	}
    71  	return fmt.Sprintf("Specification: %s:%v", util.RelPathToProjectRoot(fileName), lineNo)
    72  }
    73  
    74  func prepStacktrace(stacktrace string) string {
    75  	return fmt.Sprintf("Stacktrace: \n%s", stacktrace)
    76  }
    77  
    78  func formatErrorFragment(fragment string, indentation int) string {
    79  	return indent(fragment, indentation+errorIndentation) + newline
    80  }