コード例 #1
0
        /// <summary>
        /// Tries to emit the available reports to the specified directory with the given file name,
        /// and returns the paths of all emitted reports.
        /// </summary>
        public bool TryEmitReports(string directory, string fileName, out IEnumerable <string> reportPaths)
        {
            var paths = new List <string>();

            if (!this.Configuration.RunTestIterationsToCompletion)
            {
                // Emits the human readable trace, if it exists.
                if (!string.IsNullOrEmpty(this.ReadableTrace))
                {
                    string readableTracePath = Path.Combine(directory, fileName + ".txt");
                    File.WriteAllText(readableTracePath, this.ReadableTrace);
                    paths.Add(readableTracePath);
                }
            }

            if (!this.Configuration.RunTestIterationsToCompletion)
            {
                if (this.Configuration.IsXmlLogEnabled)
                {
                    string xmlPath = Path.Combine(directory, fileName + ".trace.xml");
                    File.WriteAllText(xmlPath, this.XmlLog.ToString());
                    paths.Add(xmlPath);
                }

                if (this.LastExecutionGraph != null && this.TestReport.NumOfFoundBugs > 0)
                {
                    string graphPath = Path.Combine(directory, fileName + ".trace.dgml");
                    this.LastExecutionGraph.SaveDgml(graphPath, true);
                    paths.Add(graphPath);
                }

                // Emits the reproducible trace, if it exists.
                if (!string.IsNullOrEmpty(this.ReproducibleTrace))
                {
                    string reproTracePath = Path.Combine(directory, fileName + ".schedule");
                    File.WriteAllText(reproTracePath, this.ReproducibleTrace);
                    paths.Add(reproTracePath);
                }
            }

            // Emits the uncontrolled invocations report, if it exists.
            if (this.TestReport.UncontrolledInvocations.Count > 0)
            {
                string reportPath = Path.Combine(directory, fileName + ".uncontrolled.json");
                File.WriteAllText(reportPath, UncontrolledInvocationsReport.ToJSON(this.TestReport.UncontrolledInvocations));
                paths.Add(reportPath);
            }

            reportPaths = paths;
            return(paths.Count > 0);
        }
コード例 #2
0
        /// <summary>
        /// Tries to emit the testing reports, if any.
        /// </summary>
        public IEnumerable <string> TryEmitReports(string directory, string file)
        {
            bool reportsEmitted = false;

            // Find the next available file index.
            int   index = 0;
            Regex match = new Regex("^(.*)_([0-9]+)_([0-9]+)");

            foreach (var path in Directory.GetFiles(directory))
            {
                string name = Path.GetFileName(path);
                if (name.StartsWith(file))
                {
                    var result = match.Match(name);
                    if (result.Success)
                    {
                        string value = result.Groups[3].Value;
                        if (int.TryParse(value, out int i))
                        {
                            index = Math.Max(index, i + 1);
                        }
                    }
                }
            }

            if (!this.Configuration.RunTestIterationsToCompletion)
            {
                // Emits the human readable trace, if it exists.
                if (!string.IsNullOrEmpty(this.ReadableTrace))
                {
                    string readableTracePath = Path.Combine(directory, file + "_" + index + ".txt");
                    this.Logger.WriteLine(LogSeverity.Important, $"..... Writing {readableTracePath}");
                    File.WriteAllText(readableTracePath, this.ReadableTrace);
                    reportsEmitted = true;
                    yield return(readableTracePath);
                }
            }

            if (this.Configuration.IsXmlLogEnabled)
            {
                string xmlPath = Path.Combine(directory, file + "_" + index + ".trace.xml");
                this.Logger.WriteLine(LogSeverity.Important, $"..... Writing {xmlPath}");
                File.WriteAllText(xmlPath, this.XmlLog.ToString());
                reportsEmitted = true;
                yield return(xmlPath);
            }

            if (this.Graph != null)
            {
                string graphPath = Path.Combine(directory, file + "_" + index + ".dgml");
                this.Logger.WriteLine(LogSeverity.Important, $"..... Writing {graphPath}");
                this.Graph.SaveDgml(graphPath, true);
                reportsEmitted = true;
                yield return(graphPath);
            }

            if (!this.Configuration.RunTestIterationsToCompletion)
            {
                // Emits the reproducible trace, if it exists.
                if (!string.IsNullOrEmpty(this.ReproducibleTrace))
                {
                    string reproTracePath = Path.Combine(directory, file + "_" + index + ".schedule");
                    this.Logger.WriteLine(LogSeverity.Important, $"..... Writing {reproTracePath}");
                    File.WriteAllText(reproTracePath, this.ReproducibleTrace);
                    reportsEmitted = true;
                    yield return(reproTracePath);
                }
            }

            // Emits the uncontrolled invocations report, if it exists.
            if (this.TestReport.UncontrolledInvocations.Count > 0)
            {
                string reportPath = Path.Combine(directory, file + "_" + index + ".uncontrolled.json");
                this.Logger.WriteLine(LogSeverity.Important, $"..... Writing {reportPath}");
                File.WriteAllText(reportPath, UncontrolledInvocationsReport.ToJSON(this.TestReport.UncontrolledInvocations));
                reportsEmitted = true;
                yield return(reportPath);
            }

            if (!reportsEmitted)
            {
                Console.WriteLine($"..... No reports available.");
            }

            this.Logger.WriteLine(LogSeverity.Important, $"... Elapsed {this.Profiler.Results()} sec.");
        }