mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-08 21:14:41 -04:00
Include template name in the client test screenshot missing error (#4434)
* Include template name in the error message if possible * Update javadoc
This commit is contained in:
parent
640e77ae59
commit
6816ccd43b
3 changed files with 19 additions and 5 deletions
fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric
api/client/gametest/v1/screenshot
impl/client/gametest
|
@ -77,6 +77,7 @@ public interface TestScreenshotComparisonOptions extends TestScreenshotCommonOpt
|
|||
* as the one that is compared against in this screenshot comparison.
|
||||
*
|
||||
* @return This screenshot comparison options instance
|
||||
* @throws java.util.NoSuchElementException if template image is not provided by path
|
||||
*/
|
||||
TestScreenshotComparisonOptions save();
|
||||
|
||||
|
|
|
@ -361,7 +361,7 @@ public final class ClientGameTestContextImpl implements ClientGameTestContext {
|
|||
}
|
||||
|
||||
if (result == null) {
|
||||
throw new AssertionError("Screenshot does not contain template");
|
||||
throw new AssertionError("Screenshot does not contain template" + optionsImpl.getTemplateImagePath().map(" '%s'"::formatted).orElse(""));
|
||||
}
|
||||
|
||||
return result.add(region.getX(), region.getY());
|
||||
|
@ -418,7 +418,7 @@ public final class ClientGameTestContextImpl implements ClientGameTestContext {
|
|||
|
||||
private static void onTemplateImageDoesntExist(NativeImage subScreenshot, TestScreenshotComparisonOptionsImpl options) {
|
||||
if (TestSystemProperties.TEST_MOD_RESOURCES_PATH != null) {
|
||||
Path savePath = Path.of(TestSystemProperties.TEST_MOD_RESOURCES_PATH).resolve("templates").resolve(options.getTemplateImagePath() + ".png");
|
||||
Path savePath = Path.of(TestSystemProperties.TEST_MOD_RESOURCES_PATH).resolve("templates").resolve(options.getTemplateImagePathOrThrow() + ".png");
|
||||
|
||||
try {
|
||||
Files.createDirectories(savePath.getParent());
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.InputStream;
|
|||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
|
@ -52,7 +53,7 @@ public final class TestScreenshotComparisonOptionsImpl extends TestScreenshotCom
|
|||
|
||||
@Override
|
||||
public TestScreenshotComparisonOptions save() {
|
||||
return saveWithFileName(getTemplateImagePath());
|
||||
return saveWithFileName(getTemplateImagePathOrThrow());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,8 +90,20 @@ public final class TestScreenshotComparisonOptionsImpl extends TestScreenshotCom
|
|||
return this;
|
||||
}
|
||||
|
||||
public String getTemplateImagePath() {
|
||||
return this.templateImage.left().orElseThrow();
|
||||
/**
|
||||
* Gets the path to the template image, relative to the {@code templates} directory, if one was provided.
|
||||
*/
|
||||
public Optional<String> getTemplateImagePath() {
|
||||
return this.templateImage.left();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the template image, relative to the {@code templates} directory, if one was provided.
|
||||
*
|
||||
* @throws java.util.NoSuchElementException if template image is not provided by path
|
||||
*/
|
||||
public String getTemplateImagePathOrThrow() {
|
||||
return this.getTemplateImagePath().orElseThrow();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Add table
Reference in a new issue