Skip to content

Commit 08f347a

Browse files
authored
add more tests for p2p, multitargeting, conf (#22)
test `--project-refs` test `-gp` with Debug/Release configurations test multi targeting: * fsc args * test `--get-property` generate tests results but disable upload to appveyor
1 parent 43682ef commit 08f347a

File tree

14 files changed

+297
-19
lines changed

14 files changed

+297
-19
lines changed

appveyor.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ artifacts:
1818
- path: bin\nupkg\*.nupkg
1919
name: nupkgs
2020
type: NuGetPackage
21+
22+
on_finish:
23+
- ps: >-
24+
$wc = New-Object 'System.Net.WebClient';
25+
$testResults = @(
26+
# '.\bin\test_results\TestResults.xml'
27+
)
28+
- ps: >-
29+
Foreach ($path in $testResults) {
30+
If (Test-Path $path) {
31+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit3/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $path))
32+
}
33+
}

test/dotnet-proj-info.Tests/Program.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ let main argv =
1515
Environment.SetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL", "1")
1616
Environment.SetEnvironmentVariable("MSBuildExtensionsPath", null)
1717

18-
Tests.runTestsWithArgs defaultConfig (args |> Array.ofList) (DotnetProjInfo.Tests.tests pkgUnderTestVersion)
18+
let resultsPath = IO.Path.Combine(__SOURCE_DIRECTORY__,"..","..","bin","test_results","TestResults.xml")
19+
20+
let writeResults = TestResults.writeNUnitSummary (resultsPath, "dotnet-proj-info.Tests")
21+
let config = defaultConfig.appendSummaryHandler writeResults
22+
23+
Tests.runTestsWithArgs config (args |> Array.ofList) (DotnetProjInfo.Tests.tests pkgUnderTestVersion)

test/dotnet-proj-info.Tests/Sample.fs

Lines changed: 125 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let tests pkgUnderTestVersion =
127127
|> fun s -> s.Trim()
128128
|> asLines
129129

130-
[
130+
let generalTests =
131131
testList "general" [
132132
testCase |> withLog "can show help" (fun _ fs ->
133133

@@ -137,6 +137,7 @@ let tests pkgUnderTestVersion =
137137
)
138138
]
139139

140+
let sanityChecks =
140141
testList "sanity check of projects" [
141142

142143
testCase |> withLog "can build sample1" (fun _ fs ->
@@ -165,15 +166,51 @@ let tests pkgUnderTestVersion =
165166
let projPath = testDir/ (``samples2 NetSdk library``.ProjectFile)
166167
let projDir = Path.GetDirectoryName projPath
167168

168-
let result = dotnet fs ["build"; projPath]
169-
result |> checkExitCodeZero
169+
dotnet fs ["build"; projPath]
170+
|> checkExitCodeZero
170171

171-
let outputPath = projDir/"bin"/"Debug"/"netstandard2.0"/ ``samples2 NetSdk library``.AssemblyName + ".dll"
172+
let tfm = ``samples2 NetSdk library``.TargetFrameworks |> Map.toList |> List.map fst |> List.head
173+
let outputPath = projDir/"bin"/"Debug"/tfm/ ``samples2 NetSdk library``.AssemblyName + ".dll"
172174
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)
173175
)
174176

177+
testCase |> withLog "can build sample3" (fun _ fs ->
178+
let testDir = inDir fs "sanity_check_sample2"
179+
copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir
180+
181+
let projPath = testDir/ (``sample3 Netsdk projs``.ProjectFile)
182+
let projDir = Path.GetDirectoryName projPath
183+
184+
dotnet fs ["build"; projPath]
185+
|> checkExitCodeZero
186+
187+
let outputPath = projDir/"bin"/"Debug"/"netcoreapp2.1"/ ``sample3 Netsdk projs``.AssemblyName + ".dll"
188+
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)
189+
190+
let result = dotnet fs ["run"; "-p"; projPath; "--no-build"]
191+
result |> checkExitCodeZero
192+
193+
Expect.equal "Hello World from F#!" (result.Result.StandardOutput.Trim()) "check console out"
194+
)
195+
196+
testCase |> withLog "can build sample4" (fun _ fs ->
197+
let testDir = inDir fs "sanity_check_sample4"
198+
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir
199+
200+
let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)
201+
let projDir = Path.GetDirectoryName projPath
202+
203+
dotnet fs ["build"; projPath]
204+
|> checkExitCodeZero
205+
206+
for (tfm, _) in ``samples4 NetSdk multi tfm``.TargetFrameworks |> Map.toList do
207+
let outputPath = projDir/"bin"/"Debug"/tfm/ ``samples4 NetSdk multi tfm``.AssemblyName + ".dll"
208+
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)
209+
)
210+
175211
]
176212

213+
let netFwTests =
177214
testList ".net" [
178215
testCase |> withLog "can show installed .net frameworks" (fun _ fs ->
179216

@@ -202,6 +239,7 @@ let tests pkgUnderTestVersion =
202239
)
203240
]
204241

242+
let oldSdkTests =
205243
testList "old sdk" [
206244
testCase |> withLog "can read properties" (fun _ fs ->
207245
let testDir = inDir fs "oldsdk_props"
@@ -225,8 +263,9 @@ let tests pkgUnderTestVersion =
225263
)
226264
]
227265

266+
let netSdkTests =
228267
testList ".net sdk" [
229-
testCase |> withLog "can read properties" (fun _ fs ->
268+
yield testCase |> withLog "can read properties" (fun _ fs ->
230269
let testDir = inDir fs "netsdk_props"
231270
copyDirFromAssets fs ``samples2 NetSdk library``.ProjDir testDir
232271

@@ -237,10 +276,12 @@ let tests pkgUnderTestVersion =
237276

238277
let result = projInfo fs [projPath; "--get-property"; "TargetFramework"]
239278
result |> checkExitCodeZero
240-
Expect.equal "TargetFramework=netstandard2.0" (result.Result.StandardOutput.Trim()) "wrong output"
279+
let tfm = ``samples2 NetSdk library``.TargetFrameworks |> Map.toList |> List.map fst |> List.head
280+
let out = result.Result.StandardOutput.Trim()
281+
Expect.equal out (sprintf "TargetFramework=%s" tfm) "wrong output"
241282
)
242283

243-
testCase |> withLog "can read fsc args" (fun _ fs ->
284+
yield testCase |> withLog "can read fsc args" (fun _ fs ->
244285
let testDir = inDir fs "netsdk_fsc_args"
245286
copyDirFromAssets fs ``samples2 NetSdk library``.ProjDir testDir
246287

@@ -252,7 +293,83 @@ let tests pkgUnderTestVersion =
252293
let result = projInfo fs [projPath; "--fsc-args"]
253294
result |> checkExitCodeZero
254295
)
296+
297+
for conf in [ "Debug"; "Release" ] do
298+
yield testCase |> withLog (sprintf "can read properties for conf (%s)" conf) (fun _ fs ->
299+
let testDir = inDir fs (sprintf "netsdk_props_%s" (conf.ToLower()))
300+
copyDirFromAssets fs ``samples2 NetSdk library``.ProjDir testDir
301+
302+
let projPath = testDir/ (``samples2 NetSdk library``.ProjectFile)
303+
304+
dotnet fs ["restore"; projPath]
305+
|> checkExitCodeZero
306+
307+
let result = projInfo fs [projPath; "-gp"; "OutputPath"; "-c"; conf]
308+
result |> checkExitCodeZero
309+
let out = result.Result.StandardOutput.Trim()
310+
311+
let tfm = ``samples2 NetSdk library``.TargetFrameworks |> Map.toList |> List.map fst |> List.head
312+
let expectedPath = "bin"/conf/tfm + Path.DirectorySeparatorChar.ToString()
313+
Expect.equal out (sprintf "OutputPath=%s" expectedPath) "wrong output"
314+
)
315+
316+
yield testCase |> withLog "can read project references" (fun _ fs ->
317+
let testDir = inDir fs "netsdk_proj_refs"
318+
copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir
319+
320+
let projPath = testDir/ (``sample3 Netsdk projs``.ProjectFile)
321+
322+
dotnet fs ["restore"; projPath]
323+
|> checkExitCodeZero
324+
325+
let result = projInfo fs [projPath; "--project-refs"]
326+
result |> checkExitCodeZero
327+
328+
let out = stdOutLines result
329+
330+
let p2ps =
331+
``sample3 Netsdk projs``.ProjectReferences
332+
|> List.map (fun p2p -> testDir/p2p.ProjectFile)
333+
334+
Expect.equal out p2ps "p2ps"
335+
)
336+
337+
for (tfm, infoOfTfm) in ``samples4 NetSdk multi tfm``.TargetFrameworks |> Map.toList do
338+
yield testCase |> withLog (sprintf "can read fsc args of multitarget (%s)" tfm) (fun _ fs ->
339+
let testDir = inDir fs (sprintf "netsdk_fsc_args_multi_%s" tfm)
340+
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir
341+
342+
let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)
343+
344+
dotnet fs ["restore"; projPath]
345+
|> checkExitCodeZero
346+
347+
let result = projInfo fs [projPath; "--fsc-args"; "-f"; tfm]
348+
result |> checkExitCodeZero
349+
)
350+
351+
yield testCase |> withLog (sprintf "can read properties of multitarget (%s)" tfm) (fun _ fs ->
352+
let testDir = inDir fs (sprintf "netsdk_props_multi_%s" tfm)
353+
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir
354+
355+
let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)
356+
357+
dotnet fs ["restore"; projPath]
358+
|> checkExitCodeZero
359+
360+
let result = projInfo fs [projPath; "-f"; tfm; "--get-property"; "MyProperty"]
361+
result |> checkExitCodeZero
362+
let out = result.Result.StandardOutput.Trim()
363+
let prop = infoOfTfm.Props |> Map.find "MyProperty"
364+
Expect.equal out (sprintf "MyProperty=%s" prop) "wrong output"
365+
)
366+
255367
]
256368

257-
]
369+
[ generalTests
370+
sanityChecks
371+
netFwTests
372+
oldSdkTests
373+
netSdkTests ]
258374
|> testList "suite"
375+
|> testSequenced

test/dotnet-proj-info.Tests/TestAssets.fs

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,73 @@ module DotnetProjInfo.TestAssets
33
open FileUtils
44

55
type TestAssetProjInfo =
6-
{ ProjDir: string;
7-
AssemblyName: string;
8-
ProjectFile: string }
6+
{ ProjDir: string
7+
AssemblyName: string
8+
ProjectFile: string
9+
TargetFrameworks: Map<string, TestAssetProjInfoByTfm>
10+
ProjectReferences: TestAssetProjInfo list }
11+
and TestAssetProjInfoByTfm =
12+
{ SourceFiles: string list
13+
Props: Map<string,string> }
14+
15+
let sourceFiles sources =
16+
{ SourceFiles = sources
17+
Props = Map.empty }
18+
19+
let andProps props x =
20+
let n =
21+
[ yield! x.Props |> Map.toList
22+
yield! props ]
23+
{ x with Props = n |> Map.ofList }
924

1025
let ``samples1 OldSdk library`` =
11-
{ ProjDir = "sample1-oldsdk-lib";
12-
AssemblyName = "Lib1";
13-
ProjectFile = "l1"/"l1.fsproj" }
26+
{ ProjDir = "sample1-oldsdk-lib"
27+
AssemblyName = "Lib1"
28+
ProjectFile = "l1"/"l1.fsproj"
29+
TargetFrameworks = Map.ofList [
30+
"net461", sourceFiles ["AssemblyInfo.fs"; "Library.fs"]
31+
]
32+
ProjectReferences = [] }
1433

1534
let ``samples2 NetSdk library`` =
16-
{ ProjDir = "sample2-netsdk-lib";
17-
AssemblyName = "n1";
18-
ProjectFile = "n1"/"n1.fsproj" }
35+
{ ProjDir = "sample2-netsdk-lib"
36+
AssemblyName = "n1"
37+
ProjectFile = "n1"/"n1.fsproj"
38+
TargetFrameworks = Map.ofList [
39+
"netstandard2.0", sourceFiles ["Library.fs"]
40+
]
41+
ProjectReferences = [] }
42+
43+
let ``sample3 Netsdk projs`` =
44+
{ ProjDir = "sample3-netsdk-projs"
45+
AssemblyName = "c1"
46+
ProjectFile = "c1"/"c1.fsproj"
47+
TargetFrameworks = Map.ofList [
48+
"netcoreapp2.1", sourceFiles ["Program.fs"]
49+
]
50+
ProjectReferences =
51+
[ { ProjDir = "sample3-netsdk-projs"/"l1"
52+
AssemblyName = "l1"
53+
ProjectFile = "l1"/"l1.csproj"
54+
TargetFrameworks = Map.ofList [
55+
"netstandard2.0", sourceFiles ["Class1.cs"]
56+
]
57+
ProjectReferences = [] }
58+
{ ProjDir = "sample3-netsdk-projs"/"l2"
59+
AssemblyName = "l2"
60+
ProjectFile = "l2"/"l2.fsproj"
61+
TargetFrameworks = Map.ofList [
62+
"netstandard2.0", sourceFiles ["Library.fs"]
63+
]
64+
ProjectReferences = [] }
65+
] }
66+
67+
let ``samples4 NetSdk multi tfm`` =
68+
{ ProjDir = "sample4-netsdk-multitfm"
69+
AssemblyName = "m1"
70+
ProjectFile = "m1"/"m1.fsproj"
71+
TargetFrameworks = Map.ofList [
72+
"netstandard2.0", (sourceFiles ["LibraryA.fs"] |> andProps ["MyProperty", "AAA"])
73+
"net461", (sourceFiles ["LibraryB.fs"] |> andProps ["MyProperty", "BBB"])
74+
]
75+
ProjectReferences = [] }

test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Expecto" Version="5.*" />
16+
<PackageReference Include="Expecto" Version="8.4.*" />
17+
<PackageReference Include="Expecto.TestResults" Version="8.4.*" />
1718
<PackageReference Include="MedallionShell" Version="1.5.0" />
1819
</ItemGroup>
1920

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Learn more about F# at http://fsharp.org
2+
3+
open System
4+
5+
[<EntryPoint>]
6+
let main argv =
7+
let msg = l1.Class1.GetMessage("F#")
8+
l2.Say.hello msg
9+
0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\l1\l1.csproj" />
14+
<ProjectReference Include="..\l2\l2.fsproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace l1
4+
{
5+
public class Class1
6+
{
7+
public static string GetMessage(string lang)
8+
{
9+
return $"World from {lang}!";
10+
}
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace l2
2+
3+
module Say =
4+
let hello name =
5+
printfn "Hello %s" name

0 commit comments

Comments
 (0)