Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recipe item #1319

Merged
merged 4 commits into from Nov 27, 2022
Merged

Fix recipe item #1319

merged 4 commits into from Nov 27, 2022

Conversation

Veracity0
Copy link
Contributor

Considering this was the second time it happened, I thought I would write a unit test.
I wrote a little ash script:

foreach it in $items[] {
    string recipe = it.string_modifier("Recipe");
    if (recipe == "") continue;
    print(it + " is a recipe for " + recipe);
    item ritem = recipe.to_item();
    if (ritem == $item[none]) {
	print("item '" + it.name + " has recipe '" + recipe + "' which is not an item");
    }
}

Which yields this:

plans for depleted Grimacite hammer is a recipe for depleted Grimacite hammer
plans for depleted Grimacite gravy boat is a recipe for depleted Grimacite gravy boat
plans for depleted Grimacite weightlifting belt is a recipe for depleted Grimacite weightlifting belt
plans for depleted Grimacite grappling hook is a recipe for depleted Grimacite grappling hook
plans for depleted Grimacite ninja mask is a recipe for depleted Grimacite ninja mask
plans for depleted Grimacite shinguards is a recipe for depleted Grimacite shinguards
plans for depleted Grimacite astrolabe is a recipe for depleted Grimacite astrolabe
fumble formula is a recipe for concoction of clumsiness
mother's secret recipe is a recipe for white chocolate chip brownies
fettucini épines Inconnu recipe is a recipe for fettucini épines Inconnu
slap and slap again recipe is a recipe for slap and slap again
Recipe of Before Yore: ratatouille de Jarlsberg is a recipe for ratatouille de Jarlsberg
Recipe of Before Yore: Jarlsberg's vegetable soup is a recipe for Jarlsberg's vegetable soup
Recipe of Before Yore: roasted vegetable of J. is a recipe for roasted vegetable of Jarlsberg
Recipe of Before Yore: St. Pete's sneaky smoothie is a recipe for St. Pete's sneaky smoothie
Recipe of Before Yore: Pete's wily whey bar is a recipe for Pete's wiley whey bar
Recipe of Before Yore: Pete's rich ricotta is a recipe for Pete's rich ricotta
Recipe of Before Yore: Boris's beer is a recipe for Boris's beer
Recipe of Before Yore: honey bun of Boris is a recipe for honey bun of Boris
Recipe of Before Yore: Boris's bread is a recipe for Boris's bread
Recipe of Before Yore: Calzone of Legend is a recipe for Calzone of Legend
Recipe of Before Yore: Pizza of Legend is a recipe for Pizza of Legend
Recipe of Before Yore: roasted vegetable focaccia is a recipe for roasted vegetable focaccia
Recipe of Before Yore: plain calzone is a recipe for plain calzone
Recipe of Before Yore: baked veggie ricotta is a recipe for baked veggie ricotta casserole
Recipe of Before Yore: Deep Dish of Legend is a recipe for Deep Dish of Legend

Notice that it does not report an error. That is good.

My options:

  1. Don't print the successes. Submit an ASH script which prints "all recipes match" if they do into CustomScriptTest.
  2. Make that a Java unit test which asserts that each recipe is an item and includes the bad item in the message.

Except, neither of those works on my system.

  1. CustomScriptTest does not print the filename of the failing test. You think it does? Nope.

CustomScriptTest.java:

  @ParameterizedTest
  @MethodSource("data")
  void testScript(String script) throws IOException {
    String expectedOutput = getExpectedOutput(script).trim();
    ...
    assertEquals(expectedOutput, output, script + " output does not match: ");
  }

I munged the expected output for one script and did this:

./gradlew test --tests=CustomScriptTest >& /tmp/test.txt

test.txt contained this:

CustomScriptTest > testScript(String) > net.sourceforge.kolmafia.CustomScriptTest.testScript(String)[45] STANDARD_OUT
    12 ms	[CustomScriptTest:testScript]

CustomScriptTest > testScript(String) > net.sourceforge.kolmafia.CustomScriptTest.testScript(String)[45] FAILED
    org.opentest4j.AssertionFailedError at CustomScriptTest.java:83

Completely useless at identifying which script was tested - except it was the 45th script tested.
The helpful string supplied to assertEquals() is nowhere to be seen.

  1. Given that customized error messages do not work, how, pray tell, do I get my Java unit test to print the bad recipe?

So, no tests.

@Veracity0 Veracity0 requested a review from a team as a code owner November 27, 2022 17:55
@codecov
Copy link

codecov bot commented Nov 27, 2022

Codecov Report

Merging #1319 (af2428e) into main (ae2b9d6) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1319      +/-   ##
============================================
- Coverage     33.11%   33.10%   -0.02%     
+ Complexity    16547    16544       -3     
============================================
  Files          1045     1045              
  Lines        162890   162890              
  Branches      35336    35336              
============================================
- Hits          53945    53925      -20     
- Misses        99524    99548      +24     
+ Partials       9421     9417       -4     
Impacted Files Coverage Δ
...net/sourceforge/kolmafia/textui/DataFileCache.java 37.73% <0.00%> (-5.67%) ⬇️
.../sourceforge/kolmafia/preferences/Preferences.java 84.70% <0.00%> (-1.60%) ⬇️
...forge/kolmafia/textui/langserver/FilesMonitor.java 79.48% <0.00%> (-1.29%) ⬇️
...sourceforge/kolmafia/textui/langserver/Script.java 84.04% <0.00%> (-1.07%) ⬇️
...lmafia/swingui/widget/ListCellRendererFactory.java 27.52% <0.00%> (-0.48%) ⬇️
...eforge/kolmafia/swingui/panel/GearChangePanel.java 58.60% <0.00%> (-0.28%) ⬇️
src/net/sourceforge/kolmafia/KoLCharacter.java 58.30% <0.00%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae2b9d6...af2428e. Read the comment docs.

Copy link
Member

@midgleyc midgleyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that JUnit not printing the actual message had to be configurable, but I can't actually successfully configure it.

@jaadams5
Copy link
Contributor

I made a failing script. I ran all tests from a command line. The failing script was not mentioned in what went to the console. But I was referred to a local file file:///C:/KoLmafia/build/reports/tests/test/index.html. That file included the text CustomScriptTest. [44] test_test.ash which told me the failing script was the 44th, test_test.ash. The link from that page went to test output that started with org.opentest4j.AssertionFailedError: test_test.ash output does not match: so the script name is being printed when the assertion failure occurs.

@Veracity0 Veracity0 enabled auto-merge (squash) November 27, 2022 20:56
@Veracity0 Veracity0 merged commit 87ac739 into main Nov 27, 2022
@Veracity0 Veracity0 deleted the recipe-item branch November 27, 2022 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants