1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace ILLink.Tests
{
public class HelloWorldFixture : ProjectFixture
{
public string csproj;
public HelloWorldFixture (IMessageSink diagnosticMessageSink) : base (diagnosticMessageSink)
{
csproj = SetupProject ();
}
public string SetupProject()
{
string projectRoot = "helloworld";
string csproj = Path.Combine(projectRoot, $"{projectRoot}.csproj");
if (File.Exists(csproj)) {
LogMessage ($"using existing project {csproj}");
return csproj;
}
if (Directory.Exists(projectRoot)) {
Directory.Delete(projectRoot, true);
}
Directory.CreateDirectory(projectRoot);
int ret = CommandHelper.Dotnet("new console", projectRoot);
if (ret != 0) {
LogMessage ("dotnet new failed");
Assert.True(false);
}
AddLinkerReference(csproj);
return csproj;
}
}
public class HelloWorldTest : IntegrationTestBase, IClassFixture<HelloWorldFixture>
{
HelloWorldFixture fixture;
public HelloWorldTest(HelloWorldFixture fixture, ITestOutputHelper helper) : base(helper) {
this.fixture = fixture;
}
[Fact]
public void RunHelloWorldStandalone()
{
string executablePath = BuildAndLink(fixture.csproj, selfContained: true);
CheckOutput(executablePath, selfContained: true);
}
[Fact]
public void RunHelloWorldPortable()
{
string target = BuildAndLink(fixture.csproj, selfContained: false);
CheckOutput(target, selfContained: false);
}
void CheckOutput(string target, bool selfContained = false)
{
int ret = RunApp(target, out string commandOutput, selfContained: selfContained);
Assert.True(ret == 0);
Assert.Contains("Hello World!", commandOutput);
}
}
}
|