Skip to content

Commit e6c1349

Browse files
Ability to log a summary message
1 parent a977f2a commit e6c1349

24 files changed

+146
-22
lines changed

CSharpInteractive.HostApi/IHost.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ public interface IHost
8888
/// <param name="warning">Warning message.</param>
8989
void Warning(string? warning);
9090

91+
/// <summary>
92+
/// Writes a summary message to stdOut.
93+
/// <example>
94+
/// <code>
95+
/// Info("Some info");
96+
/// </code>
97+
/// </example>
98+
/// </summary>
99+
/// <param name="summary">Summary message.</param>
100+
void Summary(string? summary);
101+
91102
/// <summary>
92103
/// Writes an information message to stdOut.
93104
/// <example>

CSharpInteractive.Tests/ProcessResultHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal void ShouldLogInfoWhenFinishedAndHasHandler(ProcessState state)
2929
}
3030

3131
[Fact]
32-
public void ShouldLogInfoWhenFinishedAndHasNoHandler()
32+
public void ShouldLogSummaryWhenFinishedAndHasNoHandler()
3333
{
3434
// Given
3535
var handler = CreateInstance();
@@ -38,7 +38,7 @@ public void ShouldLogInfoWhenFinishedAndHasNoHandler()
3838
handler.Handle(new ProcessResult(_processInfo, ProcessState.Finished, 12, _description), default(Action<object>));
3939

4040
// Then
41-
_log.Verify(i => i.Info(_description));
41+
_log.Verify(i => i.Summary(_description));
4242
}
4343

4444
[Fact]

CSharpInteractive.Tests/README_TEMPLATE.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Writing an empty line to a build log](#writing-an-empty-line-to-a-build-log)
88
- [Registering errors in the build log](#registering-errors-in-the-build-log)
99
- [Registering warnings in the build log](#registering-warnings-in-the-build-log)
10+
- [Registering a summary in the build log](#registering-a-summary-in-the-build-log)
1011
- [Registering information in the build log](#registering-information-in-the-build-log)
1112
- [Registering trace information in the build log](#registering-trace-information-in-the-build-log)
1213
- Arguments and parameters
@@ -136,6 +137,12 @@ Error("Error info", "Error identifier");
136137
Warning("Warning info");
137138
```
138139

140+
### Registering a summary in the build log
141+
142+
``` CSharp
143+
Summary("Summary message");
144+
```
145+
139146
### Registering information in the build log
140147

141148
``` CSharp
@@ -360,7 +367,7 @@ using HostApi;
360367

361368
var cancellationTokenSource = new CancellationTokenSource();
362369
var task = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120")
363-
.RunAsync(default, cancellationTokenSource.Token);
370+
.RunAsync(null, cancellationTokenSource.Token);
364371

365372
cancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));
366373
task.IsCompleted.ShouldBeFalse();
@@ -372,7 +379,7 @@ If timeout expired a process will be killed.
372379
using HostApi;
373380

374381
var exitCode = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120")
375-
.Run(default, TimeSpan.FromMilliseconds(1))
382+
.Run(null, TimeSpan.FromMilliseconds(1))
376383
.ExitCode;
377384
```
378385

@@ -678,7 +685,7 @@ new DotNetFormat()
678685
``` CSharp
679686
using HostApi;
680687

681-
string? repositoryPath = default;
688+
string? repositoryPath = null;
682689
new DotNetNuGetConfigGet()
683690
.WithConfigKey("repositoryPath")
684691
.Run(output => repositoryPath = output.Line).EnsureSuccess();
@@ -1018,7 +1025,7 @@ new DotNet()
10181025
using HostApi;
10191026

10201027
// Gets the dotnet version, running a command like: "dotnet --version"
1021-
NuGetVersion? version = default;
1028+
NuGetVersion? version = null;
10221029
new DotNetCustom("--version")
10231030
.Run(message => NuGetVersion.TryParse(message.Line, out version))
10241031
.EnsureSuccess();

CSharpInteractive.Tests/UsageScenarios/BaseScenario.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public bool HasSdk(string sdkVersion)
7373

7474
public void Warning(string? warning) => Composition.Shared.Root.Host.Warning(warning);
7575

76+
public void Summary(string? summary) => Composition.Shared.Root.Host.Summary(summary);
77+
7678
public void Info(string? text) => Composition.Shared.Root.Host.Info(text);
7779

7880
public void Trace(string? trace, string? origin = null) => Composition.Shared.Root.Host.Trace(trace, origin);

CSharpInteractive.Tests/UsageScenarios/Comments/CommandLineAsyncCancellation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using HostApi;
22

33
var cancellationTokenSource = new CancellationTokenSource();
44
var task = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120")
5-
.RunAsync(default, cancellationTokenSource.Token);
5+
.RunAsync(null, cancellationTokenSource.Token);
66

77
cancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));
88
task.IsCompleted.ShouldBeFalse();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using HostApi;
22

33
var exitCode = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120")
4-
.Run(default, TimeSpan.FromMilliseconds(1))
4+
.Run(null, TimeSpan.FromMilliseconds(1))
55
.ExitCode;

CSharpInteractive.Tests/UsageScenarios/Comments/DotNetCustomScenario.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using HostApi;
22

33
// Gets the dotnet version, running a command like: "dotnet --version"
4-
NuGetVersion? version = default;
4+
NuGetVersion? version = null;
55
new DotNetCustom("--version")
66
.Run(message => NuGetVersion.TryParse(message.Line, out version))
77
.EnsureSuccess();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using HostApi;
22

3-
string? repositoryPath = default;
3+
string? repositoryPath = null;
44
new DotNetNuGetConfigGet()
55
.WithConfigKey("repositoryPath")
66
.Run(output => repositoryPath = output.Line).EnsureSuccess();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Summary("Summary message");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
3+
4+
namespace CSharpInteractive.Tests.UsageScenarios;
5+
6+
using System;
7+
8+
public class LogSummaryScenario(ITestOutputHelper output) : BaseScenario(output)
9+
{
10+
[SkippableFact]
11+
public void Run()
12+
{
13+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
14+
15+
// $visible=true
16+
// $tag=01 Output, logging and tracing
17+
// $priority=04
18+
// $description=Registering a summary in the build log
19+
// {
20+
Summary("Summary message");
21+
// }
22+
}
23+
}

0 commit comments

Comments
 (0)