예제 #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);
        }
        /// <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);
        }
예제 #3
0
        /// <summary>
        /// Run a Compare 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 file1    = Environment.ExpandEnvironmentVariables(element.GetAttribute("File1"));
            string file2    = Environment.ExpandEnvironmentVariables(element.GetAttribute("File2"));
            string testName = element.ParentNode.Attributes["Name"].Value;

            // Check the results
            ArrayList differences = CompareUnit.CompareResults(file1, file2, testName, update);

            previousUnitResults.Errors.AddRange(differences);
            previousUnitResults.Output.AddRange(differences);
        }
        /// <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));
                }
            }
        }
예제 #5
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);
        }
예제 #6
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);
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
        /// <summary>
        /// Run a unit test.
        /// </summary>
        /// <param name="unitTestElement">The unit test to run.</param>
        private void RunUnitTest(XmlElement unitTestElement)
        {
            string      name          = unitTestElement.GetAttribute("Name");
            string      tempDirectory = Path.Combine(unitTestElement.GetAttribute("TempDirectory"), name);
            UnitResults unitResults   = new UnitResults();

            try
            {
                // ensure the temp directory exists
                Directory.CreateDirectory(tempDirectory);

                foreach (XmlNode node in unitTestElement.ChildNodes)
                {
                    if (XmlNodeType.Element == node.NodeType)
                    {
                        XmlElement unitElement = (XmlElement)node;

                        // add inherited attributes from the parent "UnitTest" element
                        foreach (XmlAttribute attribute in unitTestElement.Attributes)
                        {
                            if (attribute.NamespaceURI.Length == 0)
                            {
                                unitElement.SetAttribute(attribute.Name, attribute.Value);
                            }
                        }

                        // add inherited attributes from the grandparent "UnitTests" element
                        foreach (XmlAttribute attribute in unitTestElement.ParentNode.Attributes)
                        {
                            if (attribute.NamespaceURI.Length == 0)
                            {
                                unitElement.SetAttribute(attribute.Name, attribute.Value);
                            }
                        }
                        unitElement.SetAttribute("TempDirectory", tempDirectory);

                        switch (node.LocalName)
                        {
                        case "Candle":
                            CandleUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Compare":
                            CompareUnit.RunUnitTest(unitElement, unitResults, this.updateTests, this);
                            break;

                        case "Dark":
                            DarkUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Heat":
                            HeatUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Insignia":
                            InsigniaUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Light":
                            // If WixUnit was not run with -val then suppress MSI validation
                            if (!this.validate && ("true" != unitElement.GetAttribute("ForceValidation")))
                            {
                                string arguments = unitElement.GetAttribute("Arguments");
                                if (!arguments.Contains("-sval"))
                                {
                                    unitElement.SetAttribute("Arguments", String.Concat(arguments, " -sval"));
                                }
                            }

                            LightUnit.RunUnitTest(unitElement, unitResults, this.updateTests, this);
                            break;

                        case "Lit":
                            LitUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Process":
                            ProcessUnit.RunUnitTest(unitElement, unitResults, this);
                            break;

                        case "Pyro":
                            PyroUnit.RunUnitTest(unitElement, unitResults, this.updateTests, this);
                            break;

                        case "Torch":
                            TorchUnit.RunUnitTest(unitElement, unitResults, this.updateTests, this);
                            break;

                        case "WixProj":
                            bool skipValidation = (!this.validate);
                            WixProjUnit.RunUnitTest(unitElement, unitResults, this.verbose, skipValidation, this.updateTests, this);
                            break;

                        case "Smoke":
                            SmokeUnit.RunUnitTest(unitElement, unitResults, this);
                            break;
                        }

                        // check for errors
                        if (unitResults.Errors.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }
            catch (WixException we)
            {
                string message = this.messageHandler.GetMessageString(this, we.Error);

                if (null != message)
                {
                    unitResults.Errors.Add(message);
                    unitResults.Output.Add(message);
                }
            }
            catch (Exception e)
            {
                string message = this.messageHandler.GetMessageString(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));

                if (null != message)
                {
                    unitResults.Errors.Add(message);
                    unitResults.Output.Add(message);
                }
            }

            lock (this.lockObject)
            {
                Console.Write("{0} of {1} - {2}: ", ++this.completedUnitTests, this.totalUnitTests, name.PadRight(30, '.'));

                if (unitResults.Errors.Count > 0)
                {
                    this.failedUnitTests.Add(name, this.completedUnitTests);

                    Console.WriteLine("Failed");

                    if (this.verbose)
                    {
                        foreach (string line in unitResults.Output)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                    else
                    {
                        foreach (string line in unitResults.Errors)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }
                else
                {
                    Console.WriteLine("Success");

                    if (this.verbose)
                    {
                        foreach (string line in unitResults.Output)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }

                if (this.totalUnitTests == this.completedUnitTests)
                {
                    this.unitTestsComplete.Set();
                }
            }
        }
        /// <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);
                }
            }
        }