searleser97 / cpbooster

Competitive Programming Booster
GNU General Public License v3.0
144 stars 30 forks source link

Issue #9, #51: Fix invalid output diff in Windows CMD due to CR in output #98

Closed MohamedIrfanAM closed 8 months ago

MohamedIrfanAM commented 8 months ago

Resolves #51 #9

searleser97 commented 8 months ago

The issue with using trimmed lines is that it also removes spaces at the end or begining, so if someone added some spaces accidentally it will no longer be detected by cpbooster, however, from the code change looks like the issue is just the line ending so probably we could just normalize the line endings depending on the OS without removing the spaces

MohamedIrfanAM commented 8 months ago

In windows compiled output has '\r\n' instead of '\n' at end of each line. This creates two problems

  1. Veredict.AC_WHEN_TRIMMED is found instead of Veredict.AC because output and ans will never be same https://github.com/searleser97/cpbooster/blob/cdfbd6fe91dcde76c101922718542002f934689c/app/src/Test/TesterFactory/Tester.ts#L204C3-L204C3
  2. https://github.com/searleser97/cpbooster/blob/cdfbd6fe91dcde76c101922718542002f934689c/app/src/Test/TesterFactory/Tester.ts#L187 when this .split("\n") is called the outputLines is left with "\r" at end of each line and this creates weird output

Both problems can be fixed if we replace all'\r\n' sequence in the output file with '\n' Something like

    const isWindows = os.type() === "Windows_NT" || os.release().includes("Microsoft");
    let output = execution.stdout?.toString() ?? "";
    const ans = fs.readFileSync(answerFilePath).toString();
    if(isWindows){
      output = output.replace(/\r\n/g, "\n");
    }

May I proceed?

searleser97 commented 8 months ago

In windows compiled output has '\r\n' instead of '\n' at end of each line. This creates two problems

  1. Veredict.AC_WHEN_TRIMMED is found instead of Veredict.AC because output and ans will never be same https://github.com/searleser97/cpbooster/blob/cdfbd6fe91dcde76c101922718542002f934689c/app/src/Test/TesterFactory/Tester.ts#L204C3-L204C3
  2. https://github.com/searleser97/cpbooster/blob/cdfbd6fe91dcde76c101922718542002f934689c/app/src/Test/TesterFactory/Tester.ts#L187

    when this .split("\n") is called the outputLines is left with "\r" at end of each line and this creates weird output

Both problems can be fixed if we replace all'\r\n' sequence in the output file with '\n' Something like

    const isWindows = os.type() === "Windows_NT" || os.release().includes("Microsoft");
    let output = execution.stdout?.toString() ?? "";
    const ans = fs.readFileSync(answerFilePath).toString();
    if(isWindows){
      output = output.replace(/\r\n/g, "\n");
    }

May I proceed?

I agree, let's do that

MohamedIrfanAM commented 8 months ago

I moved isWindows to Util, is that okay? https://github.com/searleser97/cpbooster/pull/98/commits/fe0b510ee72385d22218e3234a903330cd4bd9a6