-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved package tests into test project
- Loading branch information
Showing
49 changed files
with
1,227 additions
and
493 deletions.
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"gpgsign", | ||
"nologo", | ||
"nupkg", | ||
"Sdks", | ||
"shas", | ||
"Versioner", | ||
"Xbehave", | ||
|
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,5 @@ | ||
{ | ||
"ignore": [ | ||
"MinVerTests.Packages/**" | ||
] | ||
} |
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,6 @@ | ||
#if !NETCOREAPP2_1 | ||
namespace MinVerTests.Infra | ||
{ | ||
public record AssemblyVersion(int Major, int Minor, int Build, int Revision); | ||
} | ||
#endif |
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,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using CliWrap; | ||
using CliWrap.Buffered; | ||
|
||
namespace MinVerTests.Infra | ||
{ | ||
internal static class CommandExtensions | ||
{ | ||
private static int index; | ||
|
||
public static async Task<BufferedCommandResult> ExecuteBufferedLoggedAsync(this Command command) | ||
{ | ||
var validation = command.Validation; | ||
|
||
var result = await command.WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(); | ||
|
||
var index = Interlocked.Increment(ref CommandExtensions.index); | ||
|
||
var log = | ||
$@" | ||
# Command {index} | ||
## Target file path | ||
`{command.TargetFilePath}` | ||
## Arguments | ||
`{command.Arguments}` | ||
## Environment variables | ||
```text | ||
{string.Join(Environment.NewLine, command.EnvironmentVariables.Select(pair => $"{pair.Key}={pair.Value}"))} | ||
``` | ||
## Exit code | ||
`{result.ExitCode}` | ||
## Standard error | ||
```text | ||
{result.StandardError} | ||
``` | ||
## Standard output | ||
```text | ||
{result.StandardOutput} | ||
``` | ||
"; | ||
|
||
await File.WriteAllTextAsync(Path.Combine(command.WorkingDirPath, $"command-{index:D2}.md"), log); | ||
|
||
return result.ExitCode == 0 || validation == CommandResultValidation.None ? result : throw new Exception(log); | ||
} | ||
} | ||
} |
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,12 @@ | ||
namespace MinVerTests.Infra | ||
{ | ||
internal static class Configuration | ||
{ | ||
public const string Current = | ||
#if DEBUG | ||
"Debug"; | ||
#elif RELEASE | ||
"Release"; | ||
#endif | ||
} | ||
} |
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,6 @@ | ||
#if !NETCOREAPP2_1 | ||
namespace MinVerTests.Infra | ||
{ | ||
public record FileVersion(int FileMajorPart, int FileMinorPart, int FileBuildPart, int FilePrivatePart, string ProductVersion); | ||
} | ||
#endif |
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,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using CliWrap; | ||
using CliWrap.Buffered; | ||
|
||
namespace MinVerTests.Infra | ||
{ | ||
public static class Git | ||
{ | ||
public static async Task EnsureEmptyRepositoryAndCommit(string path) | ||
{ | ||
await EnsureEmptyRepository(path); | ||
await Commit(path); | ||
} | ||
|
||
public static Task Commit(string path) => | ||
Cli.Wrap("git").WithArguments("commit -m '.' --allow-empty").WithWorkingDirectory(path).ExecuteAsync(); | ||
|
||
public static async Task EnsureEmptyRepository(string path) | ||
{ | ||
FileSystem.EnsureEmptyDirectory(path); | ||
await Init(path); | ||
} | ||
|
||
public static async Task Init(string path) | ||
{ | ||
_ = await Cli.Wrap("git").WithArguments("init").WithWorkingDirectory(path).ExecuteAsync(); | ||
_ = await Cli.Wrap("git").WithArguments("config user.email [email protected]").WithWorkingDirectory(path).ExecuteAsync(); | ||
_ = await Cli.Wrap("git").WithArguments("config user.name John Doe").WithWorkingDirectory(path).ExecuteAsync(); | ||
_ = await Cli.Wrap("git").WithArguments("config commit.gpgsign false").WithWorkingDirectory(path).ExecuteAsync(); | ||
} | ||
|
||
public static async Task<string> GetGraph(string path) => | ||
(await Cli.Wrap("git").WithArguments("log --graph --pretty=format:'%d'").WithWorkingDirectory(path).ExecuteBufferedAsync()) | ||
.StandardOutput; | ||
|
||
public static Task Tag(string path, string tag) => | ||
Cli.Wrap("git").WithArguments($"tag {tag}").WithWorkingDirectory(path).ExecuteAsync(); | ||
|
||
public static Task Tag(string path, string tagName, string sha) => | ||
Cli.Wrap("git").WithArguments($"tag {tagName} {sha}").WithWorkingDirectory(path).ExecuteAsync(); | ||
|
||
public static Task AnnotatedTag(string path, string tag, string message) => | ||
Cli.Wrap("git").WithArguments($"tag {tag} -a -m '{message}'").WithWorkingDirectory(path).ExecuteAsync(); | ||
|
||
public static async Task<IEnumerable<string>> GetCommitShas(string path) => | ||
(await Cli.Wrap("git").WithArguments("log --pretty=format:\"%H\"").WithWorkingDirectory(path).ExecuteBufferedAsync()) | ||
.StandardOutput | ||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
public static Task Checkout(string path, string sha) => | ||
Cli.Wrap("git").WithArguments($"checkout {sha}").WithWorkingDirectory(path).ExecuteAsync(); | ||
} | ||
} |
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,26 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using CliWrap; | ||
|
||
namespace MinVerTests.Infra | ||
{ | ||
public static class MinVerCli | ||
{ | ||
public static async Task<(string, string)> Run(string workingDirectory, string configuration = Configuration.Current, params (string, string)[] envVars) | ||
{ | ||
var environmentVariables = envVars.ToDictionary(envVar => envVar.Item1, envVar => envVar.Item2, StringComparer.OrdinalIgnoreCase); | ||
_ = environmentVariables.TryAdd("MinVerVerbosity".ToAltCase(), "trace"); | ||
|
||
var result = await Cli.Wrap("dotnet") | ||
.WithArguments($"exec {GetPath(configuration)}") | ||
.WithEnvironmentVariables(environmentVariables) | ||
.WithWorkingDirectory(workingDirectory).ExecuteBufferedLoggedAsync(); | ||
|
||
return (result.StandardOutput.Trim(), result.StandardError); | ||
} | ||
|
||
public static string GetPath(string configuration) => | ||
Solution.GetFullPath($"minver-cli/bin/{configuration}/netcoreapp2.1/minver-cli.dll"); | ||
} | ||
} |
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1;net5.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CliWrap" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,17 @@ | ||
#if !NETCOREAPP2_1 | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MinVerTests.Infra | ||
{ | ||
public record Package(string Version, AssemblyVersion AssemblyVersion, FileVersion FileVersion) | ||
{ | ||
public static Package WithVersion(int Major, int Minor, int Patch, IEnumerable<string> PreReleaseIdentifiers = null, int Height = 0, string BuildMetadata = null) | ||
{ | ||
var version = $"{Major}.{Minor}.{Patch}{(!(PreReleaseIdentifiers?.Any() ?? false) ? "" : $"-{string.Join(".", PreReleaseIdentifiers)}")}{(Height == 0 ? "" : $".{Height}")}{(string.IsNullOrEmpty(BuildMetadata) ? "" : $"+{BuildMetadata}")}"; | ||
|
||
return new Package(version, new AssemblyVersion(Major, 0, 0, 0), new FileVersion(Major, Minor, Patch, 0, version)); | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.