2022-01-21 07:59:36 -06:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
|
|
|
|
|
|
|
internal class DotNetHelper
|
|
|
|
{
|
2022-02-10 15:58:01 -06:00
|
|
|
private static readonly object s_lockObj = new object();
|
|
|
|
|
2022-01-21 07:59:36 -06:00
|
|
|
public string DotNetPath { get; }
|
|
|
|
|
|
|
|
public DotNetHelper(ITestOutputHelper outputHelper)
|
|
|
|
{
|
2022-02-10 15:58:01 -06:00
|
|
|
lock (s_lockObj)
|
2022-01-21 07:59:36 -06:00
|
|
|
{
|
2022-02-10 15:58:01 -06:00
|
|
|
if (!Directory.Exists(Config.DotNetDirectory))
|
2022-01-21 07:59:36 -06:00
|
|
|
{
|
2022-02-10 15:58:01 -06:00
|
|
|
if (!File.Exists(Config.DotNetTarballPath))
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"Tarball path '{Config.DotNetTarballPath}' specified in {Config.DotNetTarballPathEnv} does not exist.");
|
|
|
|
}
|
2022-01-21 07:59:36 -06:00
|
|
|
|
2022-02-10 15:58:01 -06:00
|
|
|
Directory.CreateDirectory(Config.DotNetDirectory);
|
|
|
|
ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"xzf {Config.DotNetTarballPath} -C {Config.DotNetDirectory}", outputHelper);
|
|
|
|
}
|
2022-01-21 07:59:36 -06:00
|
|
|
}
|
|
|
|
|
2022-02-10 15:58:01 -06:00
|
|
|
DotNetPath = Path.Combine(Config.DotNetDirectory, "dotnet");
|
2022-01-21 07:59:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ExecuteDotNetCmd(string args, ITestOutputHelper outputHelper)
|
|
|
|
{
|
|
|
|
(Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess(DotNetPath, args, outputHelper);
|
|
|
|
|
|
|
|
Assert.Equal(0, executeResult.Process.ExitCode);
|
|
|
|
}
|
|
|
|
}
|