gitee.com/mirrors/gauge@v1.0.6/reporter/consoleFormatter.go (about)

     1  // Copyright 2015 ThoughtWorks, Inc.
     2  
     3  // This file is part of Gauge.
     4  
     5  // Gauge is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  
    10  // Gauge is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  
    15  // You should have received a copy of the GNU General Public License
    16  // along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package reporter
    19  
    20  import (
    21  	"fmt"
    22  	"strings"
    23  
    24  	"github.com/getgauge/gauge/util"
    25  )
    26  
    27  const (
    28  	scenarioIndentation = 2
    29  	stepIndentation     = 4
    30  	errorIndentation    = 2
    31  	successSymbol       = "✔"
    32  	failureSymbol       = "✘"
    33  	successChar         = "P"
    34  	failureChar         = "F"
    35  )
    36  
    37  func formatScenario(scenarioHeading string) string {
    38  	return fmt.Sprintf("## %s", scenarioHeading)
    39  }
    40  
    41  func formatSpec(specHeading string) string {
    42  	return fmt.Sprintf("# %s", specHeading)
    43  }
    44  
    45  func indent(text string, indentation int) string {
    46  	return spaces(indentation) + strings.Replace(text, newline, newline+spaces(indentation), -1)
    47  }
    48  
    49  func spaces(numOfSpaces int) string {
    50  	if numOfSpaces <= 0 {
    51  		return ""
    52  	}
    53  	return strings.Repeat(" ", numOfSpaces)
    54  }
    55  
    56  func getFailureSymbol() string {
    57  	if util.IsWindows() {
    58  		return spaces(1) + failureChar
    59  	}
    60  	return spaces(1) + failureSymbol
    61  }
    62  
    63  func getSuccessSymbol() string {
    64  	if util.IsWindows() {
    65  		return spaces(1) + successChar
    66  	}
    67  	return spaces(1) + successSymbol
    68  }
    69  
    70  func prepErrorMessage(msg string) string {
    71  	return fmt.Sprintf("Error Message: %s", msg)
    72  }
    73  
    74  func prepStepMsg(msg string) string {
    75  	return fmt.Sprintf("\nFailed Step: %s", msg)
    76  }
    77  
    78  func prepSpecInfo(fileName string, lineNo int, excludeLineNo bool) string {
    79  	if excludeLineNo {
    80  		return fmt.Sprintf("Specification: %s", util.RelPathToProjectRoot(fileName))
    81  	}
    82  	return fmt.Sprintf("Specification: %s:%v", util.RelPathToProjectRoot(fileName), lineNo)
    83  }
    84  
    85  func prepStacktrace(stacktrace string) string {
    86  	return fmt.Sprintf("Stacktrace: \n%s", stacktrace)
    87  }
    88  
    89  func formatErrorFragment(fragment string, indentation int) string {
    90  	return indent(fragment, indentation+errorIndentation) + newline
    91  }