Skip to content

Commit

Permalink
Use a shorter path for test working directories, get rid of Stage 0 p…
Browse files Browse the repository at this point in the history
…roject.json based CLI
  • Loading branch information
dsplaisted committed Aug 30, 2017
1 parent fd66cdc commit 4c3b13e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 313 deletions.
20 changes: 0 additions & 20 deletions run-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ if (!(Test-Path $env:DOTNET_INSTALL_DIR))
mkdir $env:DOTNET_INSTALL_DIR | Out-Null
}

# We also need to pull down a project.json based CLI that is used by some tests
# so create another directory for that.
if (!$env:DOTNET_INSTALL_DIR_PJ)
{
$env:DOTNET_INSTALL_DIR_PJ="$RepoRoot\.dotnet_stage0PJ\$Architecture"
}

if (!(Test-Path $env:DOTNET_INSTALL_DIR_PJ))
{
mkdir $env:DOTNET_INSTALL_DIR_PJ | Out-Null
}



# Disable first run since we want to control all package sources
Expand All @@ -88,14 +76,6 @@ if ($LastExitCode -ne 0)
exit $LastExitCode
}

Write-Output "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR_PJ -Architecture ""$Architecture"" -Version 1.0.0-preview2-1-003177"
Invoke-Expression "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR_PJ -Architecture ""$Architecture"" -Version 1.0.0-preview2-1-003177"
if ($LastExitCode -ne 0)
{
Write-Output "The .NET CLI installation failed with exit code $LastExitCode"
exit $LastExitCode
}

# Put the stage0 on the path
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"

Expand Down
13 changes: 0 additions & 13 deletions run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ args=($temp)
[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$ARCHITECTURE
[ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR

# We also need to pull down a project.json based CLI that is used by some tests
# so create another directory for that.
[ -z "$DOTNET_INSTALL_DIR_PJ" ] && export DOTNET_INSTALL_DIR_PJ=$REPOROOT/.dotnet_stage0PJ/$ARCHITECTURE
[ -d "$DOTNET_INSTALL_DIR_PJ" ] || mkdir -p $DOTNET_INSTALL_DIR_PJ

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

# Enable verbose VS Test Console logging
Expand All @@ -163,14 +158,6 @@ if [ $EXIT_CODE != 0 ]; then
exit $EXIT_CODE
fi

# Install a project.json based CLI for use by tests
(set -x ; "$REPOROOT/scripts/obtain/dotnet-install.sh" --channel "master" --install-dir "$DOTNET_INSTALL_DIR_PJ" --architecture "$ARCHITECTURE" --version "1.0.0-preview2-1-003177")
EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
echo "run-build: Error: installing project-json based cli failed with exit code $EXIT_CODE." >&2
exit $EXIT_CODE
fi

# Put stage 0 on the PATH (for this shell only)
PATH="$DOTNET_INSTALL_DIR:$PATH"

Expand Down
28 changes: 9 additions & 19 deletions src/Microsoft.DotNet.TestFramework/TestAssetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class TestAssetInfo

public string AssetName { get; private set; }

public FileInfo DotnetExeFile { get; private set; }
public FileInfo DotnetExeFile => _testAssets.DotnetCsprojExe;

public string ProjectFilePattern { get; private set; }
public string ProjectFilePattern => "*.csproj";

public DirectoryInfo Root { get; private set; }

internal TestAssetInfo(DirectoryInfo root, string assetName, FileInfo dotnetExeFile, string projectFilePattern)
private TestAssets _testAssets { get; }

internal TestAssetInfo(DirectoryInfo root, string assetName, TestAssets testAssets)
{
if (root == null)
{
Expand All @@ -33,23 +35,16 @@ internal TestAssetInfo(DirectoryInfo root, string assetName, FileInfo dotnetExeF
throw new ArgumentException("Argument cannot be null or whitespace", nameof(assetName));
}

if (dotnetExeFile == null)
if (testAssets == null)
{
throw new ArgumentNullException(nameof(dotnetExeFile));
}

if (string.IsNullOrWhiteSpace(projectFilePattern))
{
throw new ArgumentException("Argument cannot be null or whitespace", nameof(projectFilePattern));
throw new ArgumentNullException(nameof(testAssets));
}

Root = root;

AssetName = assetName;

DotnetExeFile = dotnetExeFile;

ProjectFilePattern = projectFilePattern;
_testAssets = testAssets;
}

public TestAssetInstance CreateInstance([CallerMemberName] string callingMethod = "", string identifier = "")
Expand All @@ -71,12 +66,7 @@ internal IEnumerable<FileInfo> GetSourceFiles()

private DirectoryInfo GetTestDestinationDirectory(string callingMethod, string identifier)
{
#if NET451
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
string baseDirectory = AppContext.BaseDirectory;
#endif
return new DirectoryInfo(Path.Combine(baseDirectory, callingMethod + identifier, AssetName));
return _testAssets.CreateTestDirectory(AssetName, callingMethod, identifier);
}

private void ThrowIfTestAssetDoesNotExist()
Expand Down
45 changes: 9 additions & 36 deletions src/Microsoft.DotNet.TestFramework/TestAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public class TestAssets

private FileInfo _dotnetCsprojExe;

private FileInfo _dotnetProjectJsonExe;
private string _testWorkingFolder;

private const string ProjectJsonSearchPattern = "project.json";
public FileInfo DotnetCsprojExe => _dotnetCsprojExe;

private const string CsprojSearchPattern = "*.csproj";

public TestAssets(DirectoryInfo assetsRoot, FileInfo dotnetCsprojExe, FileInfo dotnetProjectJsonExe)
public TestAssets(DirectoryInfo assetsRoot, FileInfo dotnetCsprojExe, string testWorkingFolder)
{
if (assetsRoot == null)
{
Expand All @@ -35,11 +33,6 @@ public TestAssets(DirectoryInfo assetsRoot, FileInfo dotnetCsprojExe, FileInfo d
throw new ArgumentNullException(nameof(dotnetCsprojExe));
}

if (dotnetProjectJsonExe == null)
{
throw new ArgumentNullException(nameof(dotnetProjectJsonExe));
}

if (!assetsRoot.Exists)
{
throw new DirectoryNotFoundException($"Directory not found at '{assetsRoot}'");
Expand All @@ -50,16 +43,10 @@ public TestAssets(DirectoryInfo assetsRoot, FileInfo dotnetCsprojExe, FileInfo d
throw new FileNotFoundException("Csproj dotnet executable must exist", dotnetCsprojExe.FullName);
}

if (!dotnetProjectJsonExe.Exists)
{
throw new FileNotFoundException("project.json dotnet executable must exist", dotnetProjectJsonExe.FullName);
}

_root = assetsRoot;

_dotnetCsprojExe = dotnetCsprojExe;

_dotnetProjectJsonExe = dotnetProjectJsonExe;
_testWorkingFolder = testWorkingFolder;
}

public TestAssetInfo Get(string name)
Expand All @@ -74,24 +61,7 @@ public TestAssetInfo Get(string kind, string name)
return new TestAssetInfo(
assetDirectory,
name,
_dotnetCsprojExe,
CsprojSearchPattern);
}

public TestAssetInfo GetProjectJson(string name)
{
return GetProjectJson(TestAssetKinds.TestProjects, name);
}

public TestAssetInfo GetProjectJson(string kind, string name)
{
var assetDirectory = new DirectoryInfo(Path.Combine(_root.FullName, kind, name));

return new TestAssetInfo(
assetDirectory,
name,
_dotnetProjectJsonExe,
ProjectJsonSearchPattern);
this);
}

public DirectoryInfo CreateTestDirectory(string testProjectName = "temp", [CallerMemberName] string callingMethod = "", string identifier = "")
Expand All @@ -112,7 +82,10 @@ private string GetTestDestinationDirectoryPath(string testProjectName, string ca
#else
string baseDirectory = AppContext.BaseDirectory;
#endif
return Path.Combine(baseDirectory, callingMethod + identifier, testProjectName);
// Find the name of the assembly the test comes from based on the the base directory and how the output path has been constructed
string testAssemblyName = new DirectoryInfo(baseDirectory).Parent.Parent.Name;

return Path.Combine(_testWorkingFolder, testAssemblyName, callingMethod + identifier, testProjectName);
}
}
}
183 changes: 0 additions & 183 deletions test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs

This file was deleted.

Loading

0 comments on commit 4c3b13e

Please sign in to comment.