Пример #1
0
        /// <summary>
        /// Run a Smoke unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments        = element.GetAttribute("Arguments");
            string expectedErrors   = element.GetAttribute("ExpectedErrors");
            string expectedWarnings = element.GetAttribute("ExpectedWarnings");
            string extensions       = element.GetAttribute("Extensions");
            string toolsDirectory   = element.GetAttribute("ToolsDirectory");

            string        toolFile    = Path.Combine(toolsDirectory, "Smoke.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            // handle extensions
            if (!String.IsNullOrEmpty(extensions))
            {
                foreach (string extension in extensions.Split(';'))
                {
                    commandLine.AppendFormat(" -ext \"{0}\"", extension);
                }
            }

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);
        }
Пример #2
0
        /// <summary>
        /// Fix a failed test by replacing the expected file with the actual file
        /// </summary>
        /// <param name="expectedFile">The expected file</param>
        /// <param name="actualFile">The actual file</param>
        /// <param name="testName">The test name</param>
        /// <param name="differences">The list of differences between to files</param>
        /// <returns>True if the user chose to update the test, false otherwise</returns>
        private static bool UpdateTest(string expectedFile, string actualFile, string testName, ArrayList differences)
        {
            Console.WriteLine();
            Console.WriteLine(String.Concat("Test Name: ", testName));

            // Print the differences that were found
            foreach (string line in differences)
            {
                Console.WriteLine(line);
            }

            Console.WriteLine();
            Console.Write("Do you wish to update the test to use the actual file '{0}' as the expected '{1}' (y/n)? ", actualFile, expectedFile);
            string answer = Console.ReadLine();

            if (answer.Equals("y", StringComparison.InvariantCultureIgnoreCase) || answer.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
            {
                // sd edit the expected file
                ArrayList output = ToolUtility.RunTool("sd.exe", String.Concat("edit ", expectedFile));

                // Print the sd edit output
                foreach (string line in output)
                {
                    Console.WriteLine(line);
                }

                File.Copy(actualFile, expectedFile, true);
                return(true);
            }
            else
            {
                Console.WriteLine("The test was not updated");
                return(false);
            }
        }
        /// <summary>
        /// Run a tool with the given file name and command line.
        /// </summary>
        /// <param name="toolFile">The tool's file name.</param>
        /// <param name="commandLine">The command line.</param>
        /// <returns>An ArrayList of output strings.</returns>
        public static ArrayList RunTool(string toolFile, string commandLine)
        {
            // The returnCode variable doesn't get used but it must be created to pass as an argument
            int returnCode;

            return(ToolUtility.RunTool(toolFile, commandLine, out returnCode));
        }
        /// <summary>
        /// Run a Insignia unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments        = element.GetAttribute("Arguments");
            string expectedErrors   = element.GetAttribute("ExpectedErrors");
            string expectedWarnings = element.GetAttribute("ExpectedWarnings");
            string tempDirectory    = element.GetAttribute("TempDirectory");
            string toolsDirectory   = element.GetAttribute("ToolsDirectory");

            string        toolFile    = Path.Combine(toolsDirectory, "Insignia.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            // handle wixunit arguments
            if (args.NoTidy)
            {
                commandLine.Append(" -notidy");
            }

            // handle child elements
            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    switch (node.LocalName)
                    {
                    case "SourceFile":
                        string sourceFile = Environment.ExpandEnvironmentVariables(node.InnerText.Trim());
                        string outputFile = Path.Combine(tempDirectory, sourceFile);

                        Directory.CreateDirectory(Path.GetDirectoryName(outputFile));

                        // If the file already exists, let's throw an error - otherwise one output file overwriting the other
                        // in the notidy case would be confusing
                        File.Copy(sourceFile, outputFile, false);

                        DirectoryInfo inputDirInfo = new DirectoryInfo(Path.GetDirectoryName(sourceFile));
                        FileInfo[]    cabFiles     = inputDirInfo.GetFiles("*.cab");
                        foreach (FileInfo cabFile in cabFiles)
                        {
                            File.Copy(cabFile.FullName, Path.Combine(Path.GetDirectoryName(outputFile), cabFile.Name), false);
                        }

                        // Remove any read-only attributes on the file
                        FileAttributes attributes = File.GetAttributes(outputFile);
                        attributes = (attributes & ~FileAttributes.ReadOnly);
                        File.SetAttributes(outputFile, attributes);

                        commandLine.AppendFormat(" -im \"{0}\"", outputFile);

                        previousUnitResults.OutputFiles.Add(outputFile);
                        break;
                    }
                }
            }

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);
        }
        /// <summary>
        /// Run a Process unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments          = element.GetAttribute("Arguments");
            string executable         = element.GetAttribute("Executable");
            string expectedReturnCode = element.GetAttribute("ExpectedReturnCode");
            string workingDirectory   = element.GetAttribute("WorkingDirectory");

            bool compareReturnCodes = false;

            // Check if an ExpectedReturnCode was set
            if (null != expectedReturnCode && String.Empty != expectedReturnCode)
            {
                compareReturnCodes = true;
            }

            // Set the current working directory if one was specified
            string currentDirectory = Environment.CurrentDirectory;

            if (null != workingDirectory && String.Empty != workingDirectory)
            {
                Environment.CurrentDirectory = workingDirectory;
            }

            // Run the process
            int       actualReturnCode;
            ArrayList output = ToolUtility.RunTool(executable, arguments, out actualReturnCode);

            Environment.CurrentDirectory = currentDirectory;

            previousUnitResults.Output.AddRange(output);

            // Check the results
            if (compareReturnCodes)
            {
                if (actualReturnCode == Convert.ToInt32(expectedReturnCode))
                {
                    previousUnitResults.Output.Add(String.Format("Actual return code {0} matched expected return code {1}", actualReturnCode, expectedReturnCode));
                }
                else
                {
                    previousUnitResults.Errors.Add(String.Format("Actual return code {0} did not match expected return code {1}", actualReturnCode, expectedReturnCode));
                    previousUnitResults.Output.Add(String.Format("Actual return code {0} did not match expected return code {1}", actualReturnCode, expectedReturnCode));
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Run a Dark unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments        = element.GetAttribute("Arguments");
            string expectedErrors   = element.GetAttribute("ExpectedErrors");
            string expectedWarnings = element.GetAttribute("ExpectedWarnings");
            string tempDirectory    = element.GetAttribute("TempDirectory");
            string toolsDirectory   = element.GetAttribute("ToolsDirectory");

            string        toolFile    = Path.Combine(toolsDirectory, "dark.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            // handle wixunit arguments
            if (args.NoTidy)
            {
                commandLine.Append(" -notidy");
            }

            // determine the correct extension for the decompiled output
            string extension = ".wxs";

            if (0 <= arguments.IndexOf("-xo"))
            {
                extension = ".wixout";
            }

            // handle any previous outputs
            string outputFile = null;

            foreach (string databaseFile in previousUnitResults.OutputFiles)
            {
                commandLine.AppendFormat(" \"{0}\"", databaseFile);

                outputFile = Path.Combine(tempDirectory, String.Concat("decompiled_", Path.GetFileNameWithoutExtension(databaseFile), extension));
            }
            previousUnitResults.OutputFiles.Clear();

            commandLine.AppendFormat(" \"{0}\" -x \"{1}\"", outputFile, tempDirectory);
            previousUnitResults.OutputFiles.Add(outputFile);

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);
        }
Пример #7
0
        /// <summary>
        /// Run a Heat unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments        = element.GetAttribute("Arguments");
            string expectedErrors   = element.GetAttribute("ExpectedErrors");
            string expectedWarnings = element.GetAttribute("ExpectedWarnings");
            string tempDirectory    = element.GetAttribute("TempDirectory");
            string toolsDirectory   = element.GetAttribute("ToolsDirectory");

            string        toolFile    = Path.Combine(toolsDirectory, "heat.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            string outputFile = Path.Combine(tempDirectory, "harvested.wxs");

            commandLine.AppendFormat(" -out \"{0}\"", outputFile);
            previousUnitResults.OutputFiles.Add(outputFile);

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);

            if (0 == previousUnitResults.Errors.Count)
            {
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true;
                doc.Load(outputFile);

                XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);
                namespaceManager.AddNamespace("wix", "http://wixtoolset.org/schemas/v4/wxs");

                foreach (XmlElement componentElement in doc.SelectNodes("//wix:Component[@Guid=\"PUT-GUID-HERE\"]", namespaceManager))
                {
                    componentElement.SetAttribute("Guid", Guid.Empty.ToString("B"));
                }

                doc.Save(outputFile);
            }
        }
Пример #8
0
        /// <summary>
        /// Run a Torch unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="update">Indicates whether to give the user the option to fix a failing test.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, bool update, ICommandArgs args)
        {
            string arguments         = element.GetAttribute("Arguments");
            string expectedErrors    = element.GetAttribute("ExpectedErrors");
            string expectedWarnings  = element.GetAttribute("ExpectedWarnings");
            string extensions        = element.GetAttribute("Extensions");
            string outputFile        = element.GetAttribute("OutputFile");
            string targetDatabase    = element.GetAttribute("TargetDatabase");
            string tempDirectory     = element.GetAttribute("TempDirectory");
            string testName          = element.ParentNode.Attributes["Name"].Value;
            string toolsDirectory    = element.GetAttribute("ToolsDirectory");
            string updatedDatabase   = element.GetAttribute("UpdatedDatabase");
            bool   usePreviousOutput = ("true" == element.GetAttribute("UsePreviousOutput"));
            bool   verifyTransform   = ("true" == element.GetAttribute("VerifyTransform"));

            string        toolFile    = Path.Combine(toolsDirectory, "torch.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            // handle extensions
            if (!String.IsNullOrEmpty(extensions))
            {
                foreach (string extension in extensions.Split(';'))
                {
                    commandLine.AppendFormat(" -ext \"{0}\"", extension);
                }
            }

            // handle wixunit arguments
            if (args.NoTidy)
            {
                commandLine.Append(" -notidy");
            }

            // handle any previous outputs
            if (0 < previousUnitResults.OutputFiles.Count && usePreviousOutput)
            {
                commandLine.AppendFormat(" \"{0}\"", previousUnitResults.OutputFiles[0]);
                previousUnitResults.OutputFiles.Clear();
            }
            else // diff database files to create transform
            {
                commandLine.AppendFormat(" \"{0}\" \"{1}\"", targetDatabase, updatedDatabase);
            }


            if (null == outputFile || String.Empty == outputFile)
            {
                outputFile = Path.Combine(tempDirectory, "transform.mst");
            }
            commandLine.AppendFormat(" -out \"{0}\"", outputFile);
            previousUnitResults.OutputFiles.Add(outputFile);

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);

            // check the results
            if (verifyTransform && 0 == expectedErrors.Length && 0 == previousUnitResults.Errors.Count)
            {
                string actualDatabase = Path.Combine(tempDirectory, String.Concat(Guid.NewGuid(), ".msi"));
                File.Copy(targetDatabase, actualDatabase);
                File.SetAttributes(actualDatabase, File.GetAttributes(actualDatabase) & ~FileAttributes.ReadOnly);
                using (Database database = new Database(actualDatabase, OpenDatabase.Direct))
                {
                    // use transform validation bits set in the transform (if any; defaults to None).
                    database.ApplyTransform(outputFile);
                    database.Commit();
                }

                // check the output file
                ArrayList differences = CompareUnit.CompareResults(updatedDatabase, actualDatabase, testName, update);
                previousUnitResults.Errors.AddRange(differences);
                previousUnitResults.Output.AddRange(differences);
            }
        }
        /// <summary>
        /// Run a Wixproj unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="verbose">The level of verbosity for the MSBuild logging.</param>
        /// <param name="skipValidation">Tells light to skip validation.</param>
        /// <param name="update">Indicates whether to give the user the option to fix a failing test.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, bool verbose, bool skipValidation, bool update, ICommandArgs args)
        {
            string arguments                = element.GetAttribute("Arguments");
            string expectedErrors           = element.GetAttribute("ExpectedErrors");
            string expectedResult           = element.GetAttribute("ExpectedResult");
            string expectedWarnings         = element.GetAttribute("ExpectedWarnings");
            string extensions               = element.GetAttribute("Extensions");
            bool   noOutputName             = XmlConvert.ToBoolean(element.GetAttribute("NoOutputName"));
            bool   noOutputPath             = XmlConvert.ToBoolean(element.GetAttribute("NoOutputPath"));
            bool   defineSolutionProperties = XmlConvert.ToBoolean(element.GetAttribute("DefineSolutionProperties"));
            string suppressExtensions       = element.GetAttribute("SuppressExtensions");
            string tempDirectory            = element.GetAttribute("TempDirectory");
            string testName            = element.ParentNode.Attributes["Name"].Value;
            string toolsDirectory      = element.GetAttribute("ToolsDirectory");
            string msBuildDirectory    = Environment.GetEnvironmentVariable("WixTestMSBuildDirectory");
            string msBuildToolsVersion = Environment.GetEnvironmentVariable("WixTestMSBuildToolsVersion");

            // check the combinations of attributes
            if (expectedErrors.Length > 0 && expectedResult.Length > 0)
            {
                throw new WixException(WixErrors.IllegalAttributeWithOtherAttribute(null, element.Name, "ExpectedErrors", "ExpectedResult"));
            }

            // we'll run MSBuild on the .wixproj to generate the output
            if (null == msBuildDirectory)
            {
                msBuildDirectory = Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), @"Microsoft.NET\Framework\v3.5");
            }

            string        toolFile    = Path.Combine(msBuildDirectory, "MSBuild.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            // rebuild by default
            commandLine.AppendFormat(" /target:Rebuild /verbosity:{0}", verbose ? "detailed" : "normal");

            if (skipValidation)
            {
                commandLine.Append(" /property:SuppressValidation=true");
            }

            // add DefineSolutionProperties
            commandLine.AppendFormat(" /property:DefineSolutionProperties={0}", defineSolutionProperties);

            // make sure the tools directory ends in a single backslash
            if (toolsDirectory[toolsDirectory.Length - 1] != Path.DirectorySeparatorChar)
            {
                toolsDirectory = String.Concat(toolsDirectory, Path.DirectorySeparatorChar);
            }

            // handle the wix-specific directories and files
            commandLine.AppendFormat(" /property:WixToolPath=\"{0}\\\"", toolsDirectory);
            commandLine.AppendFormat(" /property:WixExtDir=\"{0}\\\"", toolsDirectory);
            commandLine.AppendFormat(" /property:WixTargetsPath=\"{0}\"", Path.Combine(toolsDirectory, "wix.targets"));
            commandLine.AppendFormat(" /property:WixTasksPath=\"{0}\"", Path.Combine(toolsDirectory, "WixTasks.dll"));
            commandLine.AppendFormat(" /property:BaseIntermediateOutputPath=\"{0}\\\\\"", Path.Combine(tempDirectory, "obj"));

            // handle extensions
            string[]      suppressedExtensionArray = suppressExtensions.Split(';');
            StringBuilder extensionsToUse          = new StringBuilder();

            foreach (string extension in extensions.Split(';'))
            {
                if (0 > Array.BinarySearch(suppressedExtensionArray, extension))
                {
                    if (extensionsToUse.Length > 0)
                    {
                        extensionsToUse.Append(";");
                    }
                    extensionsToUse.Append(extension);
                }
            }
            commandLine.AppendFormat(" /property:WixExtension=\"{0}\"", extensionsToUse.ToString());

            previousUnitResults.OutputFiles.Clear();

            // handle the source file
            string sourceFile = element.GetAttribute("SourceFile").Trim();

            // handle the expected result output file
            string outputFile;

            if (expectedResult.Length > 0)
            {
                outputFile = Path.Combine(tempDirectory, Path.GetFileName(expectedResult));
            }
            else
            {
                outputFile = Path.Combine(tempDirectory, "ShouldNotBeCreated.msi");
            }

            if (!noOutputName)
            {
                commandLine.AppendFormat(" /property:OutputName=\"{0}\"", Path.GetFileNameWithoutExtension(outputFile));
            }

            if (!noOutputPath)
            {
                commandLine.AppendFormat(" /property:OutputPath=\"{0}\\\\\"", Path.GetDirectoryName(outputFile));
            }
            previousUnitResults.OutputFiles.Add(outputFile);

            if (!String.IsNullOrEmpty(msBuildToolsVersion))
            {
                commandLine.AppendFormat(" /tv:{0}", msBuildToolsVersion);
            }

            // add the source file as the last parameter
            commandLine.AppendFormat(" \"{0}\"", sourceFile);

            // run one msbuild process at a time due to multiproc issues
            ArrayList output = null;

            try
            {
                mutex.WaitOne();
                output = ToolUtility.RunTool(toolFile, commandLine.ToString());
            }
            finally
            {
                mutex.ReleaseMutex();
            }

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);

            // check the output file
            if (previousUnitResults.Errors.Count == 0)
            {
                if (expectedResult.Length > 0)
                {
                    ArrayList differences = CompareUnit.CompareResults(expectedResult, outputFile, testName, update);

                    previousUnitResults.Errors.AddRange(differences);
                    previousUnitResults.Output.AddRange(differences);
                }
                else if (expectedErrors.Length > 0 && File.Exists(outputFile)) // ensure the output doesn't exist
                {
                    string error = String.Format(CultureInfo.InvariantCulture, "Expected failure, but the unit test created output file \"{0}\".", outputFile);

                    previousUnitResults.Errors.Add(error);
                    previousUnitResults.Output.Add(error);
                }
            }
        }
        /// <summary>
        /// Run a Candle unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, ICommandArgs args)
        {
            string arguments         = element.GetAttribute("Arguments");
            string expectedErrors    = element.GetAttribute("ExpectedErrors");
            string expectedWarnings  = element.GetAttribute("ExpectedWarnings");
            string extensions        = element.GetAttribute("Extensions");
            string outputDirectory   = element.GetAttribute("OutputDirectory");
            bool   suppressWixCop    = ("true" == element.GetAttribute("SuppressWixCop"));
            string tempDirectory     = element.GetAttribute("TempDirectory");
            string toolsDirectory    = element.GetAttribute("ToolsDirectory");
            bool   usePreviousOutput = ("true" == element.GetAttribute("UsePreviousOutput"));

            string        toolFile          = Path.Combine(toolsDirectory, "candle.exe");
            StringBuilder commandLine       = new StringBuilder(arguments);
            StringBuilder wixCopCommandLine = new StringBuilder("-set1");

            wixCopCommandLine.Append(Path.Combine(toolsDirectory, "WixCop.settings.xml"));

            // handle extensions
            if (!String.IsNullOrEmpty(extensions))
            {
                foreach (string extension in extensions.Split(';'))
                {
                    commandLine.AppendFormat(" -ext \"{0}\"", extension);
                }
            }

            // If the output directory is not set, set it to the temp directory.
            if (String.IsNullOrEmpty(outputDirectory))
            {
                outputDirectory = tempDirectory;
            }
            commandLine.AppendFormat(" -out \"{0}\\\\\"", outputDirectory);

            // handle any previous outputs
            if (usePreviousOutput)
            {
                ArrayList previousWixobjFiles = new ArrayList();
                foreach (string sourceFile in previousUnitResults.OutputFiles)
                {
                    string wixobjFile = String.Concat(Path.GetFileNameWithoutExtension(sourceFile), ".wixobj");

                    commandLine.AppendFormat(" \"{0}\"", sourceFile);
                    wixCopCommandLine.AppendFormat(" \"{0}\"", sourceFile);

                    previousWixobjFiles.Add(Path.Combine(tempDirectory, wixobjFile));
                }
                previousUnitResults.OutputFiles.Clear();
                previousUnitResults.OutputFiles.AddRange(previousWixobjFiles);
            }
            else
            {
                previousUnitResults.OutputFiles.Clear();
            }

            // handle child elements
            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    switch (node.LocalName)
                    {
                    case "SourceFile":
                        string sourceFile = Environment.ExpandEnvironmentVariables(node.InnerText.Trim());
                        string wixobjFile = String.Concat(Path.GetFileNameWithoutExtension(sourceFile), ".wixobj");

                        commandLine.AppendFormat(" \"{0}\"", sourceFile);
                        wixCopCommandLine.AppendFormat(" \"{0}\"", sourceFile);

                        previousUnitResults.OutputFiles.Add(Path.Combine(outputDirectory, wixobjFile));
                        break;
                    }
                }
            }

            // run WixCop if it hasn't been suppressed
            if (!suppressWixCop)
            {
                string wixCopFile = Path.Combine(toolsDirectory, "wixcop.exe");

                ArrayList wixCopOutput = ToolUtility.RunTool(wixCopFile, wixCopCommandLine.ToString());
                previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(wixCopOutput, String.Empty, String.Empty));
                previousUnitResults.Output.AddRange(wixCopOutput);
            }

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);
        }
Пример #11
0
        /// <summary>
        /// Run a Light unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="update">Indicates whether to give the user the option to fix a failing test.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, bool update, ICommandArgs args)
        {
            string arguments              = element.GetAttribute("Arguments");
            string expectedErrors         = element.GetAttribute("ExpectedErrors");
            string expectedResult         = element.GetAttribute("ExpectedResult");
            string expectedWarnings       = element.GetAttribute("ExpectedWarnings");
            string extensions             = element.GetAttribute("Extensions");
            string outputFile             = element.GetAttribute("OutputFile");
            string intermediateOutputType = element.GetAttribute("IntermediateOutputType");
            string suppressExtensions     = element.GetAttribute("SuppressExtensions");
            string tempDirectory          = element.GetAttribute("TempDirectory");
            string testName          = element.ParentNode.Attributes["Name"].Value;
            string toolsDirectory    = element.GetAttribute("ToolsDirectory");
            bool   usePreviousOutput = ("true" == element.GetAttribute("UsePreviousOutput"));

            if (expectedErrors.Length == 0 && expectedResult.Length == 0 && intermediateOutputType.Length == 0 && outputFile.Length == 0)
            {
                throw new WixException(WixErrors.ExpectedAttributes(null, element.Name, "ExpectedErrors", "ExpectedResult", "IntermediateOutputType", "OutputFile", null));
            }

            if (expectedErrors.Length > 0 && (expectedResult.Length > 0 || intermediateOutputType.Length > 0 || outputFile.Length > 0))
            {
                throw new WixException(WixErrors.IllegalAttributeWithOtherAttributes(null, element.Name, "ExpectedErrors", "ExpectedResult", "IntermediateOutputType", "OutputFile", null));
            }
            else if (expectedResult.Length > 0 && (intermediateOutputType.Length > 0 || outputFile.Length > 0))
            {
                throw new WixException(WixErrors.IllegalAttributeWithOtherAttributes(null, element.Name, "ExpectedResult", "IntermediateOutputType", "OutputFile"));
            }
            else if (intermediateOutputType.Length > 0 && outputFile.Length > 0)
            {
                throw new WixException(WixErrors.IllegalAttributeWithOtherAttributes(null, element.Name, "IntermediateOutputType", "OutputFile", null));
            }

            string        toolFile    = Path.Combine(toolsDirectory, "light.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            commandLine.Append(" -b \"%WIX%\\examples\\data\"");

            // handle wixunit arguments
            if (args.NoTidy)
            {
                commandLine.Append(" -notidy");
            }

            // handle extensions
            if (!String.IsNullOrEmpty(extensions))
            {
                string[] suppressedExtensionArray = suppressExtensions.Split(';');
                foreach (string extension in extensions.Split(';'))
                {
                    if (0 > Array.BinarySearch(suppressedExtensionArray, extension))
                    {
                        commandLine.AppendFormat(" -ext \"{0}\"", extension);
                    }
                }
            }

            // handle any previous outputs
            if (usePreviousOutput)
            {
                foreach (string inputFile in previousUnitResults.OutputFiles)
                {
                    commandLine.AppendFormat(" \"{0}\"", inputFile);
                }
            }
            previousUnitResults.OutputFiles.Clear();

            // handle child elements
            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    switch (node.LocalName)
                    {
                    case "LibraryFile":
                        string libraryFile = node.InnerText.Trim();

                        commandLine.AppendFormat(" \"{0}\"", libraryFile);
                        break;

                    case "LocalizationFile":
                        string localizationFile = node.InnerText.Trim();

                        commandLine.AppendFormat(" -loc \"{0}\"", localizationFile);
                        break;
                    }
                }
            }

            if (outputFile.Length > 0)
            {
                // outputFile has been explicitly set
            }
            else if (expectedResult.Length > 0)
            {
                outputFile = Path.Combine(tempDirectory, Path.GetFileName(expectedResult));
            }
            else if (intermediateOutputType.Length > 0)
            {
                string intermediateFile = String.Concat("intermediate.", intermediateOutputType);

                outputFile = Path.Combine(tempDirectory, intermediateFile);
            }
            else
            {
                outputFile = Path.Combine(tempDirectory, "ShouldNotBeCreated.msi");
            }
            commandLine.AppendFormat("{0} -out \"{1}\"", (Path.GetExtension(outputFile) == ".wixout" ? " -xo" : String.Empty), outputFile);
            previousUnitResults.OutputFiles.Add(outputFile);

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);

            // check the output file
            if (previousUnitResults.Errors.Count == 0)
            {
                if (expectedResult.Length > 0)
                {
                    ArrayList differences = CompareUnit.CompareResults(expectedResult, outputFile, testName, update);

                    previousUnitResults.Errors.AddRange(differences);
                    previousUnitResults.Output.AddRange(differences);
                }
                else if (expectedErrors.Length > 0 && File.Exists(outputFile)) // ensure the output doesn't exist
                {
                    string error = String.Format(CultureInfo.InvariantCulture, "Expected failure, but the unit test created output file \"{0}\".", outputFile);

                    previousUnitResults.Errors.Add(error);
                    previousUnitResults.Output.Add(error);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Run a Pyro unit test.
        /// </summary>
        /// <param name="element">The unit test element.</param>
        /// <param name="previousUnitResults">The previous unit test results.</param>
        /// <param name="update">Indicates whether to give the user the option to fix a failing test.</param>
        /// <param name="args">The command arguments passed to WixUnit.</param>
        public static void RunUnitTest(XmlElement element, UnitResults previousUnitResults, bool update, ICommandArgs args)
        {
            string arguments        = element.GetAttribute("Arguments");
            string expectedErrors   = element.GetAttribute("ExpectedErrors");
            string expectedResult   = element.GetAttribute("ExpectedResult");
            string expectedWarnings = element.GetAttribute("ExpectedWarnings");
            string extensions       = element.GetAttribute("Extensions");
            string inputFile        = element.GetAttribute("InputFile");
            string outputFile       = element.GetAttribute("OutputFile");
            string tempDirectory    = element.GetAttribute("TempDirectory");
            string testName         = element.ParentNode.Attributes["Name"].Value;
            string toolsDirectory   = element.GetAttribute("ToolsDirectory");

            if (null == inputFile || String.Empty == inputFile)
            {
                throw new WixException(WixErrors.IllegalEmptyAttributeValue(null, element.Name, "InputFile"));
            }

            if (null == outputFile || String.Empty == outputFile)
            {
                throw new WixException(WixErrors.IllegalEmptyAttributeValue(null, element.Name, "OutputFile"));
            }

            // After Pyro is run, verify that this file was not created
            if (0 < expectedErrors.Length)
            {
                outputFile = Path.Combine(tempDirectory, "ShouldNotBeCreated.msp");
            }

            string        toolFile    = Path.Combine(toolsDirectory, "pyro.exe");
            StringBuilder commandLine = new StringBuilder(arguments);

            commandLine.AppendFormat(" \"{0}\" -out \"{1}\"", inputFile, outputFile);
            previousUnitResults.OutputFiles.Add(outputFile);

            // handle extensions
            if (!String.IsNullOrEmpty(extensions))
            {
                foreach (string extension in extensions.Split(';'))
                {
                    commandLine.AppendFormat(" -ext \"{0}\"", extension);
                }
            }

            // handle wixunit arguments
            if (args.NoTidy)
            {
                commandLine.Append(" -notidy");
            }

            // handle child elements
            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    switch (node.LocalName)
                    {
                    case "Transform":
                        string transformFile = node.Attributes["File"].Value;
                        string baseline      = node.Attributes["Baseline"].Value;
                        commandLine.AppendFormat(" -t {0} \"{1}\"", baseline, transformFile);
                        break;

                    default:
                        break;
                    }
                }
            }

            // run the tool
            ArrayList output = ToolUtility.RunTool(toolFile, commandLine.ToString());

            previousUnitResults.Errors.AddRange(ToolUtility.GetErrors(output, expectedErrors, expectedWarnings));
            previousUnitResults.Output.AddRange(output);

            // check the output file
            if (0 == previousUnitResults.Errors.Count)
            {
                if (0 < expectedResult.Length)
                {
                    ArrayList differences = CompareUnit.CompareResults(expectedResult, outputFile, testName, update);

                    previousUnitResults.Errors.AddRange(differences);
                    previousUnitResults.Output.AddRange(differences);
                }
                else if (0 < expectedErrors.Length && File.Exists(outputFile)) // ensure the output doesn't exist
                {
                    string error = String.Format(CultureInfo.InvariantCulture, "Expected failure, but the unit test created output file \"{0}\".", outputFile);

                    previousUnitResults.Errors.Add(error);
                    previousUnitResults.Output.Add(error);
                }
            }
        }