Welcome to mirror list, hosted at ThFree Co, Russian Federation.

HelloWorldTest.cs « ILLink.Tasks.Tests « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 23e4662c20628d287f8bf6a6bc7e240a96ef2b47 (plain)
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
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace ILLink.Tests
{
	public class HelloWorldTest : IntegrationTestBase
	{
		private string csproj;

		public HelloWorldTest(ITestOutputHelper output) : base(output) {
			csproj = SetupProject();
		}

		public string SetupProject()
		{
			string projectRoot = "helloworld";
			string csproj = Path.Combine(projectRoot, $"{projectRoot}.csproj");

			if (File.Exists(csproj)) {
				output.WriteLine($"using existing project {csproj}");
				return csproj;
			}

			if (Directory.Exists(projectRoot)) {
				Directory.Delete(projectRoot, true);
			}

			Directory.CreateDirectory(projectRoot);
			int ret = Dotnet("new console", projectRoot);
			if (ret != 0) {
				output.WriteLine("dotnet new failed");
				Assert.True(false);
			}

			AddLinkerReference(csproj);

			return csproj;
		}

		[Fact]
		public void RunHelloWorldStandalone()
		{
			string executablePath = BuildAndLink(csproj, selfContained: true);
			CheckOutput(executablePath, selfContained: true);
		}

		[Fact]
		public void RunHelloWorldPortable()
		{
			string target = BuildAndLink(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.True(commandOutput.Contains("Hello World!"));
		}
	}
}