Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/Configuration/TestModuleRules.cs
chris constantinescu 8c968941f9 UBT TestMode that allows building a test executable for an associated target.
- Each module can now have a Tests folder at its root containing low level tests written with Catch2
- Used like this: UnrealBuildTool.exe -Mode=Test TargetName Platform Configuration
- It creates a test executable that's associated with the specified build Target and it includes all the tests for the Target AND all its dependencies as well
- When building without -Mode=Test it will omit the Tests folder contents from compilation: in theory we never allowed folders named Tests at the root of modules, but there might be isolated exceptions where we didn't validate folder names - in this case we will need to move that Tests folder one level up for example
- Code paths for test and non-test builds are entirely separated

#jira UE-135280
#rb Jerome.Delattre
#preflight 61e839d5276892ce10759205

[CL 18663474 by chris constantinescu in ue5-main branch]
2022-01-19 15:00:37 -05:00

76 lines
2.2 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Core;
using System.IO;
namespace UnrealBuildTool
{
/// <summary>
/// ModuleRules extension for low level tests.
/// </summary>
public class TestModuleRules : ModuleRules
{
/// <summary>
/// Associated tested module of this test module.
/// </summary>
public ModuleRules TestedModule { get; private set; }
/// <summary>
/// Constructs a TestModuleRules object with an associated tested module.
/// </summary>
public TestModuleRules(ModuleRules TestedModule) : base(new ReadOnlyTargetRules(TestedModule.Target.TestTarget))
{
this.TestedModule = TestedModule;
Name = TestedModule.Name + "Tests";
if (!string.IsNullOrEmpty(TestedModule.ShortName))
{
ShortName = TestedModule.ShortName + "Tests";
}
File = FileReference.Combine(UnrealBuildTool.EngineSourceDirectory, "UnrealBuildTool", "Configuration", "TestModuleRules.cs");
Directory = DirectoryReference.Combine(TestedModule.Directory, "Tests");
Context = TestedModule.Context;
PCHUsage = PCHUsageMode.NoPCHs;
PrecompileForTargets = PrecompileTargetsType.None;
if (Target.Configuration == UnrealTargetConfiguration.Debug && Target.Platform == UnrealTargetPlatform.Linux)
{
OptimizeCode = CodeOptimization.Never;
}
bAllowConfidentialPlatformDefines = true;
bLegalToDistributeObjectCode = true;
// Required false for catch.hpp
bUseUnity = false;
// Disable exception handling so that tests can assert for exceptions
bEnableObjCExceptions = false;
bEnableExceptions = false;
PrivateDependencyModuleNames.AddRange(
new string[] {
"Core",
"Projects",
"LowLevelTestsRunner"
});
PrivateIncludePaths.Add("Runtime/Launch/Private");
PrivateIncludePathModuleNames.Add("Launch");
// Tests can refer to tested module's Public and Private paths
PublicIncludePaths.Add(Path.Combine(TestedModule.ModuleDirectory, "Public"));
PrivateIncludePaths.Add(Path.Combine(TestedModule.ModuleDirectory, "Private"));
// Platforms specific setup
if (Target.Platform == UnrealTargetPlatform.Android)
{
PublicDefinitions.Add("CATCH_CONFIG_NOSTDOUT");
}
}
}
}