Skip to content

Commit

Permalink
Add a new ITs for a multi-target solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaury Levé committed Nov 23, 2017
1 parent 1951d0c commit 092e19f
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</organization>

<properties>
<scannerMsbuild.version>3.0.2.656</scannerMsbuild.version>
<scannerMsbuild.version>3.1.0.730</scannerMsbuild.version>
<surefire.argLine>-server</surefire.argLine>
</properties>

Expand Down
25 changes: 25 additions & 0 deletions its/projects/MultiTargetConsoleApp/MultiTargetConsoleApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiTargetConsoleApp", "MultiTargetConsoleApp\MultiTargetConsoleApp.csproj", "{9D7FB932-3B1E-446D-9D34-A63410458B88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D7FB932-3B1E-446D-9D34-A63410458B88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D7FB932-3B1E-446D-9D34-A63410458B88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D7FB932-3B1E-446D-9D34-A63410458B88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D7FB932-3B1E-446D-9D34-A63410458B88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {13A8E4AE-D696-4779-8C1B-6AEF70A70004}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net46;net40</TargetFrameworks>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace MultiTargetConsoleApp
{
public static class Program
{
public static void Main(string[] args)
{
int unusedVar = 42;

Console.WriteLine("Hello World!");
#if NETCOREAPP2_0
Console.WriteLine("\tfrom .Net Core 2.0"); // FIXME: .Net Core 2
#elif NET46
Console.WriteLine("\tfrom .Net Fwk 4.6"); // FIXME: .Net fwk 4.6
#else
Console.WriteLine("\tfrom other"); // FIXME: Other
#endif

Console.ReadKey();
}
}
}
70 changes: 70 additions & 0 deletions its/src/test/java/com/sonar/it/csharp/MultiTargetAppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* SonarSource :: C# :: ITs :: Plugin
* Copyright (C) 2011-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.sonar.it.csharp;

import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.ws.Issues;

import com.sonar.orchestrator.Orchestrator;

import java.nio.file.Path;
import java.util.List;

import static com.sonar.it.csharp.Tests.getComponent;
import static com.sonar.it.csharp.Tests.getIssues;
import static org.assertj.core.api.Assertions.assertThat;

public class MultiTargetAppTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();

@ClassRule
public static final Orchestrator orchestrator = Tests.ORCHESTRATOR;

@Before
public void init() throws Exception {
orchestrator.resetData();
}

@Test
public void should_analyze_multitarget_project() throws Exception {
Path projectDir = Tests.projectDir(temp, "MultiTargetConsoleApp");
orchestrator.executeBuild(Tests.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("MultiTargetConsoleApp")
.setProjectName("MultiTargetConsoleApp")
.setProjectVersion("1.0"));

Tests.runNuGet(orchestrator, projectDir, "restore");
Tests.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

orchestrator.executeBuild(Tests.newScanner(projectDir)
.addArgument("end"));

assertThat(getComponent("MultiTargetConsoleApp:MultiTargetConsoleApp:9D7FB932-3B1E-446D-9D34-A63410458B88:Program.cs")).isNotNull();

List<Issues.Issue> issues = getIssues("MultiTargetConsoleApp:MultiTargetConsoleApp:9D7FB932-3B1E-446D-9D34-A63410458B88:Program.cs");
assertThat(issues).hasSize(4);
}
}
21 changes: 21 additions & 0 deletions its/src/test/java/com/sonar/it/csharp/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
public class Tests {

private static final String MSBUILD_PATH = "msbuild.path";
private static final String NUGET_PATH = "nuget.path";

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
Expand All @@ -87,6 +88,26 @@ public static Build<ScannerForMSBuild> newScanner(Path projectDir) {
.setScannerVersion(System.getProperty("scannerMsbuild.version"));
}

public static void runNuGet(Orchestrator orch, Path projectDir, String... arguments) {
Path nugetPath = getNuGetPath(orch);

int r = CommandExecutor.create().execute(Command.create(nugetPath.toString())
.addArguments(arguments)
.setDirectory(projectDir.toFile()), 60 * 1000);
assertThat(r).isEqualTo(0);
}

private static Path getNuGetPath(Orchestrator orch) {
String toolsFolder = Paths.get("tools").resolve("nuget-4.4.1.exe").toAbsolutePath().toString();
String nugetPathStr = orch.getConfiguration().getString(NUGET_PATH, toolsFolder);
Path nugetPath = Paths.get(nugetPathStr).toAbsolutePath();
if (!Files.exists(nugetPath)) {
throw new IllegalStateException("Unable to find NuGet at '" + nugetPath.toString() +
"'. Please configure property '" + NUGET_PATH + "'");
}
return nugetPath;
}

public static void runMSBuild(Orchestrator orch, Path projectDir, String... arguments) {
Path msBuildPath = getMsBuildPath(orch);

Expand Down

0 comments on commit 092e19f

Please sign in to comment.