mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Config no longer logs a warning when saved in integration test
Supersedes #6108 See https://github.com/space-wizards/space-station-14/issues/39196
This commit is contained in:
@@ -44,6 +44,7 @@ END TEMPLATE-->
|
||||
### Bugfixes
|
||||
|
||||
* `LayoutContainer.SetMarginsPreset` and `SetAnchorAndMarginPreset` now correctly use the provided control's top anchor when calculating the margins for its presets; it previously used the bottom anchor instead. This may result in a few UI differences, by a few pixels at most.
|
||||
* `IConfigurationManager` no longer logs a warning when saving configuration in an integration test.
|
||||
|
||||
### Other
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -25,7 +26,7 @@ namespace Robust.Shared.Configuration
|
||||
|
||||
private const char TABLE_DELIMITER = '.';
|
||||
protected readonly Dictionary<string, ConfigVar> _configVars = new();
|
||||
private string? _configFile;
|
||||
private ConfigFileStorage? _configFile;
|
||||
protected bool _isServer;
|
||||
|
||||
protected readonly ReaderWriterLockSlim Lock = new();
|
||||
@@ -182,7 +183,7 @@ namespace Robust.Shared.Configuration
|
||||
{
|
||||
using var file = File.OpenRead(configFile);
|
||||
var result = LoadFromTomlStream(file);
|
||||
_configFile = configFile;
|
||||
SetSaveFile(configFile);
|
||||
_sawmill.Info($"Configuration loaded from file");
|
||||
return result;
|
||||
}
|
||||
@@ -195,7 +196,12 @@ namespace Robust.Shared.Configuration
|
||||
|
||||
public void SetSaveFile(string configFile)
|
||||
{
|
||||
_configFile = configFile;
|
||||
_configFile = new ConfigFileStorageDisk { Path = configFile };
|
||||
}
|
||||
|
||||
public void SetVirtualConfig()
|
||||
{
|
||||
_configFile = new ConfigFileStorageVirtual();
|
||||
}
|
||||
|
||||
public void CheckUnusedCVars()
|
||||
@@ -312,8 +318,27 @@ namespace Robust.Shared.Configuration
|
||||
var memoryStream = new MemoryStream();
|
||||
SaveToTomlStream(memoryStream, cvars);
|
||||
memoryStream.Position = 0;
|
||||
using var file = File.Create(_configFile);
|
||||
memoryStream.CopyTo(file);
|
||||
|
||||
switch (_configFile)
|
||||
{
|
||||
case ConfigFileStorageDisk disk:
|
||||
{
|
||||
using var file = File.Create(disk.Path);
|
||||
memoryStream.CopyTo(file);
|
||||
break;
|
||||
}
|
||||
case ConfigFileStorageVirtual @virtual:
|
||||
{
|
||||
@virtual.Stream.SetLength(0);
|
||||
memoryStream.CopyTo(@virtual.Stream);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new UnreachableException();
|
||||
}
|
||||
}
|
||||
|
||||
_sawmill.Info($"config saved to '{_configFile}'.");
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -954,6 +979,30 @@ namespace Robust.Shared.Configuration
|
||||
}
|
||||
|
||||
protected delegate void ValueChangedDelegate(object value, in CVarChangeInfo info);
|
||||
|
||||
private abstract class ConfigFileStorage;
|
||||
|
||||
private sealed class ConfigFileStorageDisk : ConfigFileStorage
|
||||
{
|
||||
public required string Path;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Path;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ConfigFileStorageVirtual : ConfigFileStorage
|
||||
{
|
||||
// I did not realize when adding this class that there is currently no way to *load* this data again.
|
||||
// Oh well, might be useful for a future unit test.
|
||||
public readonly MemoryStream Stream = new();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "<VIRTUAL>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -10,6 +10,15 @@ namespace Robust.Shared.Configuration
|
||||
void LoadCVarsFromAssembly(Assembly assembly);
|
||||
void LoadCVarsFromType(Type containingType);
|
||||
|
||||
/// <summary>
|
||||
/// Indicate that config should be stored in-memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This suppresses warnings from <see cref="IConfigurationManager.SaveToFile"/>
|
||||
/// if no config is otherwise loaded.
|
||||
/// </remarks>
|
||||
void SetVirtualConfig();
|
||||
|
||||
void Initialize(bool isServer);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
@@ -765,6 +765,8 @@ namespace Robust.UnitTesting
|
||||
(CVars.ResCheckBadFileExtensions.Name, "false")
|
||||
});
|
||||
|
||||
cfg.SetVirtualConfig();
|
||||
|
||||
server.ContentStart = Options?.ContentStart ?? false;
|
||||
var logHandler = Options?.OverrideLogHandler ?? (() => new TestLogHandler(cfg, "SERVER", _testOut));
|
||||
if (server.Start(serverOptions, logHandler))
|
||||
@@ -1033,6 +1035,8 @@ namespace Robust.UnitTesting
|
||||
(CVars.ResCheckBadFileExtensions.Name, "false")
|
||||
});
|
||||
|
||||
cfg.SetVirtualConfig();
|
||||
|
||||
GameLoop = new IntegrationGameLoop(DependencyCollection.Resolve<IGameTiming>(),
|
||||
_fromInstanceWriter, _toInstanceReader);
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Log;
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Configuration;
|
||||
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
[TestFixture]
|
||||
[TestOf(typeof(ConfigurationManagerTest))]
|
||||
internal sealed class ConfigurationIntegrationTest : RobustIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestSaveNoWarningServer()
|
||||
{
|
||||
using var server = StartServer(new ServerIntegrationOptions
|
||||
{
|
||||
FailureLogLevel = LogLevel.Warning
|
||||
});
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var cfg = server.Resolve<IConfigurationManager>();
|
||||
cfg.SaveToFile();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSaveNoWarningClient()
|
||||
{
|
||||
using var server = StartClient(new ClientIntegrationOptions
|
||||
{
|
||||
FailureLogLevel = LogLevel.Warning
|
||||
});
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var cfg = server.Resolve<IConfigurationManager>();
|
||||
cfg.SaveToFile();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user