forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuilderTargetsTest.cs
75 lines (71 loc) · 3.08 KB
/
BuilderTargetsTest.cs
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 System.Text;
using System.Diagnostics;
using NUnit.Framework;
namespace MonoGame.Tests.ContentPipeline
{
[TestFixture]
public class BuilderTargetsTest
{
string[] msBuildFolders = new string[]
{
Path.Combine ("MSBuild", "15.0", "Bin", "MSBuild.exe"),
Path.Combine ("MSBuild", "14.0", "Bin", "MSBuild.exe"),
};
string FindBuildTool(string buildTool)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT && buildTool == "msbuild")
{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
foreach (var path in msBuildFolders)
{
if (File.Exists(Path.Combine(programFiles, path)))
return Path.Combine(programFiles, path);
}
}
return buildTool;
}
bool RunBuild(string buildTool, string projectFile, params string[] parameters)
{
var root = Path.GetDirectoryName(typeof(BuilderTargetsTest).Assembly.Location);
var psi = new ProcessStartInfo(FindBuildTool(buildTool))
{
Arguments = projectFile + " /t:BuildContent " + string.Join(" ", parameters) + " /noconsolelogger \"/flp1:LogFile=build.log;Encoding=UTF-8;Verbosity=Diagnostic\"",
WorkingDirectory = root,
UseShellExecute = true,
};
using (var process = Process.Start(psi))
{
process.WaitForExit();
return process.ExitCode == 0;
}
}
static object[] BuilderTargetsBuildTools = new object[] {
"msbuild",
"xbuild",
};
[Test]
[TestCaseSource("BuilderTargetsBuildTools")]
#if DESKTOPGL
[Ignore("Fails on Mac build server with xbuild for some reason.")]
#else
[Ignore("This test need to be rewritten to properly test Tools\\MonoGame.Content.Builder instead of the old builder targets.")]
#endif
public void BuildSimpleProject(string buildTool)
{
if (buildTool == "xbuild" && Environment.OSVersion.Platform == PlatformID.Win32NT)
Assert.Ignore("Skipping xbuild tests on windows");
var root = Path.GetDirectoryName(typeof(BuilderTargetsTest).Assembly.Location);
var outputPath = Path.Combine(root, "Assets", "Projects", "Content", "bin");
if (Directory.Exists(outputPath))
Directory.Delete(outputPath, recursive: true);
var result = RunBuild(buildTool, Path.Combine("Assets", "Projects", "BuildSimpleProject.csproj"), new string[] {
"/p:MonoGameContentBuilderExe=" + Path.Combine(root, "MGCB.exe")
});
Assert.AreEqual(true, result, "Content Build should have succeeded.");
var contentFont = Path.Combine(outputPath, "DesktopGL", "Content", "ContentFont.xnb");
Assert.IsTrue(File.Exists(contentFont), "'" + contentFont + "' should exist.");
}
}
}