2015-11-24 18:48:31 -08:00
// 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 ;
2015-11-24 17:47:33 -08:00
using System.IO ;
2015-12-21 10:42:41 -08:00
using System.Linq ;
2015-11-25 19:46:01 -08:00
using System.Runtime.InteropServices ;
2015-12-30 17:02:59 -08:00
using Microsoft.DotNet.Tools.Test.Utilities ;
2015-12-18 16:39:43 -08:00
using Microsoft.Extensions.PlatformAbstractions ;
2016-01-27 16:20:26 -08:00
using Xunit ;
2016-03-15 11:50:14 -07:00
using System.Diagnostics ;
2015-11-24 17:47:33 -08:00
2015-12-30 17:02:59 -08:00
namespace Microsoft.DotNet.Tests.EndToEnd
2015-11-24 17:47:33 -08:00
{
2015-12-30 17:02:59 -08:00
public class EndToEndTest : TestBase
2015-11-24 17:47:33 -08:00
{
2016-04-01 10:34:04 -07:00
private static readonly string NetCoreAppTfm = "netcoreapp1.0" ;
2015-12-30 17:02:59 -08:00
private static readonly string s_expectedOutput = "Hello World!" + Environment . NewLine ;
private static readonly string s_testdirName = "e2etestroot" ;
2016-01-22 14:05:02 -08:00
private static readonly string s_outputdirName = "test space/bin" ;
2016-02-02 10:04:50 -08:00
2016-01-29 17:37:08 -08:00
private static string RestoredTestProjectDirectory { get ; set ; }
2015-12-30 17:02:59 -08:00
private string Rid { get ; set ; }
2015-11-25 19:46:01 -08:00
private string TestDirectory { get ; set ; }
2015-12-30 17:02:59 -08:00
private string TestProject { get ; set ; }
2015-11-25 19:46:01 -08:00
private string OutputDirectory { get ; set ; }
2015-11-24 17:47:33 -08:00
2016-01-29 17:37:08 -08:00
static EndToEndTest ( )
{
EndToEndTest . SetupStaticTestProject ( ) ;
}
2015-11-24 17:47:33 -08:00
public static void Main ( )
{
Console . WriteLine ( "Dummy Entrypoint." ) ;
}
2016-02-02 10:04:50 -08:00
2015-12-30 17:02:59 -08:00
public EndToEndTest ( )
2015-11-25 19:46:01 -08:00
{
2016-01-29 17:37:08 -08:00
TestInstanceSetup ( ) ;
2015-11-25 19:46:01 -08:00
}
2015-11-24 17:47:33 -08:00
[Fact]
2015-12-30 17:02:59 -08:00
public void TestDotnetBuild ( )
2015-11-24 17:47:33 -08:00
{
2016-04-01 10:34:04 -07:00
var buildCommand = new BuildCommand ( TestProject , output : OutputDirectory , framework : NetCoreAppTfm ) ;
2015-12-30 17:02:59 -08:00
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2015-11-24 17:47:33 -08:00
2016-03-15 11:50:14 -07:00
TestOutputExecutable ( OutputDirectory , buildCommand . GetPortableOutputName ( ) , s_expectedOutput ) ;
2015-11-25 19:46:01 -08:00
}
2015-11-24 17:47:33 -08:00
2015-12-21 10:42:41 -08:00
[Fact]
public void TestDotnetIncrementalBuild ( )
{
// first build
2016-04-01 10:34:04 -07:00
var buildCommand = new BuildCommand ( TestProject , output : OutputDirectory , framework : NetCoreAppTfm ) ;
2015-12-21 10:42:41 -08:00
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2016-03-15 11:50:14 -07:00
TestOutputExecutable ( OutputDirectory , buildCommand . GetPortableOutputName ( ) , s_expectedOutput ) ;
2015-12-21 10:42:41 -08:00
2016-01-21 15:01:21 -08:00
var binariesOutputDirectory = GetCompilationOutputPath ( OutputDirectory , false ) ;
2016-01-27 16:20:26 -08:00
var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles (
2016-01-20 15:41:46 -08:00
binariesOutputDirectory ) ;
2015-12-21 10:42:41 -08:00
// second build; should get skipped (incremental because no inputs changed)
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2016-03-15 11:50:14 -07:00
TestOutputExecutable ( OutputDirectory , buildCommand . GetPortableOutputName ( ) , s_expectedOutput ) ;
2015-12-21 10:42:41 -08:00
2016-01-27 16:20:26 -08:00
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles (
2016-01-20 15:41:46 -08:00
binariesOutputDirectory ) ;
2016-01-27 16:20:26 -08:00
Assert . Equal ( latestWriteTimeFirstBuild , latestWriteTimeUtcSecondBuild ) ;
2015-12-21 10:42:41 -08:00
TouchSourceFileInDirectory ( TestDirectory ) ;
// third build; should get compiled because the source file got touched
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2016-03-15 11:50:14 -07:00
TestOutputExecutable ( OutputDirectory , buildCommand . GetPortableOutputName ( ) , s_expectedOutput ) ;
2015-12-21 10:42:41 -08:00
2016-01-27 16:20:26 -08:00
var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles (
2016-01-20 15:41:46 -08:00
binariesOutputDirectory ) ;
2016-01-27 16:20:26 -08:00
Assert . NotEqual ( latestWriteTimeUtcSecondBuild , latestWriteTimeUtcThirdBuild ) ;
2015-12-21 10:42:41 -08:00
}
2016-03-15 11:50:14 -07:00
[Fact(Skip = "Native compilation isn't shipping in 1.0 and we're moving it out anyway")]
2015-12-30 17:02:59 -08:00
public void TestDotnetBuildNativeRyuJit ( )
2015-11-25 19:46:01 -08:00
{
2016-03-03 18:38:58 +00:00
if ( ! IsNativeCompilationSupported ( ) )
2016-01-05 18:11:38 -08:00
{
2016-02-23 18:04:49 -08:00
return ;
}
2016-04-01 10:34:04 -07:00
var buildCommand = new BuildCommand ( TestProject , output : OutputDirectory , native : true , framework : NetCoreAppTfm ) ;
2015-11-24 17:47:33 -08:00
2015-12-30 17:02:59 -08:00
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2015-11-24 17:47:33 -08:00
2016-01-20 15:41:46 -08:00
TestNativeOutputExecutable ( OutputDirectory , buildCommand . GetOutputExecutableName ( ) , s_expectedOutput ) ;
2015-11-25 19:46:01 -08:00
}
2015-11-24 17:47:33 -08:00
2016-03-15 11:50:14 -07:00
[Fact(Skip = "Native compilation isn't shipping in 1.0 and we're moving it out anyway")]
2015-12-30 17:02:59 -08:00
public void TestDotnetBuildNativeCpp ( )
2015-11-25 19:46:01 -08:00
{
2016-03-03 18:38:58 +00:00
if ( ! IsNativeCompilationSupported ( ) )
{
2016-02-23 18:04:49 -08:00
return ;
}
2016-04-01 10:34:04 -07:00
var buildCommand = new BuildCommand ( TestProject , output : OutputDirectory , native : true , nativeCppMode : true , framework : NetCoreAppTfm ) ;
2015-12-30 17:02:59 -08:00
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2015-11-24 17:47:33 -08:00
2016-01-20 15:41:46 -08:00
TestNativeOutputExecutable ( OutputDirectory , buildCommand . GetOutputExecutableName ( ) , s_expectedOutput ) ;
2015-11-25 19:46:01 -08:00
}
2015-11-24 17:47:33 -08:00
2016-03-15 11:50:14 -07:00
[Fact(Skip = "Native compilation isn't shipping in 1.0 and we're moving it out anyway")]
2015-12-21 10:42:41 -08:00
public void TestDotnetCompileNativeCppIncremental ( )
{
2016-03-03 18:38:58 +00:00
if ( ! IsNativeCompilationSupported ( ) )
{
2016-02-23 18:04:49 -08:00
return ;
}
2015-12-21 10:42:41 -08:00
// first build
2016-04-01 10:34:04 -07:00
var buildCommand = new BuildCommand ( TestProject , output : OutputDirectory , native : true , nativeCppMode : true , framework : NetCoreAppTfm ) ;
2016-01-21 15:01:21 -08:00
var binariesOutputDirectory = GetCompilationOutputPath ( OutputDirectory , false ) ;
2016-01-20 15:41:46 -08:00
2015-12-21 10:42:41 -08:00
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2016-01-20 15:41:46 -08:00
TestNativeOutputExecutable ( OutputDirectory , buildCommand . GetOutputExecutableName ( ) , s_expectedOutput ) ;
2016-01-27 16:20:26 -08:00
var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles ( binariesOutputDirectory ) ;
2015-12-21 10:42:41 -08:00
// second build; should be skipped because nothing changed
buildCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2016-01-20 15:41:46 -08:00
TestNativeOutputExecutable ( OutputDirectory , buildCommand . GetOutputExecutableName ( ) , s_expectedOutput ) ;
2016-01-27 16:20:26 -08:00
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles ( binariesOutputDirectory ) ;
Assert . Equal ( latestWriteTimeUtcFirstBuild , latestWriteTimeUtcSecondBuild ) ;
2015-12-21 10:42:41 -08:00
}
2015-11-25 19:46:01 -08:00
[Fact]
public void TestDotnetRun ( )
{
2016-04-06 15:37:43 -07:00
var restoreCommand = new TestCommand ( "dotnet" ) ;
restoreCommand . Execute ( $"restore {TestProject}" )
. Should ( )
. Pass ( ) ;
2015-12-30 17:02:59 -08:00
var runCommand = new RunCommand ( TestProject ) ;
2015-11-24 17:47:33 -08:00
2015-12-30 17:02:59 -08:00
runCommand . Execute ( )
. Should ( )
. Pass ( ) ;
2015-11-24 17:47:33 -08:00
}
2015-12-18 11:34:55 -08:00
[Fact]
2015-11-25 19:46:01 -08:00
public void TestDotnetPack ( )
{
2015-12-30 17:02:59 -08:00
var packCommand = new PackCommand ( TestDirectory , output : OutputDirectory ) ;
2015-11-25 19:46:01 -08:00
2015-12-30 17:02:59 -08:00
packCommand . Execute ( )
. Should ( )
. Pass ( ) ;
2015-11-25 19:46:01 -08:00
}
[Fact]
public void TestDotnetPublish ( )
{
2015-12-30 17:02:59 -08:00
var publishCommand = new PublishCommand ( TestProject , output : OutputDirectory ) ;
publishCommand . Execute ( ) . Should ( ) . Pass ( ) ;
2015-11-25 19:46:01 -08:00
2016-03-15 11:50:14 -07:00
TestExecutable ( OutputDirectory , publishCommand . GetPortableOutputName ( ) , s_expectedOutput ) ;
2015-11-25 19:46:01 -08:00
}
2016-02-04 12:41:50 -08:00
[Fact]
public void TestDotnetHelp ( )
{
var helpCommand = new HelpCommand ( ) ;
helpCommand . Execute ( ) . Should ( ) . Pass ( ) ;
}
[Fact]
public void TestDotnetHelpBuild ( )
{
var helpCommand = new HelpCommand ( ) ;
helpCommand . Execute ( "build" ) . Should ( ) . Pass ( ) ;
}
2016-01-29 17:37:08 -08:00
private void TestInstanceSetup ( )
2015-11-25 19:46:01 -08:00
{
2015-12-30 17:02:59 -08:00
var root = Temp . CreateDirectory ( ) ;
2016-01-29 17:37:08 -08:00
var testInstanceDir = root . CopyDirectory ( RestoredTestProjectDirectory ) ;
TestDirectory = testInstanceDir . Path ;
2015-12-30 17:02:59 -08:00
TestProject = Path . Combine ( TestDirectory , "project.json" ) ;
OutputDirectory = Path . Combine ( TestDirectory , s_outputdirName ) ;
2015-11-25 19:46:01 -08:00
2016-01-29 17:37:08 -08:00
Rid = PlatformServices . Default . Runtime . GetLegacyRestoreRuntimeIdentifier ( ) ;
2015-12-30 17:02:59 -08:00
}
2015-11-25 19:46:01 -08:00
2016-01-29 17:37:08 -08:00
private static void SetupStaticTestProject ( )
2015-12-30 17:02:59 -08:00
{
2016-01-29 17:37:08 -08:00
RestoredTestProjectDirectory = Path . Combine ( AppContext . BaseDirectory , "bin" , s_testdirName ) ;
// Ignore Delete Failure
try
{
Directory . Delete ( RestoredTestProjectDirectory , true ) ;
}
2016-02-02 10:04:50 -08:00
catch ( Exception ) { }
2016-01-29 17:37:08 -08:00
Directory . CreateDirectory ( RestoredTestProjectDirectory ) ;
2016-04-06 14:34:39 -07:00
WriteNuGetConfig ( RestoredTestProjectDirectory ) ;
2016-01-29 17:37:08 -08:00
2015-12-30 17:02:59 -08:00
var currentDirectory = Directory . GetCurrentDirectory ( ) ;
2016-01-29 17:37:08 -08:00
Directory . SetCurrentDirectory ( RestoredTestProjectDirectory ) ;
2015-11-25 19:46:01 -08:00
2015-12-30 17:02:59 -08:00
new NewCommand ( ) . Execute ( ) . Should ( ) . Pass ( ) ;
new RestoreCommand ( ) . Execute ( "--quiet" ) . Should ( ) . Pass ( ) ;
Directory . SetCurrentDirectory ( currentDirectory ) ;
2015-11-25 19:46:01 -08:00
}
2016-03-07 20:23:41 -05:00
private bool IsNativeCompilationSupported ( )
2016-01-05 18:11:38 -08:00
{
2016-03-07 20:23:41 -05:00
bool isSupported = true ;
var platform = PlatformServices . Default . Runtime . OperatingSystem . ToLower ( ) ;
switch ( platform )
2016-01-05 18:11:38 -08:00
{
2016-03-07 20:23:41 -05:00
case "centos" :
case "rhel" :
Console . WriteLine ( "Skipping native compilation tests on CentOS/RHEL - https://github.com/dotnet/cli/issues/453" ) ;
isSupported = false ;
break ;
2016-03-03 18:38:58 +00:00
case "debian" :
Console . WriteLine ( "Skipping native compilation tests on Debian - https://github.com/dotnet/cli/issues/1666" ) ;
isSupported = false ;
break ;
2016-03-07 20:23:41 -05:00
case "windows" :
Console . WriteLine ( "Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550" ) ;
isSupported = RuntimeInformation . ProcessArchitecture ! = Architecture . X86 ;
break ;
default :
break ;
2016-01-05 18:11:38 -08:00
}
2016-03-07 20:23:41 -05:00
return isSupported ;
2016-02-23 18:04:49 -08:00
}
2016-04-06 14:34:39 -07:00
// Todo: this is a hack until corefx is on nuget.org remove this After RC 2 Release
private static void WriteNuGetConfig ( string directory )
{
var contents = @"<?xml version=""1.0"" encoding=""utf-8" "?>
< configuration >
< packageSources >
< ! - - To inherit the global NuGet package sources remove the < clear / > line below - - >
< clear / >
< add key = "" dotnet - core "" value = "" https : //dotnet.myget.org/F/dotnet-core/api/v3/index.json"" />
< add key = "" api . nuget . org "" value = "" https : //api.nuget.org/v3/index.json"" />
< / packageSources >
< / configuration > ";
var path = Path . Combine ( directory , "NuGet.config" ) ;
File . WriteAllText ( path , contents ) ;
}
2016-01-27 16:20:26 -08:00
private static DateTime GetLastWriteTimeUtcOfDirectoryFiles ( string outputDirectory )
2015-12-21 10:42:41 -08:00
{
2016-01-27 16:20:26 -08:00
return Directory . EnumerateFiles ( outputDirectory ) . Max ( f = > File . GetLastWriteTimeUtc ( f ) ) ;
2015-12-21 10:42:41 -08:00
}
private static void TouchSourceFileInDirectory ( string directory )
{
var csFile = Directory . EnumerateFiles ( directory ) . First ( f = > Path . GetExtension ( f ) . Equals ( ".cs" ) ) ;
File . SetLastWriteTimeUtc ( csFile , DateTime . UtcNow ) ;
}
2015-11-24 17:47:33 -08:00
}
2016-02-02 10:04:50 -08:00
}