-
Notifications
You must be signed in to change notification settings - Fork 1
/
Common.Targets
107 lines (94 loc) · 5.08 KB
/
Common.Targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="utf-8"?>
<!--
==================================================
Common targets library used by other files
==================================================
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<CommonTargetsLoaded>true</CommonTargetsLoaded>
</PropertyGroup>
<!-- Import 3rd party targets -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" Condition="$(MSBuildCommunityTasksLib) == ''"/>
<Import Project="$(MSBuildExtensionsPath)\Four2n.Commons\Four2n.Commons.Targets" Condition="$(Four2nCommonsTargetsIsLoaded) == ''" />
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCoverExplorer" AssemblyFile="$(NCoverExplorerTaskAssembly)"/>
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCover" AssemblyFile="$(NCoverExplorerTaskAssembly)"/>
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NUnitProject" AssemblyFile="$(NCoverExplorerTaskAssembly)"/>
<Target Name="Test" DependsOnTargets="Build;GetTestAssemblies" >
<CallTarget Targets="InternalNUnit" />
</Target>
<Target Name="Coverage" DependsOnTargets="Build;_GetTestedAssemblies;_CreateCoverageResutsFolder" >
<NCover
ToolPath="$(NCoverPath)"
CommandLineExe="$(NUnitConsole)"
CommandLineArgs="@(TestAssemblies, ' ') $(TestCommandParameters)"
CoverageFile="$(CoverageXmlFile)"
LogLevel="Normal"
LogFile="$(CoverageLogFile)"
AssemblyList="@(TestedAssemblies)"
ContinueOnError="true"
/>
<Message Text="$(CoverageResultsPath) $(CoverageXmlReportFile) $(CoverageHtmlReportFile) ssss" />
<CreateItem Include="$(CoverageXmlFile)" >
<Output ItemName="CoverageXmlFiles" TaskParameter="Include" />
</CreateItem>
<Message Text="@(CoverageXmlFiles)"/>
<NCoverExplorer
ToolPath="$(NCoverExplorerPath)"
ProjectName="TestProject"
ReportType="ModuleClassSummary"
OutputDir="$(CoverageResultsPath)"
XmlReportName="CoverageSummary.xml"
HtmlReportName="CoverageSummary.html"
ShowExcluded="True"
SatisfactoryCoverage="75"
CoverageFiles="@(CoverageXmlFiles)"
Exclusions="Assembly=*.Tests;Namespace=*.Tests*"
ModuleThresholds="@(ModuleThreshold)"
/>
<Exec Command="$(InternetBrowser) $(CoverageResultsPath)\CoverageSummary.html" />
</Target>
<Target Name="GetTestAssemblies" DependsOnTargets="Build">
<CreateItem Include="$(TargetDir)$(TargetName)*.dll" >
<Output ItemName="Assemblies" TaskParameter="Include"/>
</CreateItem>
<RegexMatch Input="@(Assemblies)" Expression="$(TestDetectionExpression)[\.]dll$">
<Output TaskParameter="Output" ItemName="TestAssemblies"/>
</RegexMatch>
</Target>
<Target Name="_GetTestedAssemblies" DependsOnTargets="GetTestAssemblies" Condition="$(TestedAssemblies) == ''">
<!-- Calculate tested assmeblies from test unit naming convention-->
<RegexReplace Input="$(AssemblyName)" Expression="$(TestedAssembliesReplaceExpression)" Replacement="">
<Output TaskParameter="Output" ItemName="TestedAssemblies"/>
</RegexReplace>
</Target>
<!--
Internal tasks
-->
<Target Name="InternalNUnit" DependsOnTargets="_CreateTestResutsFolder" Condition=" '@(TestAssemblies)' != '' ">
<Exec Command="$(NUnitConsole) @(TestAssemblies, ' ') $(TestCommandParameters)" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="NUnitExitCode"/>
</Exec>
<Xslt
Inputs="$(TestResultXmlFile)"
Xsl="$(ToolsPath)\nunit\xslt\Summary.xslt"
Output="$(TestResultTxtFile)" ContinueOnError="false"/>
<ReadLinesFromFile File="$(TestResultTxtFile)"
Condition="'$(NUnitExitCode)' != '0'">
<Output TaskParameter="Lines" ItemName="NUnitSummaryLines"/>
</ReadLinesFromFile>
<Merge Mode="TextLine"
SourceFiles="$(TestResultTxtFile);$(TestOutputFile)"
DestinationFile="$(TestSummaryFile)" />
<Message Condition="$(NUnitExitCode) == '0'" Text="@(NUnitSummaryLines, '$(NEW_LINE)')" />
<Message Condition="$(NUnitExitCode) != '0'" Text="@(NUnitSummaryLines, '$(NEW_LINE)')" Importance="High" />
<Exec Command="notepad.exe $(TestSummaryFile)" Condition="$(NUnitExitCode) != '0'"/>
<Error Condition="$(NUnitExitCode) != '0'" Text="Some tests has $(NUnitExitCode) failed tests." />
</Target>
<Target Name="_CreateTestResutsFolder" Condition="$(TestResultsPath) != '' And !Exists('$(TestResultsPath)')">
<MakeDir Directories="$(TestResultsPath)"/>
</Target>
<Target Name="_CreateCoverageResutsFolder" Condition="$(CoverageResultsPath) != '' And !Exists('$(CoverageResultsPath)')">
<MakeDir Directories="$(CoverageResultsPath)"/>
</Target>
</Project>