Skip to content

Commit

Permalink
add more tests for p2p, multitargeting, conf (#22)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
enricosada authored Sep 28, 2018
1 parent 43682ef commit 08f347a
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 19 deletions.
13 changes: 13 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ artifacts:
- path: bin\nupkg\*.nupkg
name: nupkgs
type: NuGetPackage

on_finish:
- ps: >-
$wc = New-Object 'System.Net.WebClient';
$testResults = @(
# '.\bin\test_results\TestResults.xml'
)
- ps: >-
Foreach ($path in $testResults) {
If (Test-Path $path) {
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit3/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $path))
}
}
7 changes: 6 additions & 1 deletion test/dotnet-proj-info.Tests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ let main argv =
Environment.SetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL", "1")
Environment.SetEnvironmentVariable("MSBuildExtensionsPath", null)

Tests.runTestsWithArgs defaultConfig (args |> Array.ofList) (DotnetProjInfo.Tests.tests pkgUnderTestVersion)
let resultsPath = IO.Path.Combine(__SOURCE_DIRECTORY__,"..","..","bin","test_results","TestResults.xml")

let writeResults = TestResults.writeNUnitSummary (resultsPath, "dotnet-proj-info.Tests")
let config = defaultConfig.appendSummaryHandler writeResults

Tests.runTestsWithArgs config (args |> Array.ofList) (DotnetProjInfo.Tests.tests pkgUnderTestVersion)
133 changes: 125 additions & 8 deletions test/dotnet-proj-info.Tests/Sample.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let tests pkgUnderTestVersion =
|> fun s -> s.Trim()
|> asLines

[
let generalTests =
testList "general" [
testCase |> withLog "can show help" (fun _ fs ->

Expand All @@ -137,6 +137,7 @@ let tests pkgUnderTestVersion =
)
]

let sanityChecks =
testList "sanity check of projects" [

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

let result = dotnet fs ["build"; projPath]
result |> checkExitCodeZero
dotnet fs ["build"; projPath]
|> checkExitCodeZero

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

testCase |> withLog "can build sample3" (fun _ fs ->
let testDir = inDir fs "sanity_check_sample2"
copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir

let projPath = testDir/ (``sample3 Netsdk projs``.ProjectFile)
let projDir = Path.GetDirectoryName projPath

dotnet fs ["build"; projPath]
|> checkExitCodeZero

let outputPath = projDir/"bin"/"Debug"/"netcoreapp2.1"/ ``sample3 Netsdk projs``.AssemblyName + ".dll"
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)

let result = dotnet fs ["run"; "-p"; projPath; "--no-build"]
result |> checkExitCodeZero

Expect.equal "Hello World from F#!" (result.Result.StandardOutput.Trim()) "check console out"
)

testCase |> withLog "can build sample4" (fun _ fs ->
let testDir = inDir fs "sanity_check_sample4"
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir

let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)
let projDir = Path.GetDirectoryName projPath

dotnet fs ["build"; projPath]
|> checkExitCodeZero

for (tfm, _) in ``samples4 NetSdk multi tfm``.TargetFrameworks |> Map.toList do
let outputPath = projDir/"bin"/"Debug"/tfm/ ``samples4 NetSdk multi tfm``.AssemblyName + ".dll"
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)
)

]

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

Expand Down Expand Up @@ -202,6 +239,7 @@ let tests pkgUnderTestVersion =
)
]

let oldSdkTests =
testList "old sdk" [
testCase |> withLog "can read properties" (fun _ fs ->
let testDir = inDir fs "oldsdk_props"
Expand All @@ -225,8 +263,9 @@ let tests pkgUnderTestVersion =
)
]

let netSdkTests =
testList ".net sdk" [
testCase |> withLog "can read properties" (fun _ fs ->
yield testCase |> withLog "can read properties" (fun _ fs ->
let testDir = inDir fs "netsdk_props"
copyDirFromAssets fs ``samples2 NetSdk library``.ProjDir testDir

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

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

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

Expand All @@ -252,7 +293,83 @@ let tests pkgUnderTestVersion =
let result = projInfo fs [projPath; "--fsc-args"]
result |> checkExitCodeZero
)

for conf in [ "Debug"; "Release" ] do
yield testCase |> withLog (sprintf "can read properties for conf (%s)" conf) (fun _ fs ->
let testDir = inDir fs (sprintf "netsdk_props_%s" (conf.ToLower()))
copyDirFromAssets fs ``samples2 NetSdk library``.ProjDir testDir

let projPath = testDir/ (``samples2 NetSdk library``.ProjectFile)

dotnet fs ["restore"; projPath]
|> checkExitCodeZero

let result = projInfo fs [projPath; "-gp"; "OutputPath"; "-c"; conf]
result |> checkExitCodeZero
let out = result.Result.StandardOutput.Trim()

let tfm = ``samples2 NetSdk library``.TargetFrameworks |> Map.toList |> List.map fst |> List.head
let expectedPath = "bin"/conf/tfm + Path.DirectorySeparatorChar.ToString()
Expect.equal out (sprintf "OutputPath=%s" expectedPath) "wrong output"
)

yield testCase |> withLog "can read project references" (fun _ fs ->
let testDir = inDir fs "netsdk_proj_refs"
copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir

let projPath = testDir/ (``sample3 Netsdk projs``.ProjectFile)

dotnet fs ["restore"; projPath]
|> checkExitCodeZero

let result = projInfo fs [projPath; "--project-refs"]
result |> checkExitCodeZero

let out = stdOutLines result

let p2ps =
``sample3 Netsdk projs``.ProjectReferences
|> List.map (fun p2p -> testDir/p2p.ProjectFile)

Expect.equal out p2ps "p2ps"
)

for (tfm, infoOfTfm) in ``samples4 NetSdk multi tfm``.TargetFrameworks |> Map.toList do
yield testCase |> withLog (sprintf "can read fsc args of multitarget (%s)" tfm) (fun _ fs ->
let testDir = inDir fs (sprintf "netsdk_fsc_args_multi_%s" tfm)
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir

let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)

dotnet fs ["restore"; projPath]
|> checkExitCodeZero

let result = projInfo fs [projPath; "--fsc-args"; "-f"; tfm]
result |> checkExitCodeZero
)

yield testCase |> withLog (sprintf "can read properties of multitarget (%s)" tfm) (fun _ fs ->
let testDir = inDir fs (sprintf "netsdk_props_multi_%s" tfm)
copyDirFromAssets fs ``samples4 NetSdk multi tfm``.ProjDir testDir

let projPath = testDir/ (``samples4 NetSdk multi tfm``.ProjectFile)

dotnet fs ["restore"; projPath]
|> checkExitCodeZero

let result = projInfo fs [projPath; "-f"; tfm; "--get-property"; "MyProperty"]
result |> checkExitCodeZero
let out = result.Result.StandardOutput.Trim()
let prop = infoOfTfm.Props |> Map.find "MyProperty"
Expect.equal out (sprintf "MyProperty=%s" prop) "wrong output"
)

]

]
[ generalTests
sanityChecks
netFwTests
oldSdkTests
netSdkTests ]
|> testList "suite"
|> testSequenced
75 changes: 66 additions & 9 deletions test/dotnet-proj-info.Tests/TestAssets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,73 @@ module DotnetProjInfo.TestAssets
open FileUtils

type TestAssetProjInfo =
{ ProjDir: string;
AssemblyName: string;
ProjectFile: string }
{ ProjDir: string
AssemblyName: string
ProjectFile: string
TargetFrameworks: Map<string, TestAssetProjInfoByTfm>
ProjectReferences: TestAssetProjInfo list }
and TestAssetProjInfoByTfm =
{ SourceFiles: string list
Props: Map<string,string> }

let sourceFiles sources =
{ SourceFiles = sources
Props = Map.empty }

let andProps props x =
let n =
[ yield! x.Props |> Map.toList
yield! props ]
{ x with Props = n |> Map.ofList }

let ``samples1 OldSdk library`` =
{ ProjDir = "sample1-oldsdk-lib";
AssemblyName = "Lib1";
ProjectFile = "l1"/"l1.fsproj" }
{ ProjDir = "sample1-oldsdk-lib"
AssemblyName = "Lib1"
ProjectFile = "l1"/"l1.fsproj"
TargetFrameworks = Map.ofList [
"net461", sourceFiles ["AssemblyInfo.fs"; "Library.fs"]
]
ProjectReferences = [] }

let ``samples2 NetSdk library`` =
{ ProjDir = "sample2-netsdk-lib";
AssemblyName = "n1";
ProjectFile = "n1"/"n1.fsproj" }
{ ProjDir = "sample2-netsdk-lib"
AssemblyName = "n1"
ProjectFile = "n1"/"n1.fsproj"
TargetFrameworks = Map.ofList [
"netstandard2.0", sourceFiles ["Library.fs"]
]
ProjectReferences = [] }

let ``sample3 Netsdk projs`` =
{ ProjDir = "sample3-netsdk-projs"
AssemblyName = "c1"
ProjectFile = "c1"/"c1.fsproj"
TargetFrameworks = Map.ofList [
"netcoreapp2.1", sourceFiles ["Program.fs"]
]
ProjectReferences =
[ { ProjDir = "sample3-netsdk-projs"/"l1"
AssemblyName = "l1"
ProjectFile = "l1"/"l1.csproj"
TargetFrameworks = Map.ofList [
"netstandard2.0", sourceFiles ["Class1.cs"]
]
ProjectReferences = [] }
{ ProjDir = "sample3-netsdk-projs"/"l2"
AssemblyName = "l2"
ProjectFile = "l2"/"l2.fsproj"
TargetFrameworks = Map.ofList [
"netstandard2.0", sourceFiles ["Library.fs"]
]
ProjectReferences = [] }
] }

let ``samples4 NetSdk multi tfm`` =
{ ProjDir = "sample4-netsdk-multitfm"
AssemblyName = "m1"
ProjectFile = "m1"/"m1.fsproj"
TargetFrameworks = Map.ofList [
"netstandard2.0", (sourceFiles ["LibraryA.fs"] |> andProps ["MyProperty", "AAA"])
"net461", (sourceFiles ["LibraryB.fs"] |> andProps ["MyProperty", "BBB"])
]
ProjectReferences = [] }
3 changes: 2 additions & 1 deletion test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expecto" Version="5.*" />
<PackageReference Include="Expecto" Version="8.4.*" />
<PackageReference Include="Expecto.TestResults" Version="8.4.*" />
<PackageReference Include="MedallionShell" Version="1.5.0" />
</ItemGroup>

Expand Down
9 changes: 9 additions & 0 deletions test/examples/sample3-netsdk-projs/c1/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Learn more about F# at http://fsharp.org

open System

[<EntryPoint>]
let main argv =
let msg = l1.Class1.GetMessage("F#")
l2.Say.hello msg
0
17 changes: 17 additions & 0 deletions test/examples/sample3-netsdk-projs/c1/c1.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\l1\l1.csproj" />
<ProjectReference Include="..\l2\l2.fsproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions test/examples/sample3-netsdk-projs/l1/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace l1
{
public class Class1
{
public static string GetMessage(string lang)
{
return $"World from {lang}!";
}
}
}
7 changes: 7 additions & 0 deletions test/examples/sample3-netsdk-projs/l1/l1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions test/examples/sample3-netsdk-projs/l2/Library.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace l2

module Say =
let hello name =
printfn "Hello %s" name
11 changes: 11 additions & 0 deletions test/examples/sample3-netsdk-projs/l2/l2.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fs" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions test/examples/sample4-netsdk-multitfm/m1/LibraryA.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace m1

module Say =
let hello name =
printfn "Hello %s" name
5 changes: 5 additions & 0 deletions test/examples/sample4-netsdk-multitfm/m1/LibraryB.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace m1

module Say =
let hello name =
printfn "Hello %s" name
Loading

0 comments on commit 08f347a

Please sign in to comment.