-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test and fix the gitlab reporter #2484
Merged
matthid
merged 1 commit into
fsprojects:release/next
from
baronfel:gitlab-reporter-fixed-for-real-hopefully
Mar 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -172,32 +172,33 @@ module GitLab = | |||||
member x.LogSectionName = | ||||||
sprintf "%s_%s" (x.Type.Trim()) (x.Name.Trim()) | ||||||
|
||||||
type Writer = bool -> System.ConsoleColor -> bool -> string -> unit | ||||||
type Ticks = unit -> int64 | ||||||
type ColorMapper = TraceData -> System.ConsoleColor | ||||||
/// Implements a TraceListener for TeamCity build servers. | ||||||
/// ## Parameters | ||||||
/// - `importantMessagesToStdErr` - Defines whether to trace important messages to StdErr. | ||||||
/// - `colorMap` - A function which maps TracePriorities to ConsoleColors. | ||||||
type internal GitLabTraceListener() = | ||||||
|
||||||
type internal GitLabTraceListener(write: Writer, colorMapper: ColorMapper, getTicks: Ticks) = | ||||||
interface ITraceListener with | ||||||
/// Writes the given message to the Console. | ||||||
member __.Write msg = | ||||||
let color = ConsoleWriter.colorMap msg | ||||||
let color = colorMapper msg | ||||||
let importantMessagesToStdErr = true | ||||||
let write = ConsoleWriter.write | ||||||
match msg with | ||||||
| TraceData.ImportantMessage text | TraceData.ErrorMessage text -> | ||||||
write importantMessagesToStdErr color true text | ||||||
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) -> | ||||||
write false color newLine text | ||||||
| TraceData.OpenTag (tag, descr) -> | ||||||
let unixTimestamp = System.DateTimeOffset.UtcNow.ToUnixTimeSeconds() | ||||||
let sectionHeader = sprintf "section_start:%d:%s\r\e[0K%s" unixTimestamp tag.LogSectionName | ||||||
let unixTimestamp = getTicks () | ||||||
let sectionHeader = sprintf @"section_start:%d:%s\r\e[0K%s" unixTimestamp tag.LogSectionName | ||||||
match descr with | ||||||
| Some d -> write false color true (sectionHeader d) | ||||||
| None -> write false color true (sectionHeader System.String.Empty) | ||||||
| TraceData.CloseTag (tag, time, state) -> | ||||||
let unixTimestamp = System.DateTimeOffset.UtcNow.ToUnixTimeSeconds() | ||||||
let sectionFooter = sprintf "section_end:%d:%s\r\e[0K" unixTimestamp tag.LogSectionName | ||||||
let unixTimestamp = getTicks() | ||||||
let sectionFooter = sprintf @"section_end:%d:%s\r\e[0K" unixTimestamp tag.LogSectionName | ||||||
write false color true sectionFooter | ||||||
| TraceData.BuildState (state, _) -> | ||||||
write false color true (sprintf "Changing BuildState to: %A" state) | ||||||
|
@@ -214,9 +215,10 @@ module GitLab = | |||||
write false color true (sprintf "Build Number: %s" number) | ||||||
| TraceData.TestStatus (test, status) -> | ||||||
write false color true (sprintf "Test '%s' status: %A" test status) | ||||||
|
||||||
let currentTicks () = | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
System.DateTimeOffset.UtcNow.ToUnixTimeSeconds() | ||||||
let defaultTraceListener = | ||||||
GitLabTraceListener() :> ITraceListener | ||||||
GitLabTraceListener(ConsoleWriter.write, ConsoleWriter.colorMap, currentTicks) :> ITraceListener | ||||||
let detect () = | ||||||
BuildServer.buildServer = BuildServer.GitLabCI | ||||||
let install(force:bool) = | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Fake.BuildServer.GitLab | ||
|
||
open Expecto | ||
open Fake.Core | ||
open Fake.BuildServer | ||
|
||
let testCases = [ | ||
test "can emit correct collapsed output" { | ||
let mutable messages = [] | ||
let writer _ _ newLine message = | ||
let message = if newLine then message + @"\n" else message | ||
messages <- message :: messages | ||
let sameTicks _ = 1L | ||
let sameColorMapper _ = System.ConsoleColor.White | ||
let listener = GitLab.GitLabTraceListener(writer, sameColorMapper, sameTicks) :> Fake.Core.ITraceListener | ||
|
||
let tag = KnownTags.Target("my_first_section") | ||
let traceMessages = [ | ||
TraceData.OpenTag(tag, Some "Header of the 1st collapsible section") | ||
TraceData.LogMessage("this line should be hidden when collapsed", true) | ||
TraceData.CloseTag(tag, System.TimeSpan.FromSeconds 1., TagStatus.Success) | ||
] | ||
for trace in traceMessages do | ||
listener.Write trace | ||
|
||
let inOrder = List.rev messages | ||
let expected = [ | ||
@"section_start:1:target_my_first_section\r\e[0KHeader of the 1st collapsible section\n" | ||
@"this line should be hidden when collapsed\n" | ||
@"section_end:1:target_my_first_section\r\e[0K\n" | ||
] | ||
Expect.equal inOrder expected "should have output the correct collapsible trace" | ||
} | ||
] | ||
|
||
|
||
[<Tests>] | ||
let tests = testList "Fake.BuildeServer.GitLab.Tests" testCases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should those aliases be internal?