This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #876, Correct handling of quotation marks in commands
- don't strip quotes surrounding command-line arguments when used in `scripts` - prevented command paths and grouping arguments containing spaces - pass `preserveSurroundingQuotes` into `CommandGrammar` to control stripping - use `cmd /s /c` when executing `scripts` commands on Windows - allows `&&` and similar - add functional tests of commands and scripts (together with `dnu restore`) - no `dnu restore` for .NET Core due to extra time required note: - `CommandGrammar` may need additional generalizations - e.g. unquoted term can't contain more than one escape sequence - but it's probably good enough for now - _not_ adding quotes around variables replacements inserted into commands - no way of determining if replacement is already quoted - basically, leave it to project.json author to perform appropriate quoting for their platform nits: - let VS do its thing with test services - make `CommandGrammar` constructor private; used only in `Process()` method
- Loading branch information
Showing
5 changed files
with
304 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
test/Microsoft.Framework.PackageManager.FunctionalTests/DnuRestoreTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.Framework.CommonTestUtils; | ||
using Microsoft.Framework.PackageManager.FunctionalTests; | ||
using Xunit; | ||
|
||
namespace Microsoft.Framework.PackageManager | ||
{ | ||
[Collection(nameof(PackageManagerFunctionalTestCollection))] | ||
public class DnuRestoreTests | ||
{ | ||
private readonly PackageManagerFunctionalTestFixture _fixture; | ||
|
||
public DnuRestoreTests(PackageManagerFunctionalTestFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
public static IEnumerable<object[]> RuntimeComponents | ||
{ | ||
get | ||
{ | ||
return TestUtils.GetRuntimeComponentsCombinations(); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(RuntimeComponents))] | ||
public void DnuRestore_ExecutesScripts(string flavor, string os, string architecture) | ||
{ | ||
bool isWindows = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows"; | ||
var environment = new Dictionary<string, string> | ||
{ | ||
{ "DNX_TRACE", "0" }, | ||
}; | ||
|
||
var expectedPreContent = | ||
@"""one"" | ||
""two"" | ||
"">three"" | ||
""four"" | ||
"; | ||
var expectedPostContent = | ||
@"""five"" | ||
""six"" | ||
""argument seven"" | ||
""argument eight"" | ||
"; | ||
|
||
string projectJsonContent; | ||
string scriptContent; | ||
string scriptName; | ||
if (isWindows) | ||
{ | ||
projectJsonContent = | ||
@"{ | ||
""frameworks"": { | ||
""dnx451"": { } | ||
}, | ||
""scripts"": { | ||
""prerestore"": [ | ||
""script.cmd one two > pre"", | ||
""script.cmd \>three >> pre; script.sh \ four >> pre"" | ||
], | ||
""postrestore"": [ | ||
""\""%project:Directory%/script.cmd\"" five six > post"", | ||
""\""%project:Directory%/script.cmd\"" \""argument seven\"" \""argument eight\"" >> post"" | ||
] | ||
} | ||
}"; | ||
scriptContent = | ||
@"@echo off | ||
:argumentStart | ||
if ""%~1""=="""" goto argumentEnd | ||
echo ""%~1"" | ||
shift | ||
goto argumentStart | ||
:argumentEnd"; | ||
scriptName = "script.cmd"; | ||
} | ||
else | ||
{ | ||
projectJsonContent = | ||
@"{ | ||
""frameworks"": { | ||
""dnx451"": { } | ||
}, | ||
""scripts"": { | ||
""prerestore"": [ | ||
""script.sh one two > pre"", | ||
""script.sh ^>three >> pre && script.cmd ^ four >> pre"" | ||
], | ||
""postrestore"": [ | ||
""\""%project:Directory%/script.sh\"" five six > post"", | ||
""\""%project:Directory%/script.sh\"" \""argument seven\"" \""argument eight\"" >> post"" | ||
] | ||
} | ||
}"; | ||
scriptContent = | ||
@"#!/bin/bash --restricted | ||
set -o errexit | ||
for arg in ""$@""; do | ||
printf ""\""%s\""\n"" ""$arg"" | ||
done"; | ||
scriptName = "script.sh"; | ||
} | ||
|
||
var projectStructure = | ||
$@"{{ | ||
'.': ['project.json', '{ scriptName }'] | ||
}}"; | ||
var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); | ||
using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) | ||
{ | ||
DirTree.CreateFromJson(projectStructure) | ||
.WithFileContents("project.json", projectJsonContent) | ||
.WithFileContents(scriptName, scriptContent) | ||
.WriteTo(testEnv.ProjectPath); | ||
FileOperationUtils.MarkExecutable(Path.Combine(runtimeHomePath, scriptName)); | ||
|
||
string output; | ||
string error; | ||
var exitCode = DnuTestUtils.ExecDnu( | ||
runtimeHomePath, | ||
subcommand: "restore", | ||
arguments: null, | ||
stdOut: out output, | ||
stdErr: out error, | ||
environment: environment, | ||
workingDir: testEnv.ProjectPath); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Empty(error); | ||
Assert.Contains("Executing script 'prerestore' in project.json", output); | ||
Assert.Contains("Executing script 'postrestore' in project.json", output); | ||
|
||
var preContent = File.ReadAllText(Path.Combine(testEnv.ProjectPath, "pre")); | ||
Assert.Equal(expectedPreContent, preContent); | ||
var postContent = File.ReadAllText(Path.Combine(testEnv.ProjectPath, "post")); | ||
Assert.Equal(expectedPostContent, postContent); | ||
} | ||
} | ||
} | ||
} |