2016-01-08 11:03:14 -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.
2016-01-20 15:41:46 -08:00
using System ;
2016-01-08 11:03:14 -08:00
using System.IO ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
2016-01-28 16:16:50 -08:00
namespace Microsoft.DotNet.Tools.Compiler.Tests
2016-01-08 11:03:14 -08:00
{
public class CompilerTests : TestBase
{
2016-01-28 16:16:50 -08:00
private readonly string _testProjectsRoot ;
public CompilerTests ( )
{
2016-02-05 17:43:50 -06:00
_testProjectsRoot = Path . Combine ( AppContext . BaseDirectory , "TestAssets" , "TestProjects" ) ;
2016-01-28 16:16:50 -08:00
}
2016-01-08 11:03:14 -08:00
[Fact]
public void XmlDocumentationFileIsGenerated ( )
{
// create unique directories in the 'temp' folder
var root = Temp . CreateDirectory ( ) ;
2016-01-12 16:36:31 -08:00
root . CopyFile ( Path . Combine ( _testProjectsRoot , "global.json" ) ) ;
2016-01-08 11:03:14 -08:00
var testLibDir = root . CreateDirectory ( "TestLibrary" ) ;
2016-01-28 16:16:50 -08:00
var sourceTestLibDir = Path . Combine ( _testProjectsRoot , "TestLibrary" ) ;
2016-01-08 11:03:14 -08:00
2016-01-28 16:16:50 -08:00
CopyProjectToTempDir ( sourceTestLibDir , testLibDir ) ;
2016-01-08 11:03:14 -08:00
// run compile
var outputDir = Path . Combine ( testLibDir . Path , "bin" ) ;
var testProject = GetProjectPath ( testLibDir ) ;
2016-02-03 10:57:25 -08:00
var buildCommand = new BuildCommand ( testProject , output : outputDir , framework : DefaultFramework ) ;
2016-01-08 11:03:14 -08:00
var result = buildCommand . ExecuteWithCapturedOutput ( ) ;
result . Should ( ) . Pass ( ) ;
// verify the output xml file
2016-02-03 10:57:25 -08:00
var outputXml = Path . Combine ( outputDir , "Debug" , DefaultFramework , "TestLibrary.xml" ) ;
2016-01-20 15:41:46 -08:00
Console . WriteLine ( "OUTPUT XML PATH: " + outputXml ) ;
2016-01-08 11:03:14 -08:00
Assert . True ( File . Exists ( outputXml ) ) ;
Assert . Contains ( "Gets the message from the helper" , File . ReadAllText ( outputXml ) ) ;
}
2016-02-03 10:57:25 -08:00
2016-01-18 15:14:19 -08:00
[Fact]
public void LibraryWithAnalyzer ( )
2016-01-28 16:16:50 -08:00
{
2016-01-18 15:14:19 -08:00
var root = Temp . CreateDirectory ( ) ;
var testLibDir = root . CreateDirectory ( "TestLibraryWithAnalyzer" ) ;
2016-01-28 16:16:50 -08:00
var sourceTestLibDir = Path . Combine ( _testProjectsRoot , "TestLibraryWithAnalyzer" ) ;
CopyProjectToTempDir ( sourceTestLibDir , testLibDir ) ;
2016-01-18 15:14:19 -08:00
// run compile
var outputDir = Path . Combine ( testLibDir . Path , "bin" ) ;
var testProject = GetProjectPath ( testLibDir ) ;
2016-02-03 10:57:25 -08:00
var buildCmd = new BuildCommand ( testProject , output : outputDir , framework : DefaultFramework ) ;
2016-01-18 15:14:19 -08:00
var result = buildCmd . ExecuteWithCapturedOutput ( ) ;
result . Should ( ) . Pass ( ) ;
2016-02-08 18:01:27 -08:00
Assert . Contains ( "CA1018" , result . StdErr ) ;
2016-01-18 15:14:19 -08:00
}
2016-01-08 11:03:14 -08:00
private void CopyProjectToTempDir ( string projectDir , TempDirectory tempDir )
{
// copy all the files to temp dir
foreach ( var file in Directory . EnumerateFiles ( projectDir ) )
{
tempDir . CopyFile ( file ) ;
}
}
private string GetProjectPath ( TempDirectory projectDir )
{
return Path . Combine ( projectDir . Path , "project.json" ) ;
}
}
2016-01-13 15:56:02 -08:00
}