@@ -144,6 +144,10 @@ let findByPath path parsed =
144144 | Some x -> x
145145 | None -> failwithf " key '%s ' not found in %A " path ( parsed |> Array.map ( fun kv -> kv.Key))
146146
147+ let isOSX () =
148+ System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
149+ System.Runtime.InteropServices.OSPlatform.OSX)
150+
147151let tests () =
148152
149153 let prepareTestsAssets = lazy (
@@ -241,15 +245,24 @@ let tests () =
241245
242246 Expect.equal parsed.Length 1 " lib"
243247
244- parsed
245- |> expectExists projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " net461" } " a lib"
248+ let l1Parsed =
249+ parsed
250+ |> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " net461" } " a lib"
251+
252+ let expectedSources =
253+ [ projDir / " AssemblyInfo.fs"
254+ projDir / " Library.fs"
255+ ( Path.GetTempPath()) / " .NETFramework,Version=v4.6.1.AssemblyAttributes.fs" ]
256+
257+ Expect.equal l1Parsed.SourceFiles expectedSources " check sources"
246258 )
247259
248260 testCase |> withLog " can load sample2" ( fun logger fs ->
249261 let testDir = inDir fs " load_sample2"
250262 copyDirFromAssets fs `` sample2 NetSdk library `` .ProjDir testDir
251263
252264 let projPath = testDir/ ( `` sample2 NetSdk library `` .ProjectFile)
265+ let projDir = Path.GetDirectoryName projPath
253266
254267 dotnet fs [ " restore" ; projPath]
255268 |> checkExitCodeZero
@@ -267,18 +280,30 @@ let tests () =
267280
268281 Expect.equal parsed.Length 1 " console and lib"
269282
270- parsed
271- |> expectExists projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " first is a lib"
283+ let n1Parsed =
284+ parsed
285+ |> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " first is a lib"
286+
287+ let expectedSources =
288+ [ projDir / " obj/Debug/netstandard2.0/n1.AssemblyInfo.fs"
289+ projDir / " Library.fs" ]
290+ |> List.map Path.GetFullPath
291+
292+ Expect.equal n1Parsed.SourceFiles expectedSources " check sources"
272293 )
273294
274295 testCase |> withLog " can load sample3" ( fun logger fs ->
275296 let testDir = inDir fs " load_sample3"
276297 copyDirFromAssets fs `` sample3 Netsdk projs `` .ProjDir testDir
277298
278299 let projPath = testDir/ ( `` sample3 Netsdk projs `` .ProjectFile)
279- let l1 :: l2 :: [] =
300+ let projDir = Path.GetDirectoryName projPath
301+
302+ let ( l1 , l1Dir ) :: ( l2 , l2Dir ) :: [] =
280303 `` sample3 Netsdk projs `` .ProjectReferences
281304 |> List.map ( fun p2p -> testDir/ p2p.ProjectFile )
305+ |> List.map Path.GetFullPath
306+ |> List.map ( fun path -> path, Path.GetDirectoryName( path))
282307
283308 dotnet fs [ " build" ; projPath]
284309 |> checkExitCodeZero
@@ -296,19 +321,65 @@ let tests () =
296321
297322 Expect.equal parsed.Length 3 ( sprintf " console (F#) and lib (F#) and lib (C#), but was %A " ( parsed |> Array.map ( fun x -> x.Key)))
298323
299- parsed
300- |> expectExists l1 { ProjectKey.ProjectPath = l1; TargetFramework = " netstandard2.0" } " the F# lib"
301- parsed
302- |> expectExists l2 { ProjectKey.ProjectPath = l2; TargetFramework = " netstandard2.0" } " the C# lib"
303- parsed
304- |> expectExists projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netcoreapp2.1" } " the F# console"
324+ let l1Parsed =
325+ parsed
326+ |> expectFind l1 { ProjectKey.ProjectPath = l1; TargetFramework = " netstandard2.0" } " the C# lib"
327+
328+ let l1ExpectedSources =
329+ [ l1Dir / " obj/Debug/netstandard2.0/l1.AssemblyInfo.cs"
330+ l1Dir / " Class1.fs" ]
331+ |> List.map Path.GetFullPath
332+
333+ // TODO C# doesnt have OtherOptions or SourceFiles atm. it should
334+ // Expect.equal l1Parsed.SourceFiles l1ExpectedSources "check sources"
335+ Expect.equal l1Parsed.SourceFiles [] " check sources"
336+
337+ let l2Parsed =
338+ parsed
339+ |> expectFind l2 { ProjectKey.ProjectPath = l2; TargetFramework = " netstandard2.0" } " the F# lib"
340+
341+ let l2ExpectedSources =
342+ [ l2Dir / " obj/Debug/netstandard2.0/l2.AssemblyInfo.fs"
343+ l2Dir / " Library.fs" ]
344+ |> List.map Path.GetFullPath
345+
346+ Expect.equal l2Parsed.SourceFiles l2ExpectedSources " check sources"
347+
348+
349+ let c1Parsed =
350+ parsed
351+ |> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netcoreapp2.1" } " the F# console"
352+
353+ if ( isOSX ()) then
354+ let errorOnOsx =
355+ """
356+ check sources.
357+ expected:
358+ ["/Users/travis/build/enricosada/dotnet-proj-info/test/testrun_ws/load_sample3/c1/obj/Debug/netcoreapp2.1/c1.AssemblyInfo.fs";
359+ "/Users/travis/build/enricosada/dotnet-proj-info/test/testrun_ws/load_sample3/c1/Program.fs"]
360+ actual:
361+ []
362+
363+ The OtherOptions is empty.
364+ """ .Trim()
365+ Tests.skiptest ( sprintf " Known failure on OSX travis. error is %s " errorOnOsx)
366+ //TODO check failure on osx
367+
368+ let c1ExpectedSources =
369+ [ projDir / " obj/Debug/netcoreapp2.1/c1.AssemblyInfo.fs"
370+ projDir / " Program.fs" ]
371+ |> List.map Path.GetFullPath
372+
373+ Expect.equal c1Parsed.SourceFiles c1ExpectedSources " check sources"
374+
305375 )
306376
307377 testCase |> withLog " can load sample4" ( fun logger fs ->
308378 let testDir = inDir fs " load_sample4"
309379 copyDirFromAssets fs `` sample4 NetSdk multi tfm `` .ProjDir testDir
310380
311381 let projPath = testDir/ ( `` sample4 NetSdk multi tfm `` .ProjectFile)
382+ let projDir = Path.GetDirectoryName projPath
312383
313384 dotnet fs [ " restore" ; projPath]
314385 |> checkExitCodeZero
@@ -330,15 +401,24 @@ let tests () =
330401
331402 Expect.equal parsed.Length 1 ( sprintf " multi-tfm lib (F#), but was %A " ( parsed |> Array.map ( fun x -> x.Key)))
332403
333- parsed
334- |> expectExists projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " the F# console"
404+ let m1Parsed =
405+ parsed
406+ |> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " the F# console"
407+
408+ let m1ExpectedSources =
409+ [ projDir / " obj/Debug/netstandard2.0/m1.AssemblyInfo.fs"
410+ projDir / " LibraryA.fs" ]
411+ |> List.map Path.GetFullPath
412+
413+ Expect.equal m1Parsed.SourceFiles m1ExpectedSources " check sources"
335414 )
336415
337416 testCase |> withLog " can load sample5" ( fun logger fs ->
338417 let testDir = inDir fs " load_sample5"
339418 copyDirFromAssets fs `` sample5 NetSdk CSharp library `` .ProjDir testDir
340419
341420 let projPath = testDir/ ( `` sample5 NetSdk CSharp library `` .ProjectFile)
421+ let projDir = Path.GetDirectoryName projPath
342422
343423 dotnet fs [ " restore" ; projPath]
344424 |> checkExitCodeZero
@@ -356,8 +436,18 @@ let tests () =
356436
357437 Expect.equal parsed.Length 1 " lib"
358438
359- parsed
360- |> expectExists projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " a C# lib"
439+ let l2Parsed =
440+ parsed
441+ |> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = " netstandard2.0" } " a C# lib"
442+
443+ let l2ExpectedSources =
444+ [ projDir / " obj/Debug/netstandard2.0/l2.AssemblyInfo.cs"
445+ projDir / " Class1.cs" ]
446+ |> List.map Path.GetFullPath
447+
448+ // TODO C# doesnt have OtherOptions or SourceFiles atm. it should
449+ // Expect.equal l2Parsed.SourceFiles l2ExpectedSources "check sources"
450+ Expect.equal l2Parsed.SourceFiles [] " check sources"
361451 )
362452
363453 testCase |> withLog " can load sln" ( fun logger fs ->
@@ -384,17 +474,52 @@ let tests () =
384474 Expect.equal parsed.Length 3 " c1, l1, l2"
385475
386476 let c1 = testDir/ ( `` sample6 Netsdk Sparse/1 `` .ProjectFile)
477+ let c1Dir = Path.GetDirectoryName c1
478+
387479 let l2 :: [] =
388480 `` sample6 Netsdk Sparse/1 `` .ProjectReferences
389481 |> List.map ( fun p2p -> testDir/ p2p.ProjectFile )
482+ let l2Dir = Path.GetDirectoryName l2
483+
390484 let l1 = testDir/ ( `` sample6 Netsdk Sparse/2 `` .ProjectFile)
485+ let l1Dir = Path.GetDirectoryName l1
486+
487+ let l1Parsed =
488+ parsed
489+ |> expectFind l1 { ProjectKey.ProjectPath = l1; TargetFramework = " netstandard2.0" } " the F# lib"
490+
491+ let l1ExpectedSources =
492+ [ l1Dir / " obj/Debug/netstandard2.0/l1.AssemblyInfo.fs"
493+ l1Dir / " Library.fs" ]
494+ |> List.map Path.GetFullPath
495+
496+ Expect.equal l1Parsed.SourceFiles l1ExpectedSources " check sources l1"
497+ Expect.equal l1Parsed.ReferencedProjects [] " check p2p l1"
498+
499+ let l2Parsed =
500+ parsed
501+ |> expectFind l2 { ProjectKey.ProjectPath = l2; TargetFramework = " netstandard2.0" } " the C# lib"
502+
503+ let l2ExpectedSources =
504+ [ l2Dir / " obj/Debug/netstandard2.0/l2.AssemblyInfo.fs"
505+ l2Dir / " Library.fs" ]
506+ |> List.map Path.GetFullPath
507+
508+ Expect.equal l2Parsed.SourceFiles l2ExpectedSources " check sources l2"
509+ Expect.equal l2Parsed.ReferencedProjects [] " check p2p l2"
510+
511+ let c1Parsed =
512+ parsed
513+ |> expectFind c1 { ProjectKey.ProjectPath = c1; TargetFramework = " netcoreapp2.1" } " the F# console"
514+
515+ let c1ExpectedSources =
516+ [ c1Dir / " obj/Debug/netcoreapp2.1/c1.AssemblyInfo.fs"
517+ c1Dir / " Program.fs" ]
518+ |> List.map Path.GetFullPath
519+
520+ Expect.equal c1Parsed.SourceFiles c1ExpectedSources " check sources c1"
521+ Expect.equal c1Parsed.ReferencedProjects.Length 1 " check p2p c1"
391522
392- parsed
393- |> expectExists l1 { ProjectKey.ProjectPath = l1; TargetFramework = " netstandard2.0" } " the F# lib"
394- parsed
395- |> expectExists l2 { ProjectKey.ProjectPath = l2; TargetFramework = " netstandard2.0" } " the C# lib"
396- parsed
397- |> expectExists c1 { ProjectKey.ProjectPath = c1; TargetFramework = " netcoreapp2.1" } " the F# console"
398523 )
399524
400525 ]
0 commit comments