From d3ffb034820c0b465b8fdc43b288128abb44433f Mon Sep 17 00:00:00 2001
From: Boming Zhang <bomingzh@sjtu.edu.cn>
Date: Tue, 8 Oct 2024 01:57:00 -0400
Subject: [PATCH] feat: support hide output in diff parser

---
 internal/parsers/diff/parser.go | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/internal/parsers/diff/parser.go b/internal/parsers/diff/parser.go
index fc0d106..9b45e33 100644
--- a/internal/parsers/diff/parser.go
+++ b/internal/parsers/diff/parser.go
@@ -28,6 +28,7 @@ type Conf struct {
 			FileName         string
 			AnswerPath       string
 			IgnoreWhitespace bool
+			AlwaysHide       bool
 		}
 	}
 }
@@ -68,22 +69,29 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
 					"actual", result.Files[output.FileName],
 					"answer", string(answer))
 				// If no difference, assign score
-				if compareChars(string(answer), result.Files[output.FileName], output.IgnoreWhitespace) {
+				if compareChars(string(answer), result.Files[output.FileName],
+					output.IgnoreWhitespace) {
 					score += output.Score
 				} else {
-					// Convert answer to string and split by lines
-					stdoutLines := strings.Split(string(answer), "\n")
-					resultLines := strings.Split(result.Files[output.FileName], "\n")
+					comment += fmt.Sprintf("Difference found in `%s`.\n",
+						output.FileName)
+					if !output.AlwaysHide {
+						// Convert answer to string and split by lines
+						stdoutLines := strings.Split(string(answer), "\n")
+						resultLines := strings.Split(
+							result.Files[output.FileName], "\n")
 
-					// Generate Myers diff
-					diffOps := myersDiff(stdoutLines, resultLines)
+						// Generate Myers diff
+						diffOps := myersDiff(stdoutLines, resultLines)
 
-					// Generate diff block with surrounding context
-					diffOutput := generateDiffWithContext(stdoutLines, resultLines, diffOps)
-					comment += fmt.Sprintf(
-						"difference found in %s:\n```diff\n%s```\n",
-						output.FileName, diffOutput,
-					)
+						// Generate diff block with surrounding context
+						diffOutput := generateDiffWithContext(
+							stdoutLines, resultLines, diffOps)
+						comment += fmt.Sprintf(
+							"```diff\n%s```\n",
+							diffOutput,
+						)
+					}
 				}
 			}
 		}