actually fail the test on errors

explicitly ignoring the one known error in gatherer and all custom sets
This commit is contained in:
Neil Gentleman 2016-10-16 10:34:06 -07:00
parent 510f7a86b6
commit 335950ee8f

View file

@ -7,7 +7,9 @@ import mage.cards.CardSetInfo;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.Sets; import mage.cards.Sets;
import mage.cards.SplitCard; import mage.cards.SplitCard;
import mage.cards.basiclands.BasicLand;
import mage.constants.CardType; import mage.constants.CardType;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@ -62,6 +64,9 @@ public class VerifyCardDataTest {
Collection<ExpansionSet> sets = Sets.getInstance().values(); Collection<ExpansionSet> sets = Sets.getInstance().values();
List<Card> cards = new ArrayList<>(); List<Card> cards = new ArrayList<>();
for (ExpansionSet set : sets) { for (ExpansionSet set : sets) {
if (set.isCustomSet()) {
continue;
}
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) { for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {
cards.add(CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(), cards.add(CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(),
setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo()))); setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo())));
@ -70,6 +75,17 @@ public class VerifyCardDataTest {
return cards; return cards;
} }
private void warn(Card card, String message) {
System.out.println("Warning: " + message + " for " + card.getName());
}
private void fail(Card card, String category, String message) {
failed++;
System.out.println("Error: (" + category + ") " + message + " for " + card.getName());
}
private int failed = 0;
@Test @Test
public void verifyCards() throws IOException { public void verifyCards() throws IOException {
for (Card card : allCards()) { for (Card card : allCards()) {
@ -81,11 +97,17 @@ public class VerifyCardDataTest {
check(card, tokens); check(card, tokens);
} }
} }
if (failed > 0) {
Assert.fail(failed + " Errors");
}
} }
private static final Pattern SHORT_JAVA_STRING = Pattern.compile("(?<=\")[A-Z][a-z]+(?=\")"); private static final Pattern SHORT_JAVA_STRING = Pattern.compile("(?<=\")[A-Z][a-z]+(?=\")");
private Set<String> findSourceTokens(Class c) throws IOException { private Set<String> findSourceTokens(Class c) throws IOException {
if (BasicLand.class.isAssignableFrom(c)) {
return Collections.emptySet();
}
String path = "../Mage.Sets/src/" + c.getName().replace(".", "/") + ".java"; String path = "../Mage.Sets/src/" + c.getName().replace(".", "/") + ".java";
try { try {
String source = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8); String source = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
@ -104,7 +126,7 @@ public class VerifyCardDataTest {
private void check(Card card, Set<String> tokens) { private void check(Card card, Set<String> tokens) {
JsonCard ref = MtgJson.card(card.getName()); JsonCard ref = MtgJson.card(card.getName());
if (ref == null) { if (ref == null) {
System.out.println("Missing card reference for " + card); warn(card, "Missing card reference");
return; return;
} }
checkAll(card, ref); checkAll(card, ref);
@ -146,6 +168,10 @@ public class VerifyCardDataTest {
} }
private void checkColors(Card card, JsonCard ref) { private void checkColors(Card card, JsonCard ref) {
// gatherer is missing the color indicator on one card:
if ("Ulrich, Uncontested Alpha".equals(ref.name)) {
return;
}
Collection<String> expected = ref.colors; Collection<String> expected = ref.colors;
ObjectColor color = card.getColor(null); ObjectColor color = card.getColor(null);
if (expected == null) { if (expected == null) {
@ -157,7 +183,7 @@ public class VerifyCardDataTest {
(color.isGreen() && !expected.contains("Green")) || (color.isGreen() && !expected.contains("Green")) ||
(color.isRed() && !expected.contains("Red")) || (color.isRed() && !expected.contains("Red")) ||
(color.isWhite() && !expected.contains("White"))) { (color.isWhite() && !expected.contains("White"))) {
System.out.println(color + " != " + expected + " for " + card); fail(card, "colors", color + " != " + expected);
} }
} }
@ -172,14 +198,14 @@ public class VerifyCardDataTest {
} }
} }
if (!eqSet(card.getSubtype(null), expected)) { if (!eqSet(card.getSubtype(null), expected)) {
System.out.println(card.getSubtype(null) + " != " + expected + " for " + card); fail(card, "subtypes", card.getSubtype(null) + " != " + expected);
} }
} }
private void checkSupertypes(Card card, JsonCard ref) { private void checkSupertypes(Card card, JsonCard ref) {
Collection<String> expected = ref.supertypes; Collection<String> expected = ref.supertypes;
if (!eqSet(card.getSupertype(), expected)) { if (!eqSet(card.getSupertype(), expected)) {
System.out.println(card.getSupertype() + " != " + expected + " for " + card); fail(card, "supertypes", card.getSupertype() + " != " + expected);
} }
} }
@ -190,7 +216,7 @@ public class VerifyCardDataTest {
type.add(cardType.toString()); type.add(cardType.toString());
} }
if (!eqSet(type, expected)) { if (!eqSet(type, expected)) {
System.out.println(type + " != " + expected + " for " + card); fail(card, "types", type + " != " + expected);
} }
} }
@ -205,7 +231,7 @@ public class VerifyCardDataTest {
if (!eqPT(card.getPower().toString(), ref.power) || !eqPT(card.getToughness().toString(), ref.toughness)) { if (!eqPT(card.getPower().toString(), ref.power) || !eqPT(card.getToughness().toString(), ref.toughness)) {
String pt = card.getPower() + "/" + card.getToughness(); String pt = card.getPower() + "/" + card.getToughness();
String expected = ref.power + "/" + ref.toughness; String expected = ref.power + "/" + ref.toughness;
System.out.println(pt + " != " + expected + " for " + card); fail(card, "pt", pt + " != " + expected);
} }
} }
@ -227,7 +253,7 @@ public class VerifyCardDataTest {
cost = cost.replaceAll("P\\}", "/P}"); cost = cost.replaceAll("P\\}", "/P}");
} }
if (!Objects.equals(cost, expected)) { if (!Objects.equals(cost, expected)) {
System.out.println(cost + " != " + expected + " for " + card); fail(card, "cost", cost + " != " + expected);
} }
} }