private void ReportErrorIfSolutionNotBuildingOrNotPassesTests() { var solutionCode = ex.CorrectSolutionFile.ContentAsUtf8(); var submission = ex.CreateSubmission(ex.CsprojFileName, solutionCode); var result = new CsSandboxRunnerClient().Run(submission); if (!IsCompiledAndExecuted(result)) { ReportSlideError(slide, $"Correct solution file {ex.CorrectSolutionFileName} verdict is not OK. RunResult = {result}"); } if (!ex.IsCorrectRunResult(result)) { ReportSlideError(slide, $"Correct solution file {ex.CorrectSolutionFileName} is not solution. RunResult = {result}. " + $"ExpectedOutput = {ex.ExpectedOutput.NormalizeEoln()} " + $"RealOutput = {result.GetOutput().NormalizeEoln()}"); } var buildResult = ex.BuildSolution(solutionCode); if (buildResult.HasStyleErrors) { var errorMessage = string.Join("\n", buildResult.StyleErrors.Select(e => e.GetMessageWithPositions())); ReportSlideWarning(slide, $"Correct solution file {ex.CorrectSolutionFileName} has style issues. {errorMessage}"); } }
private static RunSolutionResult GetRunResult(AbstractExerciseBlock exercise, string code) { var buildResult = exercise.BuildSolution(code); if (buildResult.HasErrors) { return new RunSolutionResult { IsCompileError = true, ErrorMessage = buildResult.ErrorMessage, ExecutionServiceName = "uLearn" } } ; RunSolutionResult runSolutionResult; if (exercise is UniversalExerciseBlock) { var result = new DockerSandboxRunner().Run(exercise.CreateSubmission(Utils.NewNormalizedGuid(), code)); runSolutionResult = new RunSolutionResult { IsRightAnswer = exercise.IsCorrectRunResult(result), ActualOutput = result.GetOutput()?.NormalizeEoln() ?? "", ErrorMessage = result.CompilationOutput, ExecutionServiceName = "course.exe", IsCompileError = result.Verdict == Verdict.CompilationError, ExpectedOutput = exercise.ExpectedOutput?.NormalizeEoln() ?? "", SubmissionId = 0, }; } else { var result = new CsSandboxRunnerClient().Run(exercise.CreateSubmission(Utils.NewNormalizedGuid(), code)); runSolutionResult = new RunSolutionResult { IsRightAnswer = exercise.IsCorrectRunResult(result), ActualOutput = result.GetOutput()?.NormalizeEoln() ?? "", ErrorMessage = result.CompilationOutput, ExecutionServiceName = "course.exe", IsCompileError = result.Verdict == Verdict.CompilationError, ExpectedOutput = exercise.ExpectedOutput?.NormalizeEoln() ?? "", SubmissionId = 0, }; } if (buildResult.HasStyleErrors) { runSolutionResult.IsStyleViolation = true; runSolutionResult.StyleMessage = string.Join("\n", buildResult.StyleErrors.Select(e => e.GetMessageWithPositions())); } return(runSolutionResult); }
private void ReportIfEthalonSolutionHasErrorsOrIssues(ExerciseSlide slide) { var exercise = (SingleFileExerciseBlock)slide.Exercise; if (exercise.EthalonSolution == null) { ReportSlideWarning(slide, "Ethalon solution not specified"); return; } var ethalon = exercise.EthalonSolution.RemoveCommonNesting(); var solution = exercise.BuildSolution(ethalon); if (solution.HasErrors) { FailOnError(slide, solution, ethalon); return; } if (solution.HasStyleErrors) { var errorMessages = string.Join("\n", solution.StyleErrors.Select(e => e.GetMessageWithPositions())); ReportSlideWarning(slide, "Style issue(s): " + errorMessages); } var result = new CsSandboxRunnerClient().Run(exercise.CreateSubmission(slide.Id.ToString(), ethalon)); var output = result.GetOutput().NormalizeEoln(); var isRightAnswer = output.NormalizeEoln().Equals(slide.Exercise.ExpectedOutput.NormalizeEoln()); if (!isRightAnswer) { ReportSlideError(slide, "Ethalon solution does not provide right answer\n" + "ActualOutput: " + output.NormalizeEoln() + "\n" + "ExpectedOutput: " + slide.Exercise.ExpectedOutput.NormalizeEoln() + "\n" + "CompilationError: " + result.CompilationOutput + "\n" + "SourceCode: " + solution.SourceCode + "\n\n"); } }