示例#1
0
        public bool Parse(IEnumerable <string> content, GraderResultBuilder resultBuilder, ILogger logger)
        {
            // <preamble>#testresult#exercise_name@test_name#result#comment

            var parts = new Stack <string>(content.Reverse());

            // must have these two
            if (!parts.TryPop(out string?testName))
            {
                logger.LogWarning($"Console messages reader: testresult operation with too few parameters");
                return(false);
            }
            if (!parts.TryPop(out string?resultString))
            {
                logger.LogWarning($"Console messages reader: testresult operation with too few parameters");
                return(false);
            }

            // other parts are optional
            parts.TryPop(out string?comment);

            if (!tryGetTestNameAndExerciseName(ref testName, out string exerciseName))
            {
                return(false);
            }

            if (!tryProcessResultString(testName, exerciseName, resultString, comment, resultBuilder, logger))
            {
                return(false);
            }

            return(true);
        }
        private static bool parseContent(string contentString, out GraderResult result)
        {
            var parser = new TestResultParser();
            var graderResultBuilder = new GraderResultBuilder();

            var outcome = parser.Parse(contentString.Split('#'), graderResultBuilder, NullLogger.Instance);

            result = graderResultBuilder.ToResult();
            return(outcome);
        }
示例#3
0
 private bool tryProcessResultString(string testName, string exerciseName, string resultString, string?comment, GraderResultBuilder resultBuilder, ILogger logger)
 {
     if (resultString.Equals(TestPassedMessage, System.StringComparison.OrdinalIgnoreCase))
     {
         resultBuilder.AddResult(exerciseName, testName, 1, comment);
         return(true);
     }
     else if (resultString.Equals(TestFailedMessage, System.StringComparison.OrdinalIgnoreCase))
     {
         resultBuilder.AddResult(exerciseName, testName, 0, comment);
         return(true);
     }
     else if (resultString.Equals(TestInconclusiveMessage, System.StringComparison.OrdinalIgnoreCase))
     {
         resultBuilder.AddInconclusive(exerciseName, testName, comment);
         return(true);
     }
     else if (int.TryParse(resultString, out int points))
     {
         resultBuilder.AddResult(exerciseName, testName, points, comment);
         return(true);
     }
     else
     {
         logger.LogWarning($"Console messages reader: testresult with unrecognized status {resultString}");
         return(false);
     }
 }