Пример #1
0
        /// <summary>
        /// Invokes a call to scalar using the arguments specified
        /// </summary>
        /// <param name="args">The arguments to use when invoking scalar</param>
        /// <param name="expectedExitCode">
        /// What the expected exit code should be.
        /// >= than 0 to check the exit code explicitly
        /// -1 = Fail if the exit code is 0
        /// -2 = Do not check the exit code (Default)
        /// </param>
        /// <param name="trace">What to set the GIT_TRACE environment variable to</param>
        /// <param name="standardInput">What to write to the standard input stream</param>
        /// <param name="internalParameter">The internal parameter to set in the arguments</param>
        /// <returns></returns>
        private string CallScalar(
            string args,
            int expectedExitCode     = DoNotCheckExitCode,
            string trace             = null,
            string standardInput     = null,
            string internalParameter = null,
            string workingDirectory  = null)
        {
            ProcessStartInfo processInfo = new ProcessStartInfo(this.pathToScalar);

            if (internalParameter == null)
            {
                internalParameter = ScalarHelpers.GetInternalParameter();
            }

            processInfo.Arguments = args + " " + TestConstants.InternalUseOnlyFlag + " " + internalParameter;

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                processInfo.WorkingDirectory = workingDirectory;
            }

            processInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;
            if (standardInput != null)
            {
                processInfo.RedirectStandardInput = true;
            }

            if (trace != null)
            {
                processInfo.EnvironmentVariables["GIT_TRACE"] = trace;
            }

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                processInfo.WorkingDirectory = workingDirectory;
            }

            using (Process process = Process.Start(processInfo))
            {
                if (standardInput != null)
                {
                    process.StandardInput.Write(standardInput);
                    process.StandardInput.Close();
                }

                string result = process.StandardOutput.ReadToEnd();
                process.WaitForExit();

                if (expectedExitCode >= SuccessExitCode)
                {
                    process.ExitCode.ShouldEqual(expectedExitCode, result);
                }
                else if (expectedExitCode == ExitCodeShouldNotBeZero)
                {
                    process.ExitCode.ShouldNotEqual(SuccessExitCode, "Exit code should not be zero");
                }

                return(result);
            }
        }
Пример #2
0
 public string GetPackRoot(FileSystemRunner fileSystem)
 {
     return(Path.Combine(ScalarHelpers.GetObjectsRootFromGitConfig(this.RepoRoot), "pack"));
 }