Skip to content

Commit

Permalink
Add environment variable to activate snapshot writing
Browse files Browse the repository at this point in the history
  • Loading branch information
mbernardeau committed Jan 30, 2018
1 parent 7e6ed40 commit 362796c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -48,11 +49,14 @@ public boolean matchesSafely(T o) {
if (Files.exists(snapshotPath)) {
// File exists => Compare snapshot file to given object
return compareSnapshot(o, snapshotPath);
} else {
} else if (isWriteSnapshotActivated()) {
// File doesn't exist => Create snapshot file and return true
createSnapshot(o, snapshotPath);
return true;
}
System.out.println("Snapshot writing is not activated in this environment.");
System.out.println("Activate snapshot writing by using -Dtest.snapshots.write");
return false;
}

/**
Expand Down Expand Up @@ -153,4 +157,7 @@ private StackTraceElement getCaller() {
.orElse(null);
}

private boolean isWriteSnapshotActivated() {
return System.getProperty("test.snapshots.write") != null;
}
}

0 comments on commit 362796c

Please sign in to comment.