Skip to content

Commit

Permalink
Fix runtime config tests (#5137)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Jul 9, 2024
1 parent 20fd1f1 commit 532e6ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
// 2) making sure we still make the project executable (and so we actually do get runtimeconfig unless the user tries hard to not make the test and EXE).
var suffix = _targetFramework.Version == "1.0.0.0" ? "latest" : $"{new Version(_targetFramework.Version).Major}.{new Version(_targetFramework.Version).Minor}";
var testhostRuntimeConfig = Path.Combine(Path.GetDirectoryName(testHostNextToRunner)!, $"testhost-{suffix}.runtimeconfig.json");
if (!File.Exists(testhostRuntimeConfig))
if (!_fileHelper.Exists(testhostRuntimeConfig))
{
testhostRuntimeConfig = Path.Combine(Path.GetDirectoryName(testHostNextToRunner)!, $"testhost-latest.runtimeconfig.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,15 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunner
// we can't put in a "default" value, and we don't have other way to determine if this provided value is the
// runtime default or the actual value that user provided, so right now the default will use the latest, instead
// or the more correct 1.0, it should be okay, as that version is not supported anymore anyway
[DataRow("netcoreapp3.1", "3.1")]
[DataRow("net5.0", "5.0")]
[DataRow("netcoreapp3.1", "3.1", true)]
[DataRow("net5.0", "5.0", true)]

// net6.0 is currently the latest released version, but it still has it's own runtime config, it is not the same as
// "latest" which means the latest you have on system. So if you have only 5.0 SDK then net6.0 will fail because it can't find net6.0,
// but latest would use net5.0 because that is the latest one on your system.
[DataRow("net6.0", "6.0")]
public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunnerIfTesthostDllIsNoFoundAndDepsFileNotFoundWithTheCorrectTfm(string tfm, string suffix)
[DataRow("net6.0", "6.0", true)]
[DataRow("net6.0", "latest", false)]
public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunnerIfTesthostDllIsNoFoundAndDepsFileNotFoundWithTheCorrectTfm(string tfm, string suffix, bool runtimeConfigExists)
{
// Absolute path to the source directory
var sourcePath = Path.Combine(_temp, "test.dll");
Expand All @@ -687,6 +688,8 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunner
var testhostNextToRunner = Path.Combine(here, "testhost.dll");
_mockFileHelper.Setup(ph => ph.Exists(testhostNextToRunner)).Returns(true);

_mockFileHelper.Setup(ph => ph.Exists(It.Is<string>(s => s.Contains($"{suffix}.runtimeconfig.json")))).Returns(runtimeConfigExists);

_dotnetHostManager.Initialize(_mockMessageLogger.Object, $"<RunSettings><RunConfiguration><TargetFrameworkVersion>{tfm}</TargetFrameworkVersion></RunConfiguration></RunSettings>");
var startInfo = _dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, _defaultConnectionInfo);

Expand Down

0 comments on commit 532e6ce

Please sign in to comment.