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-02-18 06:51:43 -08:00
|
|
|
private static readonly string s_timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
|
2022-02-10 15:58:01 -06:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-18 06:51:43 -08:00
|
|
|
public void ExecuteCmd(string args, ITestOutputHelper outputHelper)
|
2022-01-21 07:59:36 -06:00
|
|
|
{
|
|
|
|
(Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess(DotNetPath, args, outputHelper);
|
|
|
|
|
|
|
|
Assert.Equal(0, executeResult.Process.ExitCode);
|
|
|
|
}
|
2022-02-18 06:51:43 -08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create a new .NET project and return the path to the created project folder.
|
|
|
|
/// </summary>
|
|
|
|
public string ExecuteNew(string projectType, string language, string name, ITestOutputHelper outputHelper)
|
|
|
|
{
|
|
|
|
string outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), $"projects-{s_timestamp}", name);
|
|
|
|
|
|
|
|
ExecuteCmd($"new {projectType} --language \"{language}\" --name {name} --output {outputDirectory}", outputHelper);
|
|
|
|
|
|
|
|
return outputDirectory;
|
|
|
|
}
|
2022-01-21 07:59:36 -06:00
|
|
|
}
|