Files
Garry Newman d95169d8fa Unit Test Cleanup (#5064)
* Move all unit tests to Engine/Tests
* Fix Margin.EdgeSubtract
* Fix Capsule.Contains
* EnvironmentVariables.Remove if it's null
* Fixed ray trace never returning startedsolid
* Fix HistoryList.Navigate on empty list
* Fix GameObject.WorldPosition accepting NaNs
* Fix flex: initial expanding to the wrong grow/shrink
* Translation.TryConvert shouldn't throw on invalid enum strings
* Skip sound file tests on machines with no audio device
2026-06-12 13:23:50 +01:00

53 lines
2.3 KiB
C#

global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using Sandbox;
global using System.Linq;
global using System.Threading.Tasks;
global using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using Sandbox.Engine;
using Sandbox.Internal;
using System;
[assembly: Parallelize( Workers = 0, Scope = ExecutionScope.MethodLevel )]
[TestClass]
public class TestInit
{
[AssemblyInitialize]
public static void AssemblyInitialize( TestContext context )
{
// Engine-attached tier: load the native engine DLLs so interop works, but never boot
// the engine loop. Tests that need a booted engine belong in Sandbox.Test.Integration;
// tests that need no native code at all belong in Sandbox.Test.Unit.
var gameFolder = System.Environment.GetEnvironmentVariable( "FACEPUNCH_ENGINE", EnvironmentVariableTarget.Process );
if ( gameFolder is null ) throw new Exception( "FACEPUNCH_ENGINE not found" );
Environment.CurrentDirectory = gameFolder;
NetCore.InitializeInterop( gameFolder );
Api.Init();
// Usually this, is created by native source 2, we have to do it manually here, as we don't init native source2 for this assembly.
System.IO.Directory.CreateDirectory( ".source2/" );
Application.IsUnitTest = true;
GlobalContext.Current.TypeLibrary = new TypeLibrary();
GlobalContext.Current.UISystem = new UISystem();
GlobalContext.Current.TypeLibrary.AddIntrinsicTypes();
GlobalContext.Current.TypeLibrary.AddAssembly( typeof( Vector3 ).Assembly, false );
GlobalContext.Current.TypeLibrary.AddAssembly( typeof( EngineLoop ).Assembly, false );
GlobalContext.Current.TypeLibrary.AddAssembly( typeof( Facepunch.ActionGraphs.ActionGraph ).Assembly, false );
GlobalContext.Current.TypeLibrary.AddAssembly( typeof( TestInit ).Assembly, true );
GlobalToolsNamespace.EditorTypeLibrary = new TypeLibrary();
GlobalToolsNamespace.EditorTypeLibrary.AddIntrinsicTypes();
GlobalToolsNamespace.EditorTypeLibrary.AddAssembly( typeof( Vector3 ).Assembly, false );
GlobalToolsNamespace.EditorTypeLibrary.AddAssembly( typeof( EngineLoop ).Assembly, false );
GlobalToolsNamespace.EditorTypeLibrary.AddAssembly( typeof( Facepunch.ActionGraphs.ActionGraph ).Assembly, false );
GlobalToolsNamespace.EditorTypeLibrary.AddAssembly( typeof( TestInit ).Assembly, true );
}
}