This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes incorrect dependency in non-lib packages (#284)
* Stopped NETStandard.Library reference from being added to target project * Set up integration tests on targets packages * Removed local NuGet feed copy as requested * Fixed generated integration test projects failing due to not being in a repository
- Loading branch information
Showing
14 changed files
with
324 additions
and
5 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
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
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
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
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,93 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Tests.Helpers | ||
{ | ||
public sealed class CsprojFixture : IDisposable | ||
{ | ||
private readonly TempDirectory tempDir; | ||
private const string CsprojName = "test.csproj"; | ||
private const string PackagesCache = "packages"; | ||
|
||
public CsprojFixture(string[] csprojLines) | ||
{ | ||
tempDir = new TempDirectory(); | ||
|
||
File.WriteAllLines(Path.Combine(tempDir, CsprojName), csprojLines); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
tempDir.Dispose(); | ||
} | ||
|
||
public void AddFile(string path, string[] lines) | ||
{ | ||
File.WriteAllLines(Path.Combine(tempDir, path), lines); | ||
} | ||
|
||
public void DotnetRestore(string packageSource) | ||
{ | ||
RunProcess(tempDir, "dotnet", $"restore --no-cache --packages \"{PackagesCache}\" --source \"{Path.GetFullPath(packageSource)}\""); | ||
} | ||
|
||
public void DotnetMSBuild() | ||
{ | ||
RunProcess(tempDir, "dotnet", "msbuild"); | ||
} | ||
|
||
private static void RunProcess(string workingDirectory, string fileName, string arguments) | ||
{ | ||
var result = ProcessUtils.Run(new ProcessStartInfo | ||
{ | ||
WorkingDirectory = workingDirectory, | ||
FileName = "dotnet", | ||
Arguments = arguments | ||
}); | ||
|
||
var hasErrorOutput = result.StandardStreamData.Any(_ => _.IsError); | ||
if (hasErrorOutput || result.ExitCode != 0) | ||
{ | ||
var message = new StringBuilder(fileName).Append(' ').Append(arguments).Append(" exited with code ").Append(result.ExitCode); | ||
|
||
if (hasErrorOutput) message.Append(" and wrote to stderr"); | ||
|
||
if (result.StandardStreamData.Length == 0) | ||
{ | ||
message.Append(" and no output."); | ||
} | ||
else | ||
{ | ||
message.Append(':'); | ||
foreach (var data in result.StandardStreamData) | ||
message.AppendLine().Append(data); | ||
} | ||
|
||
throw new Exception(message.ToString()); | ||
} | ||
} | ||
|
||
public string[] GetFiles(string relativePath, SearchOption searchOption) | ||
{ | ||
return GetFiles(relativePath, null, searchOption); | ||
} | ||
|
||
public string[] GetFiles(string relativePath, string searchPattern, SearchOption searchOption) | ||
{ | ||
if (relativePath != null && Path.IsPathRooted(relativePath)) | ||
throw new ArgumentException("Path must be relative.", nameof(relativePath)); | ||
|
||
var files = Directory.GetFiles(Path.Combine(tempDir, relativePath), searchPattern ?? "*", searchOption); | ||
|
||
var tempDirPathLength = tempDir.Path.Length + 1; | ||
|
||
for (var i = 0; i < files.Length; i++) | ||
files[i] = files[i].Substring(tempDirPathLength); | ||
|
||
return files; | ||
} | ||
} | ||
} |
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,116 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Tests.Helpers | ||
{ | ||
public static class ProcessUtils | ||
{ | ||
public static ProcessResult Run(ProcessStartInfo startInfo) | ||
{ | ||
startInfo.UseShellExecute = false; | ||
startInfo.RedirectStandardOutput = true; | ||
startInfo.RedirectStandardError = true; | ||
startInfo.CreateNoWindow = true; | ||
|
||
using (var process = new Process { StartInfo = startInfo }) | ||
{ | ||
var standardStreamData = new List<StandardStreamData>(); | ||
var currentData = new StringBuilder(); | ||
var currentDataIsError = false; | ||
|
||
process.OutputDataReceived += (sender, e) => | ||
{ | ||
if (e.Data == null) return; | ||
if (currentDataIsError) | ||
{ | ||
if (currentData.Length != 0) | ||
standardStreamData.Add(new StandardStreamData(currentDataIsError, currentData.ToString())); | ||
currentData.Clear(); | ||
currentDataIsError = false; | ||
} | ||
currentData.AppendLine(e.Data); | ||
}; | ||
process.ErrorDataReceived += (sender, e) => | ||
{ | ||
if (e.Data == null) return; | ||
if (!currentDataIsError) | ||
{ | ||
if (currentData.Length != 0) | ||
standardStreamData.Add(new StandardStreamData(currentDataIsError, currentData.ToString())); | ||
currentData.Clear(); | ||
currentDataIsError = true; | ||
} | ||
currentData.AppendLine(e.Data); | ||
}; | ||
|
||
process.Start(); | ||
process.BeginOutputReadLine(); | ||
process.BeginErrorReadLine(); | ||
process.WaitForExit(); | ||
|
||
if (currentData.Length != 0) | ||
standardStreamData.Add(new StandardStreamData(currentDataIsError, currentData.ToString())); | ||
|
||
return new ProcessResult(process.ExitCode, standardStreamData.ToArray()); | ||
} | ||
} | ||
|
||
[DebuggerDisplay("{ToString(),nq}")] | ||
public struct ProcessResult | ||
{ | ||
public ProcessResult(int exitCode, StandardStreamData[] standardStreamData) | ||
{ | ||
ExitCode = exitCode; | ||
StandardStreamData = standardStreamData; | ||
} | ||
|
||
public int ExitCode { get; } | ||
public StandardStreamData[] StandardStreamData { get; } | ||
|
||
public override string ToString() => ToString(true); | ||
|
||
/// <param name="showStreamSource">If true, appends "[stdout] " or "[stderr] " to the beginning of each line.</param> | ||
public string ToString(bool showStreamSource) | ||
{ | ||
var r = new StringBuilder("Exit code ").Append(ExitCode); | ||
|
||
if (StandardStreamData.Length != 0) r.AppendLine(); | ||
|
||
foreach (var data in StandardStreamData) | ||
{ | ||
if (showStreamSource) | ||
{ | ||
var lines = data.Data.Split(new[] { Environment.NewLine }, StringSplitOptions.None); | ||
|
||
// StandardStreamData.Data always ends with a blank line, so skip that | ||
for (var i = 0; i < lines.Length - 1; i++) | ||
r.Append(data.IsError ? "[stderr] " : "[stdout] ").AppendLine(lines[i]); | ||
} | ||
else | ||
{ | ||
r.Append(data.Data); | ||
} | ||
} | ||
|
||
return r.ToString(); | ||
} | ||
} | ||
|
||
[DebuggerDisplay("{ToString(),nq}")] | ||
public struct StandardStreamData | ||
{ | ||
public StandardStreamData(bool isError, string data) | ||
{ | ||
IsError = isError; | ||
Data = data; | ||
} | ||
|
||
public bool IsError { get; } | ||
public string Data { get; } | ||
|
||
public override string ToString() => (IsError ? "[stderr] " : "[stdout] ") + Data; | ||
} | ||
} | ||
} |
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,34 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace Tests.Helpers | ||
{ | ||
[DebuggerDisplay("{ToString(),nq}")] | ||
public sealed class TempDirectory : IDisposable | ||
{ | ||
public TempDirectory() : this(System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName())) | ||
{ | ||
} | ||
|
||
public TempDirectory(string path) | ||
{ | ||
Directory.CreateDirectory(path); | ||
this.path = path; | ||
} | ||
|
||
private string path; | ||
public string Path => path; | ||
|
||
public static implicit operator string(TempDirectory tempFile) => tempFile.path; | ||
|
||
public override string ToString() => path; | ||
|
||
public void Dispose() | ||
{ | ||
var path = Interlocked.Exchange(ref this.path, null); | ||
if (path != null) Directory.Delete(path, recursive: true); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Tests/Integration/When_package_without_lib_is_installed.cs
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,54 @@ | ||
using System; | ||
using System.IO; | ||
using Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace Tests.Integration | ||
{ | ||
public static class When_package_without_lib_is_installed | ||
{ | ||
[Theory] | ||
[InlineData("SourceLink.Create.BitBucket")] | ||
[InlineData("SourceLink.Create.BitBucketServer")] | ||
[InlineData("SourceLink.Create.CommandLine")] | ||
[InlineData("SourceLink.Create.GitHub")] | ||
[InlineData("SourceLink.Create.GitLab")] | ||
[InlineData("SourceLink.Embed.AllSourceFiles")] | ||
[InlineData("SourceLink.Embed.PaketFiles")] | ||
[InlineData("SourceLink.Test")] | ||
public static void Should_not_reference_additional_libraries(string packageName) | ||
{ | ||
var packageSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Integration"); | ||
|
||
var packageFile = Assert.Single(Directory.GetFiles(packageSource, $"{packageName}.*.nupkg")); | ||
var packageVersion = Path.GetFileNameWithoutExtension(packageFile).Substring(packageName.Length + 1); | ||
|
||
const string targetFramework = "net462"; | ||
using (var fixture = new CsprojFixture(new[] | ||
{ | ||
"<Project Sdk=\"Microsoft.Net.Sdk\">", | ||
" <PropertyGroup>", | ||
$" <TargetFramework>{targetFramework}</TargetFramework>", | ||
" </PropertyGroup>", | ||
" <ItemGroup>", | ||
$" <PackageReference Include=\"{packageName}\" Version=\"{packageVersion}\" ExcludeAssets=\"build\" PrivateAssets=\"all\" />", | ||
" </ItemGroup>", | ||
"</Project>" | ||
})) | ||
{ | ||
fixture.AddFile("test.cs", Array.Empty<string>()); | ||
|
||
fixture.DotnetRestore(packageSource); | ||
fixture.DotnetMSBuild(); | ||
|
||
Assert.Equal( | ||
new[] | ||
{ | ||
$@"bin\Debug\{targetFramework}\test.dll", | ||
$@"bin\Debug\{targetFramework}\test.pdb" | ||
}, | ||
fixture.GetFiles($@"bin\Debug\{targetFramework}", SearchOption.AllDirectories)); | ||
} | ||
} | ||
} | ||
} |
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