Move PackagedCommands to TestAssets.

Convert package-command-test.ps1 to an XUnit test.
This commit is contained in:
Eric Erhardt 2016-02-10 13:16:23 -06:00
parent b209f98fd1
commit 5d04ca1fe3
15 changed files with 146 additions and 87 deletions

View file

@ -61,6 +61,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Files", "s
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestAssets", "TestAssets", "{82BD2E61-326D-4EA4-A1C1-93A565573C81}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet.Tests", "test\dotnet.Tests\dotnet.Tests.xproj", "{CB710268-4A82-48E4-9531-FAF1C8F78F4B}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Cli.Utils.Tests", "test\Microsoft.DotNet.Cli.Utils.Tests\Microsoft.DotNet.Cli.Utils.Tests.xproj", "{09C52F96-EFDD-4448-95EC-6D362DD60BAA}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
@ -429,6 +431,22 @@ Global
{D521DD9F-0614-4929-93B4-D8FA5682C174}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{D521DD9F-0614-4929-93B4-D8FA5682C174}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{D521DD9F-0614-4929-93B4-D8FA5682C174}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|x64.ActiveCfg = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|x64.Build.0 = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|Any CPU.Build.0 = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|x64.ActiveCfg = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|x64.Build.0 = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{09C52F96-EFDD-4448-95EC-6D362DD60BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09C52F96-EFDD-4448-95EC-6D362DD60BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09C52F96-EFDD-4448-95EC-6D362DD60BAA}.Debug|x64.ActiveCfg = Debug|Any CPU
@ -488,6 +506,7 @@ Global
{386D412C-003C-47B1-8258-0E35865CB7C4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{11C77123-E4DA-499F-8900-80C88C2C69F2} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{D521DD9F-0614-4929-93B4-D8FA5682C174} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{CB710268-4A82-48E4-9531-FAF1C8F78F4B} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{09C52F96-EFDD-4448-95EC-6D362DD60BAA} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection

View file

@ -1,4 +1,5 @@
EndToEnd
dotnet.Tests
dotnet-publish.Tests
dotnet-compile.Tests
dotnet-build.Tests

1 EndToEnd
2 dotnet.Tests
3 dotnet-publish.Tests
4 dotnet-compile.Tests
5 dotnet-build.Tests

View file

@ -1,2 +1 @@
argument-forwarding-tests
package-command-test
1 argument-forwarding-tests
package-command-test

View file

@ -1,34 +0,0 @@
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
. "$PSScriptRoot\..\common\_common.ps1"
#compile apps
dir "$RepoRoot\test\PackagedCommands\Consumers" | where {$_.PsIsContainer} | where {$_.Name.Contains("Direct")} |
foreach {
pushd "$RepoRoot\test\PackagedCommands\Consumers\$_"
dotnet build
popd
}
#run test
dir "$RepoRoot\test\PackagedCommands\Consumers" | where {$_.PsIsContainer} | where {$_.Name.Contains("AppWith")} |
foreach {
$testName = "test\PackagedCommands\Consumers\$_"
pushd "$RepoRoot\$testName"
$outputArray = dotnet hello | Out-String
$output = [string]::Join('\n', $outputArray).Trim("`r", "`n")
if ($output -ne "hello") {
error "Test Failed: $testName\dotnet hello"
error " printed $output"
Exit 1
}
info "Test passed: $testName"
popd
}
Exit 0

View file

@ -1,48 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
set -e
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "$DIR/../common/_common.sh"
#compile tests with direct dependencies
for test in $(ls -l "$REPOROOT/test/PackagedCommands/Consumers" | grep ^d | awk '{print $9}' | grep "Direct")
do
pushd "$REPOROOT/test/PackagedCommands/Consumers/$test"
dotnet build
popd
done
#run test
for test in $(ls -l "$REPOROOT/test/PackagedCommands/Consumers" | grep ^d | awk '{print $9}' | grep "AppWith")
do
testName="test/PackagedCommands/Consumers/$test"
pushd "$REPOROOT/$testName"
output=$(dotnet hello)
if [ "$output" == "Hello" ] ;
then
echo "Test Passed: $testName"
else
error "Test Failed: $testName/dotnet hello"
error " printed $output"
exit 1
fi
popd
done

View file

@ -6,7 +6,6 @@ using System;
using System.Diagnostics;
using System.IO;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class TestCommand
@ -40,11 +39,15 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
public virtual CommandResult ExecuteWithCapturedOutput(string args = "")
{
var commandPath = _command;
if (!Path.IsPathRooted(_command))
{
_command = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
}
Console.WriteLine($"Executing (Captured Output) - {_command} {args}");
var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
var stdOut = new StreamForwarder();
var stdErr = new StreamForwarder();

View file

@ -0,0 +1,71 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tests
{
public class PackagedCommandTests : TestBase
{
private readonly string _testProjectsRoot;
public PackagedCommandTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
[Theory]
[InlineData("AppWithDirectAndToolDependency")]
[InlineData("AppWithDirectDependency")]
[InlineData("AppWithToolDependency")]
public void TestPackagedCommandDependency(string appName)
{
string appDirectory = Path.Combine(_testProjectsRoot, appName);
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
.Should()
.Pass();
var currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(appDirectory);
try
{
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
result.Should().HaveStdOut("Hello" + Environment.NewLine);
result.Should().NotHaveStdErr();
result.Should().Pass();
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
}
class HelloCommand : TestCommand
{
public HelloCommand()
: base("dotnet")
{
}
public override CommandResult Execute(string args = "")
{
args = $"hello {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"hello {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}
}

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>cb710268-4a82-48e4-9531-faf1c8f78f4b</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,30 @@
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23810",
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": {
"target": "project",
"type": "build"
},
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-dev-48273-16"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
},
"content": [
"../../TestAssets/TestProjects/AppWithDirectAndToolDependency/**/*",
"../../TestAssets/TestProjects/AppWithDirectDependency/**/*",
"../../TestAssets/TestProjects/AppWithToolDependency/**/*"
],
"testRunner": "xunit"
}