diff --git a/appveyor.yml b/appveyor.yml index 5ff8861b..2619a148 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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)) + } + } diff --git a/test/dotnet-proj-info.Tests/Program.fs b/test/dotnet-proj-info.Tests/Program.fs index 6c0cf618..d74f03b1 100644 --- a/test/dotnet-proj-info.Tests/Program.fs +++ b/test/dotnet-proj-info.Tests/Program.fs @@ -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) diff --git a/test/dotnet-proj-info.Tests/Sample.fs b/test/dotnet-proj-info.Tests/Sample.fs index 8b61afbe..39e98eac 100644 --- a/test/dotnet-proj-info.Tests/Sample.fs +++ b/test/dotnet-proj-info.Tests/Sample.fs @@ -127,7 +127,7 @@ let tests pkgUnderTestVersion = |> fun s -> s.Trim() |> asLines - [ + let generalTests = testList "general" [ testCase |> withLog "can show help" (fun _ fs -> @@ -137,6 +137,7 @@ let tests pkgUnderTestVersion = ) ] + let sanityChecks = testList "sanity check of projects" [ testCase |> withLog "can build sample1" (fun _ fs -> @@ -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 -> @@ -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" @@ -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 @@ -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 @@ -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 diff --git a/test/dotnet-proj-info.Tests/TestAssets.fs b/test/dotnet-proj-info.Tests/TestAssets.fs index ebbcf6fd..af646aa7 100644 --- a/test/dotnet-proj-info.Tests/TestAssets.fs +++ b/test/dotnet-proj-info.Tests/TestAssets.fs @@ -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 + ProjectReferences: TestAssetProjInfo list } +and TestAssetProjInfoByTfm = + { SourceFiles: string list + Props: Map } + +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 = [] } diff --git a/test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj b/test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj index d84d02b9..ad00f0ac 100644 --- a/test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj +++ b/test/dotnet-proj-info.Tests/dotnet-proj-info.Tests.fsproj @@ -13,7 +13,8 @@ - + + diff --git a/test/examples/sample3-netsdk-projs/c1/Program.fs b/test/examples/sample3-netsdk-projs/c1/Program.fs new file mode 100644 index 00000000..00fd116f --- /dev/null +++ b/test/examples/sample3-netsdk-projs/c1/Program.fs @@ -0,0 +1,9 @@ +// Learn more about F# at http://fsharp.org + +open System + +[] +let main argv = + let msg = l1.Class1.GetMessage("F#") + l2.Say.hello msg + 0 diff --git a/test/examples/sample3-netsdk-projs/c1/c1.fsproj b/test/examples/sample3-netsdk-projs/c1/c1.fsproj new file mode 100644 index 00000000..754a900b --- /dev/null +++ b/test/examples/sample3-netsdk-projs/c1/c1.fsproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + + + + + diff --git a/test/examples/sample3-netsdk-projs/l1/Class1.cs b/test/examples/sample3-netsdk-projs/l1/Class1.cs new file mode 100644 index 00000000..7ec02586 --- /dev/null +++ b/test/examples/sample3-netsdk-projs/l1/Class1.cs @@ -0,0 +1,12 @@ +using System; + +namespace l1 +{ + public class Class1 + { + public static string GetMessage(string lang) + { + return $"World from {lang}!"; + } + } +} diff --git a/test/examples/sample3-netsdk-projs/l1/l1.csproj b/test/examples/sample3-netsdk-projs/l1/l1.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/test/examples/sample3-netsdk-projs/l1/l1.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/test/examples/sample3-netsdk-projs/l2/Library.fs b/test/examples/sample3-netsdk-projs/l2/Library.fs new file mode 100644 index 00000000..6c658ed7 --- /dev/null +++ b/test/examples/sample3-netsdk-projs/l2/Library.fs @@ -0,0 +1,5 @@ +namespace l2 + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/test/examples/sample3-netsdk-projs/l2/l2.fsproj b/test/examples/sample3-netsdk-projs/l2/l2.fsproj new file mode 100644 index 00000000..df454322 --- /dev/null +++ b/test/examples/sample3-netsdk-projs/l2/l2.fsproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/test/examples/sample4-netsdk-multitfm/m1/LibraryA.fs b/test/examples/sample4-netsdk-multitfm/m1/LibraryA.fs new file mode 100644 index 00000000..fb03f33d --- /dev/null +++ b/test/examples/sample4-netsdk-multitfm/m1/LibraryA.fs @@ -0,0 +1,5 @@ +namespace m1 + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/test/examples/sample4-netsdk-multitfm/m1/LibraryB.fs b/test/examples/sample4-netsdk-multitfm/m1/LibraryB.fs new file mode 100644 index 00000000..fb03f33d --- /dev/null +++ b/test/examples/sample4-netsdk-multitfm/m1/LibraryB.fs @@ -0,0 +1,5 @@ +namespace m1 + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/test/examples/sample4-netsdk-multitfm/m1/m1.fsproj b/test/examples/sample4-netsdk-multitfm/m1/m1.fsproj new file mode 100644 index 00000000..5a904b9f --- /dev/null +++ b/test/examples/sample4-netsdk-multitfm/m1/m1.fsproj @@ -0,0 +1,14 @@ + + + + netstandard2.0;net461 + AAA + BBB + + + + + + + +