Skip to content

Commit 9f99b41

Browse files
committed
Make tests tasks
1 parent 8b019e5 commit 9f99b41

File tree

4 files changed

+160
-121
lines changed

4 files changed

+160
-121
lines changed

test/Ionide.ProjInfo.Tests/TestAssets.fs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,14 @@ let ``loader2-cancel-slow`` = {
369369
"classlibf1"
370370
/ "classlibf1.fsproj"
371371
]
372-
Expects = fun projectsAfterBuild -> ()
373-
// Expect.equal (Seq.length projectsAfterBuild) 1 "projects count"
374-
375-
// let classlibf1 =
376-
// projectsAfterBuild
377-
// |> Seq.head
372+
Expects = ignore
373+
}
378374

379-
// Expect.equal classlibf1.SourceFiles.Length 3 "classlibf1 source files"
380-
// Expect.equal classlibf1.TargetFramework "net8.0" "classlibf1 target framework"
375+
let ``loader2-concurrent`` = {
376+
ProjDir = "loader2-concurrent"
377+
EntryPoints = [
378+
"classlibf1"
379+
/ "classlibf1.fsproj"
380+
]
381+
Expects = ignore
381382
}

test/Ionide.ProjInfo.Tests/Tests.fs

Lines changed: 125 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ open System.Threading.Tasks
2525
open Microsoft.Build.Evaluation
2626
open Ionide.ProjInfo.ProjectLoader
2727

28+
module Exception =
29+
open System.Runtime.ExceptionServices
30+
31+
let inline reraiseAny (e: exn) =
32+
ExceptionDispatchInfo.Capture(e).Throw()
33+
2834
let RepoDir =
2935
(__SOURCE_DIRECTORY__
3036
/ ".."
@@ -1469,50 +1475,51 @@ let testWithEnv name (data: TestAssetProjInfo2) f test =
14691475
test
14701476
name
14711477
(fun () ->
1478+
task {
1479+
let logger = Log.create (sprintf "Test '%s'" name)
1480+
let fs = FileUtils logger
14721481

1473-
let logger = Log.create (sprintf "Test '%s'" name)
1474-
let fs = FileUtils logger
1482+
let testDir = inDir fs data.ProjDir
1483+
copyDirFromAssets fs data.ProjDir testDir
14751484

1476-
let testDir = inDir fs data.ProjDir
1477-
copyDirFromAssets fs data.ProjDir testDir
1485+
let entrypoints =
1486+
data.EntryPoints
1487+
|> Seq.map (fun x ->
1488+
testDir
1489+
/ x
1490+
)
14781491

1479-
let entrypoints =
1480-
data.EntryPoints
1481-
|> Seq.map (fun x ->
1482-
testDir
1483-
/ x
1492+
entrypoints
1493+
|> Seq.iter (fun x ->
1494+
dotnet fs [
1495+
"restore"
1496+
x
1497+
]
1498+
|> checkExitCodeZero
14841499
)
14851500

1486-
entrypoints
1487-
|> Seq.iter (fun x ->
1488-
dotnet fs [
1489-
"restore"
1490-
x
1491-
]
1492-
|> checkExitCodeZero
1493-
)
1494-
1495-
let binlog = new FileInfo(Path.Combine(testDir, $"{name}.binlog"))
1496-
use blc = new Binlogs(binlog)
1501+
let binlog = new FileInfo(Path.Combine(testDir, $"{name}.binlog"))
1502+
use blc = new Binlogs(binlog)
14971503

1498-
let env = {
1499-
Logger = logger
1500-
FS = fs
1501-
Binlog = blc
1502-
Data = data
1503-
Entrypoints = entrypoints
1504-
}
1504+
let env = {
1505+
Logger = logger
1506+
FS = fs
1507+
Binlog = blc
1508+
Data = data
1509+
Entrypoints = entrypoints
1510+
}
15051511

1506-
try
1507-
f env
1508-
with e ->
1512+
try
1513+
do! f env
1514+
with e ->
15091515

1510-
logger.error (
1511-
Message.eventX "binlog path {binlog}"
1512-
>> Message.setField "binlog" binlog.FullName
1513-
)
1516+
logger.error (
1517+
Message.eventX "binlog path {binlog}"
1518+
>> Message.setField "binlog" binlog.FullName
1519+
)
15141520

1515-
reraise ()
1521+
Exception.reraiseAny e
1522+
}
15161523
)
15171524

15181525
let projectCollection () =
@@ -1531,119 +1538,124 @@ type IWorkspaceLoader2 =
15311538

15321539

15331540
let buildManagerSessionTests toolsPath =
1534-
testSequenced
1535-
<| ftestList "buildManagerSessionTests" [
1536-
testCase
1541+
ftestList "buildManagerSessionTests" [
1542+
testCaseTask
15371543
|> testWithEnv
15381544
"loader2-solution-with-2-projects"
15391545
``loader2-solution-with-2-projects``
15401546
(fun env ->
1547+
task {
15411548

1542-
let path =
1543-
env.Entrypoints
1544-
|> Seq.map ProjectGraphEntryPoint
1549+
let path =
1550+
env.Entrypoints
1551+
|> Seq.map ProjectGraphEntryPoint
15451552

1546-
let loggers = env.Binlog.Loggers
1553+
let loggers = env.Binlog.Loggers
15471554

1548-
// Evaluation
1549-
use pc = projectCollection ()
1550-
let graph = ProjectLoader2.EvaluateAsGraphDesignTime(path, pc)
1555+
// Evaluation
1556+
use pc = projectCollection ()
1557+
let graph = ProjectLoader2.EvaluateAsGraphDesignTime(path, pc)
15511558

1552-
// Execution
1553-
let bp = BuildParameters(Loggers = loggers)
1559+
// Execution
1560+
let bp = BuildParameters(Loggers = loggers)
15541561

1555-
let bm = new BuildManagerSession(buildParameters = bp)
1562+
let bm = new BuildManagerSession(buildParameters = bp)
15561563

1557-
let result =
1558-
ProjectLoader2.Execution(bm, graph)
1559-
|> Task.RunSynchronously
1564+
let result =
1565+
ProjectLoader2.Execution(bm, graph)
1566+
|> Task.RunSynchronously
15601567

1561-
// Parse
1562-
let projectsAfterBuild =
1563-
ProjectLoader2.Parse result
1564-
|> Seq.choose (
1565-
function
1566-
| Ok(Ok(LoadedProjectInfo.StandardProjectInfo x)) -> Some x
1567-
| _ -> None
1568-
)
1568+
// Parse
1569+
let projectsAfterBuild =
1570+
ProjectLoader2.Parse result
1571+
|> Seq.choose (
1572+
function
1573+
| Ok(Ok(LoadedProjectInfo.StandardProjectInfo x)) -> Some x
1574+
| _ -> None
1575+
)
15691576

1570-
env.Data.Expects projectsAfterBuild
1577+
env.Data.Expects projectsAfterBuild
1578+
}
15711579
)
15721580

1573-
testCase
1581+
testCaseTask
15741582
|> testWithEnv
15751583
"Concurrency - new graph every time"
1576-
``loader2-solution-with-2-projects``
1584+
``loader2-concurrent``
15771585
(fun env ->
1578-
let path =
1579-
env.Entrypoints
1580-
|> Seq.map ProjectGraphEntryPoint
1581-
1582-
use pc = projectCollection ()
1583-
1584-
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
1585-
1586-
let bm = new BuildManagerSession(buildParameters = bp)
1587-
1588-
let work =
1589-
async {
1590-
// Evaluation
1591-
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
1592-
let! ct = Async.CancellationToken
1593-
1594-
// Execution
1595-
return!
1596-
ProjectLoader2.Execution(bm, graph, ct = ct)
1597-
|> Async.AwaitTask
1598-
}
1599-
1600-
// Should be throttled so concurrent builds won't fail
1601-
let result =
1602-
Async.Parallel [
1603-
work
1604-
work
1605-
work
1606-
work
1607-
]
1586+
task {
1587+
let path =
1588+
env.Entrypoints
1589+
|> Seq.map ProjectGraphEntryPoint
1590+
1591+
use pc = projectCollection ()
16081592

1609-
|> Async.RunSynchronously
1593+
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
16101594

1611-
()
1595+
let bm = new BuildManagerSession(buildParameters = bp)
16121596

1597+
let work =
1598+
async {
1599+
// Evaluation
1600+
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
1601+
let! ct = Async.CancellationToken
1602+
1603+
// Execution
1604+
return!
1605+
ProjectLoader2.Execution(bm, graph, ct = ct)
1606+
|> Async.AwaitTask
1607+
}
1608+
1609+
// Should be throttled so concurrent builds won't fail
1610+
let result =
1611+
Async.Parallel [
1612+
work
1613+
work
1614+
work
1615+
work
1616+
]
1617+
1618+
|> Async.RunSynchronously
1619+
1620+
()
1621+
1622+
}
16131623
)
16141624

16151625

1616-
testCase
1626+
testCaseTask
16171627
|> testWithEnv
16181628
"Cancellable"
16191629
``loader2-cancel-slow``
16201630
(fun env ->
1621-
let path =
1622-
env.Entrypoints
1623-
|> Seq.map ProjectGraphEntryPoint
1631+
task {
1632+
let path =
1633+
env.Entrypoints
1634+
|> Seq.map ProjectGraphEntryPoint
16241635

16251636

1626-
// Evaluation
1627-
use pc = projectCollection ()
1637+
// Evaluation
1638+
use pc = projectCollection ()
16281639

1629-
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
1640+
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
16301641

1631-
// Execution
1632-
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
1633-
let bm = new BuildManagerSession(buildParameters = bp)
1642+
// Execution
1643+
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
1644+
let bm = new BuildManagerSession(buildParameters = bp)
16341645

1635-
try
1636-
use cts = new CancellationTokenSource()
1637-
cts.CancelAfter(TimeSpan.FromSeconds(1.))
1646+
try
1647+
use cts = new CancellationTokenSource()
1648+
cts.CancelAfter(TimeSpan.FromSeconds(1.))
16381649

1639-
let build = ProjectLoader2.Execution(bm, graph, ct = cts.Token)
1650+
let build = ProjectLoader2.Execution(bm, graph, ct = cts.Token)
16401651

1641-
Task.RunSynchronously build
1642-
|> ignore
1643-
with
1644-
| :? OperationCanceledException -> ()
1645-
| e -> reraise ()
1652+
Task.RunSynchronously build
1653+
|> ignore
1654+
with
1655+
| :? OperationCanceledException -> ()
1656+
| e -> Exception.reraiseAny e
16461657

1658+
}
16471659
)
16481660
]
16491661

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace classlibf1
2+
3+
module Say =
4+
let hello name =
5+
printfn "Hello %s" name
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Library.fs" />
10+
</ItemGroup>
11+
12+
<Target Name="SleepTask" BeforeTargets="CoreCompile">
13+
<Exec Command="powershell -Command &quot;Start-Sleep -Seconds 1&quot;"
14+
Condition="'$(OS)' == 'Windows_NT'"
15+
IgnoreExitCode="true" />
16+
<Exec Command="sleep 1"
17+
Condition="'$(OS)' != 'Windows_NT'"
18+
IgnoreExitCode="true" />
19+
</Target>
20+
21+
</Project>

0 commit comments

Comments
 (0)