Esempio n. 1
0
        public void CanSetLocationIntoSubDirectory()
        {
            var rootPath = base.SetupFileSystemWithStructure(new[] {
                "/FolderA/SubFolderA/FileA".NormalizeSlashes()
            });

            var result = TestHost.ExecuteWithZeroErrors(
                "Set-Location " + rootPath,
                "(Get-Location).Path");

            result.Trim().ShouldEqual((string)rootPath);

            result = TestHost.ExecuteWithZeroErrors(
                "Set-Location " + (rootPath + "/FolderA").NormalizeSlashes(),
                "(Get-Location).Path");


            result.Trim().ShouldEqual(((string)rootPath + "/FolderA").NormalizeSlashes());

            result = TestHost.ExecuteWithZeroErrors(
                "Set-Location " + (rootPath + "/FolderA/SubFolderA").NormalizeSlashes(),
                "(Get-Location).Path");

            result.Trim().PathShouldEqual(((string)rootPath + "/FolderA/SubFolderA").NormalizeSlashes());
        }
Esempio n. 2
0
        public static string Exec(this string command)
        {
            var result = TestHost.ExecuteWithZeroErrors(command);

            if (result.EndsWith(Environment.NewLine))
            {
                // trim the new-line at the end
                return(result.Substring(0, result.Length - Environment.NewLine.Length));
            }
            return(result);
        }
Esempio n. 3
0
        public void CDWithTwoPeriodsShouldMoveUpOneDirectory(string setLocationParam, string expectedLocation, string errorMessage)
        {
            var rootPath = base.SetupFileSystemWithStructure(new[] {
                "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"
            });

            var result = TestHost.ExecuteWithZeroErrors("Set-Location " + rootPath + "/a/b/c/d/e/f/g",
                                                        "Set-Location " + setLocationParam,
                                                        "(Get-Location).Path");

            result.Trim().PathShouldEqual(rootPath + expectedLocation);
        }
Esempio n. 4
0
        /// <summary>
        /// Catches the executable result and echoes it to the output.
        /// </summary>
        /// <param name="statements">statements to execute. The last statement has to return the result.</param>
        /// <returns>Executed command result.</returns>
        private static string CatchCommandResult(params string[] statements)
        {
            string[] temp = new string[statements.Length + 1];

            Array.Copy(statements, temp, statements.Length - 1);
            temp[temp.Length - 2] = string.Format("$result = ({0})", statements[statements.Length - 1]);
            temp[temp.Length - 1] = "$result";

            var result = TestHost.ExecuteWithZeroErrors(temp);

            return(result);
        }
Esempio n. 5
0
        public void AddMemberDefinitionWithInvalidCSharp()
        {
            string result = TestHost.ExecuteWithZeroErrors(
                "add-type -name Test -memberdefinition 'public WriteLine() ---'",
                "$compilerErrorCount = 0",
                "$error | ForEach-Object { if ( $_.FullyQualifiedErrorId -eq 'SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand') { $compilerErrorCount += 1 } }",
                "if ($compilerErrorCount -gt 0) { 'Multiple Compiler Errors' }"
                );

            // TODO: Original error record information is lost.
            StringAssert.Contains("Multiple Compiler Errors", result);
        }
Esempio n. 6
0
        public void AddTypeDefinitionWithInvalidCSharpCode()
        {
            string result = TestHost.ExecuteWithZeroErrors(
                "Add-Type -TypeDefinition 'public class ErrorTest --'",
                "$compilerErrorCount = 0",
                "$error | ForEach-Object { if ( $_.FullyQualifiedErrorId -eq 'SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand') { $compilerErrorCount += 1 } }",
                "if ($compilerErrorCount -gt 0) { 'Compiler error reported' }"
                );

            // TODO: Original error record information is lost.
            StringAssert.Contains("Compiler error reported", result);
        }
        public void CDToInvalidDirectoryShouldThrowError()
        {
            var currentLocation = "(Get-Location).Path".Exec();

            var result = TestHost.ExecuteWithZeroErrors("set-location thisFolderReallyShouldNotExistNoReallyItShouldNotBeAnywhereOnAnyDiskAnywherePERIOD");

            result.ShouldContain("The path does not exist");

            var currentLocationAfterBadCD = "(Get-Location).Path".Exec();

            currentLocation.PathShouldEqual(currentLocationAfterBadCD);
        }
Esempio n. 8
0
        public void AddTypeDefinitionFromFileWithInvalidCSharpCode()
        {
            string fileName = CreateTempFile("AddTypeDefinitionFromFileWithInvalidCSharpCode.cs", "public class ErrorTest --");
            string result   = TestHost.ExecuteWithZeroErrors(
                "Add-Type -Path '" + fileName + "'",
                "$compilerErrorCount = 0",
                "$error | ForEach-Object { if ( $_.FullyQualifiedErrorId -eq 'SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand') { $compilerErrorCount += 1 } }",
                "if ($compilerErrorCount -gt 0) { 'Compiler error reported' }"
                );

            // TODO: Original error record information is lost.
            //StringAssert.Contains("error[0].FullyQualifiedErrorId=COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand", result);
            StringAssert.Contains("Compiler error reported", result);
        }
Esempio n. 9
0
        /// <summary>
        /// Catches the executable result and echoes it to the output.
        /// </summary>
        /// <param name="command">Execution command.</param>
        /// <returns>Executed command result.</returns>
        private static string CatchCommandResult(string command)
        {
            var result = TestHost.ExecuteWithZeroErrors(string.Format("$result = ({0})", command), "$result");

            return(result);
        }