Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build/IntegrationTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ assert_raises "$gpsa -verbose $valid_gpx | grep \"16 of 16 files processed succe
assert_raises "$gpsa -verbose -skip-error-exit $valid_gpx $testdata/invalid-tcx/02.tcx | grep \"16 of 17 files processed successfully\" &> /dev/null" 0
assert_raises "$gpsa -verbose -skip-error-exit $valid_gpx $testdata/invalid-tcx/02.tcx | grep \"At least one error occurred\" &> /dev/null" 1
assert_raises "$gpsa -verbose -minimum-start-time=2012-01-02 -maximum-start-time=2015-03-04 $valid_gpx | grep \"does not contain any tracks after applying the given filters\" | wc -l | grep 13 &> /dev/null" 0
assert_raises "$gpsa -verbose -std-out-format=MD -summary=additional -minimum-start-time=2026-01-01 $valid_gpx | grep \"does not contain any tracks after applying the given filters\" | wc -l | grep 16 &> /dev/null" 0
assert_raises "$gpsa -std-out-format=MD -summary=additional -markdown-track-list-text=\"my value:\" $valid_gpx | grep \"my value:\" | wc -l | grep 1 &> /dev/null" 0
assert_raises "$gpsa -std-out-format=MD -summary=additional -markdown-summary-text=\"my value:\" $valid_gpx | grep \"my value:\" | wc -l | grep 1 &> /dev/null" 0
assert_raises "$gpsa -std-out-format=MD -summary=additional -markdown-summary-text=\"my value:\" -markdown-track-list-text=\"my value:\" $valid_gpx | grep \"my value:\" | wc -l | grep 2 &> /dev/null" 0

# Test stdin
if [ -f "$csv_out" ]; then
Expand Down
10 changes: 10 additions & 0 deletions src/tobi.backfrak.de/cmd/gpsa/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ var MinStartTime string
// MaxStartTime - The maximum StartTime for a track to be added to the output. Formatted in "YYYY-MMM-dd HH:mm:ss", may without seconds or just a date
var MaxStartTime string

// MarkdownAdditionalSummaryTrackListText - The text written before the track list table in case markdown output and '-summary=additional' is used in combination
var MarkdownAdditionalSummaryTrackListText string

// MarkdownAdditionalSummaryText - The text written before the summary table in case markdown output and '-summary=additional' is used in combination
var MarkdownAdditionalSummaryText string

// ReadInputStreamBuffer - Read an input stream and figure out what kind of files are given
func ReadInputStreamBuffer(reader *bufio.Reader) ([]gpsabl.InputFile, error) {
var fileArgs []gpsabl.InputFile
Expand Down Expand Up @@ -222,6 +228,10 @@ func handleComandlineOptions() {
"The minimum StartTime for a track to be added to the output. Formatted in \"YYYY-MMM-dd HH:mm:ss\", may without seconds or just a date")
flag.StringVar(&MaxStartTime, "maximum-start-time", "",
"The maximum StartTime for a track to be added to the output. Formatted in \"YYYY-MMM-dd HH:mm:ss\", may without seconds or just a date")
flag.StringVar(&MarkdownAdditionalSummaryTrackListText, "markdown-track-list-text", "List of Tracks:",
"The text written before the track list table in case markdown output and '-summary=additional' is used in combination")
flag.StringVar(&MarkdownAdditionalSummaryText, "markdown-summary-text", "Summary table:",
"The text written before the summary table in case markdown output and '-summary=additional' is used in combination")

// Overwrite the std Usage function with some custom stuff
flag.Usage = customHelpMessage
Expand Down
3 changes: 3 additions & 0 deletions src/tobi.backfrak.de/cmd/gpsa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ func getOutPutFormater(outFile os.File) gpsabl.OutputFormater {
switch iFormater.(type) {
case gpsabl.TextOutputFormater:
iFormater = setTextutputFormater(iFormater.GetTextOutputFormater())
case *mdbl.MDOutputFormater:
(iFormater.(*mdbl.MDOutputFormater)).SummaryText = MarkdownAdditionalSummaryText
(iFormater.(*mdbl.MDOutputFormater)).TrackListText = MarkdownAdditionalSummaryTrackListText
}
if iFormater == nil {
HandleError(newUnKnownFileTypeError(outFile.Name()), "", false, DontPanicFlag)
Expand Down
2 changes: 2 additions & 0 deletions src/tobi.backfrak.de/cmd/gpsa/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,5 @@ func TestProcessValidFilesWithStartTimeFilters(t *testing.T) {
MinStartTime = oldMinStartTime
DefinedFilters = []gpsabl.TrackFilter{}
}

// ToDo: Add test for -markdown-track-list-text and -markdown-summary-text parameter
40 changes: 31 additions & 9 deletions src/tobi.backfrak.de/internal/mdbl/markdownoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type MDOutputFormater struct {
entriesToWriteCount int
lineBuffer []gpsabl.OutputLine
mux sync.Mutex
TrackListText string
SummaryText string
}

// NewMDOutputFormater - Get a new MDOutputFormater
Expand All @@ -51,6 +53,8 @@ func NewMDOutputFormater() *MDOutputFormater {
ret.timeFormater = gpsabl.RFC3339
ret.lineBuffer = []gpsabl.OutputLine{}
ret.Separator = "|"
ret.TrackListText = "List of Tracks:"
ret.SummaryText = "Summary table:"

return &ret
}
Expand Down Expand Up @@ -186,41 +190,59 @@ func (formater *MDOutputFormater) WriteOutput(outFile *os.File, summary gpsabl.S
return getErr
}

if formater.entriesToWriteCount == 0 {
formater.writtenEntiresCount = formater.entriesToWriteCount
return nil
}

for _, line := range lines {
_, errWrite := outFile.WriteString(line)
if errWrite != nil {
return errWrite
}
}
formater.writtenEntiresCount = formater.entriesToWriteCount

formater.writtenEntiresCount = formater.entriesToWriteCount
return nil
}

// GetOutputLines - Get all lines of the output
func (formater *MDOutputFormater) GetOutputLines(summary gpsabl.SummaryArg) ([]string, error) {
var lines []string
var contentLines []string
var outputLines []string
var headerLines []string
if summary == gpsabl.ADDITIONAL {
outputLines = append(outputLines, fmt.Sprintf("%s%s", formater.TrackListText, GetNewLine()))
outputLines = append(outputLines, GetNewLine())
}
headerLines = append(headerLines, formater.GetHeader())
headerLines = append(headerLines, formater.GetHeaderContentSeparator())
switch summary {
case gpsabl.NONE:
lines = append(lines, formater.GetLines()...)
contentLines = append(contentLines, formater.GetLines()...)
case gpsabl.ONLY:
lines = append(lines, formater.GetStatisticSummaryLines()...)
contentLines = append(contentLines, formater.GetStatisticSummaryLines()...)
case gpsabl.ADDITIONAL:
lines = append(lines, formater.GetLines()...)
lines = append(lines, formater.GetStatisticSummaryLines()...)
contentLines = append(contentLines, formater.GetLines()...)
default:
return nil, gpsabl.NewSummaryParamaterNotKnown(summary)
}

formater.entriesToWriteCount = len(lines)
formater.entriesToWriteCount = len(contentLines)
if formater.entriesToWriteCount > 0 {
return append(headerLines, lines...), nil
outputLines = append(outputLines, headerLines...)
outputLines = append(outputLines, contentLines...)
if summary == gpsabl.ADDITIONAL {
outputLines = append(outputLines, GetNewLine())
outputLines = append(outputLines, fmt.Sprintf("%s%s", formater.SummaryText, GetNewLine()))
outputLines = append(outputLines, GetNewLine())
outputLines = append(outputLines, headerLines...)
outputLines = append(outputLines, formater.GetStatisticSummaryLines()...)
}
return outputLines, nil
}

return lines, nil
return contentLines, nil
}

// getOutPutEntries - Add the output of a TrackFile
Expand Down
106 changes: 105 additions & 1 deletion src/tobi.backfrak.de/internal/mdbl/markdownoutput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ func TestWriteOutputNoTrack(t *testing.T) {
}
}

func TestWriteOutputEmptyTrackListAdditionalSummary(t *testing.T) {
frt := NewMDOutputFormater()

errWrite := frt.WriteOutput(os.Stdout, "additional")

if errWrite != nil {
t.Errorf("Error while writing the output: %s", errWrite.Error())
}

if frt.GetNumberOfOutputEntries() != 0 {
t.Errorf("Error: The number of output entries is %d but should be %d", frt.GetNumberOfOutputEntries(), 0)
}
}

func TestWriteOutputSummaryUnknown(t *testing.T) {
frt := NewMDOutputFormater()
trackFile := getTrackFileTwoTracksWithThreeSegments()
Expand Down Expand Up @@ -722,6 +736,10 @@ func TestGetOutputLinesNoLinesInList(t *testing.T) {
if len(lines) != numberlinesExpected {
t.Errorf("Don't get an empty list when no entries are added")
}

if frt.entriesToWriteCount != numberlinesExpected {
t.Errorf("The entriesToWriteCount is '%d' but should be '%d'", frt.entriesToWriteCount, numberlinesExpected)
}
}

func TestGetOutputLinesSummaryNone(t *testing.T) {
Expand Down Expand Up @@ -782,9 +800,95 @@ func TestGetOutputLinesSummaryAdditional(t *testing.T) {
if errOut != nil {
t.Errorf("Got an error but did not expect one. The error is: %s", err.Error())
}
if len(lines) != 8 {
if len(lines) != 15 {
t.Errorf("Got an unexpected number of lines")
}

if lines[0] != fmt.Sprintf("List of Tracks:%s", GetNewLine()) {
t.Errorf("The 1. line has not the expected content. It is '%s' but should be 'List of Tracks:'", lines[0])
}

if lines[1] != GetNewLine() {
t.Errorf("The 2. line has not the expected content. It is '%s' but should be ''", lines[1])
}

if lines[2] != frt.GetHeader() {
t.Errorf("The 3. line has not the expected content. It is '%s' but should be '%s'", lines[3], frt.GetHeader())
}

if lines[6] != GetNewLine() {
t.Errorf("The 7. line has not the expected content. It is '%s' but should be ''", lines[6])
}

if lines[7] != fmt.Sprintf("Summary table:%s", GetNewLine()) {
t.Errorf("The 8. line has not the expected content. It is '%s' but should be 'Summary table:'", lines[7])
}

if lines[8] != GetNewLine() {
t.Errorf("The 9. line has not the expected content. It is '%s' but should be ''", lines[8])
}

if lines[9] != frt.GetHeader() {
t.Errorf("The 10. line has not the expected content. It is '%s' but should be '%s'", lines[9], frt.GetHeader())
}

if frt.entriesToWriteCount != 2 {
t.Errorf("GetNumberOfOutputEntries does not return the expected value. It is '%d' but should be '%d'", frt.entriesToWriteCount, 2)
}
}

func TestGetOutputLinesSummaryAdditionalNoTrackPassFilter(t *testing.T) {
frt := NewMDOutputFormater()

trackFile1 := getTrackFileWithDifferentTime()
err := frt.AddOutPut(trackFile1, "file", false)
if err != nil {
t.Errorf("Got an error but did not expect one. The error is: %s", err.Error())
}
trackFile2 := getSimpleTrackFileWithTime()
err = frt.AddOutPut(trackFile2, "file", false)
if err != nil {
t.Errorf("Got an error but did not expect one. The error is: %s", err.Error())
}
lines, errOut := frt.GetOutputLines("additional")
if errOut != nil {
t.Errorf("Got an error but did not expect one. The error is: %s", err.Error())
}
if len(lines) != 15 {
t.Errorf("Got an unexpected number of lines")
}

if lines[0] != fmt.Sprintf("List of Tracks:%s", GetNewLine()) {
t.Errorf("The 1. line has not the expected content. It is '%s' but should be 'List of Tracks:'", lines[0])
}

if lines[1] != GetNewLine() {
t.Errorf("The 2. line has not the expected content. It is '%s' but should be ''", lines[1])
}

if lines[2] != frt.GetHeader() {
t.Errorf("The 3. line has not the expected content. It is '%s' but should be '%s'", lines[3], frt.GetHeader())
}

if lines[6] != GetNewLine() {
t.Errorf("The 7. line has not the expected content. It is '%s' but should be ''", lines[6])
}

if lines[7] != fmt.Sprintf("Summary table:%s", GetNewLine()) {
t.Errorf("The 8. line has not the expected content. It is '%s' but should be 'Summary table:'", lines[7])
}

if lines[8] != GetNewLine() {
t.Errorf("The 9. line has not the expected content. It is '%s' but should be ''", lines[8])
}

if lines[9] != frt.GetHeader() {
t.Errorf("The 10. line has not the expected content. It is '%s' but should be '%s'", lines[9], frt.GetHeader())
}

if frt.entriesToWriteCount != 2 {
t.Errorf("GetNumberOfOutputEntries does not return the expected value. It is '%d' but should be '%d'", frt.entriesToWriteCount, 2)
}
}

func TestGetOutputLinesSummaryUnValid(t *testing.T) {
Expand Down