Skip to content

Commit

Permalink
- F GenericDiffReporter now reports false if process ran but failed
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed Oct 9, 2023
1 parent 829776a commit c39bdd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.spun.util.SystemUtils;
import org.approvaltests.Approvals;
import org.approvaltests.combinations.CombinationApprovals;
import org.approvaltests.reporters.macosx.DiffMergeMacOsReporter;
import org.approvaltests.reporters.macosx.P4MergeReporter;
import org.approvaltests.reporters.macosx.TkDiffReporter;
import org.approvaltests.reporters.macosx.VisualStudioCodeReporter;
Expand Down Expand Up @@ -78,4 +77,16 @@ public void testIsImage()
Approvals.verifyAll(files, a -> String.format("Image: %s = %s", a,
GenericDiffReporter.isFileExtensionValid(a, GenericDiffReporter.IMAGE_FILE_EXTENSIONS)));
}
@Test
void testRunningNonExistantFile()
{
GenericDiffReporter genericDiffReporter = new GenericDiffReporter("not-a-diff-program.exe");
assertFalse(genericDiffReporter.launch("received.txt", "approved.txt"));
}
@Test
void testProgramDidNotWork()
{
GenericDiffReporter genericDiffReporter = new GenericDiffReporter("false");
assertFalse(genericDiffReporter.launch("received.txt", "approved.txt"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.approvaltests.reporters;

import com.spun.util.ObjectUtils;
import com.spun.util.SystemUtils;
import com.spun.util.ThreadUtils;
import com.spun.util.io.FileUtils;
Expand Down Expand Up @@ -60,7 +59,7 @@ public boolean report(String received, String approved)
launch(received, approved);
return true;
}
private void launch(String received, String approved)
public boolean launch(String received, String approved)
{
try
{
Expand All @@ -69,10 +68,13 @@ private void launch(String received, String approved)
Process process = builder.start();
processOutput(received, process);
ThreadUtils.sleep(800); //Give program time to start
boolean failed = !process.isAlive() && process.exitValue() != 0;
return !failed;
}
catch (Exception e)
{
throw ObjectUtils.throwAsError(e);
SimpleLogger.warning(e);
return false;
}
}
protected void processOutput(String received, Process process)
Expand Down

0 comments on commit c39bdd1

Please sign in to comment.