Ejemplo n.º 1
0
        static void ProcessActionLog(
            ReferenceData referenceDataActionLog,
            TestResult testResult,
            TestResultActionLog testResultActionLog
            )
        {
            var config = s_classDescriptor
                .Members
                .Where(m => m.HasPublicGetter && m.MemberType == typeof (TestRunOption))
                .ToDictionary(m => m.Name, m => (TestRunOption)m.Getter(testResult.Configuration))
                ;

            var referenceLines = File.ReadAllLines(referenceDataActionLog.ActionLogPath);
            var resultLines = File.ReadAllLines(testResultActionLog.ActionLogPath);

            var state = new ValidateState (referenceLines, resultLines);

            while (state.HasContent && state.ErrorCount < MaxErrors)
            {
                var matchReferenceLine  = state.Reference.GetMatch();
                var matchResultLine     = state.Result.GetMatch();

                if (!matchReferenceLine.Success)
                {
                    state.Reference.ReportFailure("UnknownTag", "Invalid formatted line", skipLine: true);
                }

                if (!matchResultLine.Success)
                {
                    state.Result.ReportFailure("UnknownTag", "Invalid formatted line", skipLine: true);
                }

                var referenceTag = matchReferenceLine.Groups["tag"].Value;
                var referenceData = matchReferenceLine.Groups["data"].Value;

                var resultTag = matchResultLine.Groups["tag"].Value;
                var resultData = matchResultLine.Groups["data"].Value;

                var isIdentical = IsIdentical(testResult.Configuration, referenceTag, resultTag, referenceData, resultData);

                if (isIdentical)
                {
                    state.ReportAllIsGood(referenceTag);
                    continue;
                }

                var referenceOption = config.Lookup(referenceTag);

                var hasIdenticalTag =
                        referenceTag == resultTag
                    ||  (
                            testResult.Configuration.Equivalence.CommentsAndCommentLines
                            && IsComment(referenceTag)
                            && IsComment(resultTag)
                        );

                switch (referenceOption)
                {
                    case TestRunOption.ValidateExistence:
                        if (hasIdenticalTag)
                        {
                            state.ReportAllIsGood(referenceTag);
                            continue;
                        }
                        else
                        {
                            state.ReportFailure(referenceTag, resultTag, "Validation failure (missing tag)", skipReferenceLine: true, skipResultLine: false);
                            continue;
                        }
                    case TestRunOption.ValidateContent:
                        if (hasIdenticalTag)
                        {
                            if (IsComment(referenceTag))
                            {
                                var referenceCommentContent = GetCommentContent(referenceData);
                                var resultCommentContent = GetCommentContent(resultData);

                                if (referenceCommentContent.Item2 != resultCommentContent.Item2)
                                {
                                    state.ReportFailure(referenceTag, resultTag, "Validation failure (content)", skipReferenceLine: true, skipResultLine: true);
                                }
                                else
                                {
                                    state.ReportAllIsGood(referenceTag);
                                }

                                continue;
                            }
                            else
                            {
                                if (referenceData != resultData)
                                {
                                    state.ReportFailure(referenceTag, resultTag, "Validation failure (content)", skipReferenceLine: true, skipResultLine: true);
                                    continue;
                                }
                                else
                                {
                                    state.ReportAllIsGood(referenceTag);
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            state.ReportFailure(referenceTag, resultTag, "Validation failure (missing tag)", skipReferenceLine: true, skipResultLine: false);
                            continue;
                        }
                    case TestRunOption.Ignore:
                        if (hasIdenticalTag)
                        {
                            state.ReportAllIsGood(referenceTag);
                            continue;
                        }
                        else
                        {
                            state.Reference.ReportAllIsGood(referenceTag);
                            continue;
                        }
                        continue;
                    case TestRunOption.ValidateAll:
                    default:
                        state.ReportFailure(referenceTag, resultTag, "Validation failure (mismatch)", skipReferenceLine: true, skipResultLine:true);
                        continue;
                }
            }
        }
Ejemplo n.º 2
0
        static void ProcessTestResult(TestResult testResult, Dictionary<string, ReferenceData> referenceActionLogs)
        {
            Log.Info("Processing test result: {0}", testResult.Name);

            foreach (var testResultActionLog in testResult.ActionLogs)
            {
                Log.Info("Processing test result action log: {0}", testResultActionLog.ActionLogName);
                var referenceDataActionLog = referenceActionLogs
                    .Lookup(testResultActionLog.ActionLogName)
                    ;

                if (referenceDataActionLog == null)
                {
                    Log.Warning("No matching reference action log found: {0}", testResultActionLog.ActionLogName);
                    continue;
                }

                try
                {
                    ProcessActionLog(referenceDataActionLog, testResult, testResultActionLog);
                }
                catch (ExitCodeException)
                {
                    throw;
                }
                catch (Exception exc)
                {
                    Log.Warning("Error while processing result action log: {0}", exc.Message);
                }
            }
        }
Ejemplo n.º 3
0
        static TestResult GetTestResult(string testResultPath)
        {
            testResultPath = testResultPath ?? "";

            var result = new TestResult
                             {
                                 Path = testResultPath                      ,
                                 Configuration = new TestRunConfiguration() ,
                             };

            Log.Info ("Processing test result in: {0}", result.Name);

            var configurationFilePath = Path.Combine(testResultPath, ParserValidatorConfig);
            var configurationFileName = Path.GetFileName (configurationFilePath);
            if (File.Exists(configurationFilePath))
            {
                Log.Info("Reading config file: {0}", configurationFileName);
                using (var configStream = new StreamReader(configurationFilePath))
                {
                    dynamic config;
                    HRONDynamicParseError[] errors;
                    var parseResult = HRONSerializer.TryParseDynamic(
                        int.MaxValue,
                        configStream.ReadLines().Select (s => s.ToSubString ()),
                        out config,
                        out errors
                        );

                    if (!parseResult)
                    {
                        Log.Error("Failed to read config file: {0}", configurationFileName);
                        return result;
                    }

                    result.Configuration.Equivalence.EmptyContentLinesAndEmptyLines     = config.Equivalence.EmptyContentLinesAndEmptyLines ;
                    result.Configuration.Equivalence.CommentsAndCommentLines            = config.Equivalence.CommentsAndCommentLines        ;
                    result.Configuration.PreProcessor   = config.PreProcessor   ;
                    result.Configuration.Object_Begin   = config.Object_Begin   ;
                    result.Configuration.Object_End     = config.Object_End     ;
                    result.Configuration.Value_Begin    = config.Value_Begin    ;
                    result.Configuration.Value_End      = config.Value_End      ;
                    result.Configuration.Comment        = config.Comment        ;
                    result.Configuration.Empty          = config.Empty          ;
                    result.Configuration.ContentLine    = config.ContentLine    ;
                    result.Configuration.EmptyLine      = config.EmptyLine      ;
                    result.Configuration.CommentLine    = config.CommentLine    ;
                }
            }

            result.ActionLogs = Directory
                .EnumerateFiles(testResultPath, "*.actionlog")
                .Select(p => new TestResultActionLog {ActionLogPath = p})
                .ToArray()
                ;

            return result;
        }