Commit graph

344 commits

Author SHA1 Message Date
Steve Cotton
b74216d6c8 Unit tests for changing abilites with filters in [event]name=attack
The existing backstab tests' common code is moved to a utility file
for reuse in other tests, because it can be used to check whether a
weapon special was active during the damage calculations.

Git's diff can show a lot of lines being deleted, but that's just
because it's showing a file being copied, and then half of each copy
being removed.
2022-10-21 20:26:12 +02:00
Pentarctagon
8bc084bc0b Add tests for pre_attack event. 2022-08-10 09:07:30 -05:00
spixi
0f763cfdd6 Add pre attack event #4075 2022-08-10 09:07:30 -05:00
Celtic Minstrel
5a184bbb40 Split wesnoth.game_events.add into multiple functions
Basically this means each of the call modes of the old function is now a separate function.

- add_repeating and add_menu take an ID and a function
- add_wml takes variable substitution setting and a config
- add takes the full options table
2022-07-18 21:56:42 -04:00
Celtic Minstrel
8a72206f02 Unit tests for the new filter options 2022-07-18 21:56:42 -04:00
Celtic Minstrel
245cd57d24 Unit tests for each way of assigning an action to an event handler 2022-07-18 21:56:42 -04:00
Celtic Minstrel
666571caa2
Fix load_string() ignoring the passed chunk name (#6794)
Complete with a unit test!
The test results in PASS_BY_VICTORY if it fails,
which is a bit weird, but it does work.
2022-06-24 01:49:28 -04:00
Celtic Minstrel
be8783154e
Add event unit tests for dynamic filters and names (#6785) 2022-06-21 22:25:01 -04:00
newfrenchy83
5c2aaeac2d modify testing for show diffrence between using ('add/sub' attribute)and value with cumulative=yes
in this test, two same leadership with value attribute and cumulative=yes add their value then what two leadership with same id and 'add' attribute using on 'add' only(the highest when 'add' value is different)
2022-05-19 18:13:43 -05:00
newfrenchy83
856aafc8d5 add a test case for 'cumulative=yes'
this test is added for verify what cumulative=yes work in same time what 'add' and 'sub' and what using of these attributes in[leadership] don't be
changed, only using of cumulative work anew like in 1.14
2022-05-19 18:13:43 -05:00
Steve Cotton
0f6a94f2a7 Unit tests for [drains], [poison] and [slow], with apply_to=opponent
Slightly different to PR #6582, which was the 1.16 version of this. The five
lines that were labelled `preserving known bug` are changed to test that it's
been fixed.

Here `apply_to=opponent` means that the weapon special gives the opponent the
ability, the unit that should get poisoned or slowed is the unit that has the
weapon special.

There's a known bug in 1.16, that `apply_to=opponent` check the wrong unit to
see it it's `unpoisonable`, `undrainable` etc. It also checks the wrong unit to
see if it's already poisoned or slowed, so a battle between two units that both
have reverse-poison results in at most one being poisoned.

Most of the credit for this is Newfrenchy's, as he's already written a fix
and a WML based test. This commit uses a Lua test instead to test more
combinations of statuses.

This adds a `COMMON_KEEP_A_B_UNIT_TEST` macro, which is a counterpart to the
`GENERIC_UNIT_TEST` macro that starts the leaders next to each other, ready
to attack. The `A_B` is because I'm planning a multiple-side variant too.

There's no test for [petrify], as simulate_combat doesn't provide a stat for it.

This tests only 3 of the 6 abilities whose behavior changed in 650f70405f.
My thoughts on testing the others are:
* [firststrike]'s test is in 650f70405f.
* [drains], [poison] and [slow] are tested here.
* [petrify] ends combat, it's also not exposed in simulate_combat's stats.
* [plague] triggers after combat ends.
2022-04-19 15:27:49 +02:00
Steve Cotton
c5dec73784 Unit tests: make separate files for each starting position
Turn the 4 side setup of the firststrike_and_laststrike test into a macro
called `COMMON_KEEP_A_B_C_D`for reuse in other tests.

The comment for `GENERIC_UNIT_TEST` gets a couple of extra paragraphs.

All the files get wmlindent run on them, which reindents `FAIL_IF_NOT`.

The main reason for having these is separate files is Git's fuzzy-patch
matching when merging and rebasing. Having large blocks of identical text
in `wml_unit_test_macros.cfg` can mean the wrong section gets patched.
2022-04-18 04:48:53 +02:00
Celtic Minstrel
a76aa9bddc
Add wesnoth.interface.add_floating_label as a replacement for wesnoth.print (#5837)
This returns a label handle which allows you to remove, reposition, or replace the label later.

In addition to all the features of wesnoth.print, you can now specify where the label appears onscreen, as well as a fadeout time separate from the duration.

You can also anchor the text to an edge or corner instead of centering in on the screen,
specify the maximum width it can occupy as an absolute width or a percentage,
and specify a background colour and transparency.

It includes a demo scenario that demonstrates many of the capabilities of the API.
To play the demo scenario, run with -toverlay_text_demo or select it from the in-game test list.
2022-04-10 13:00:29 -04:00
newfrenchy83
650f70405f
fix [firststrike] special with apply_to=opponent crashes Wesnoth 1.17.x (#6574)
As reported on the forum in https://forums.wesnoth.org/viewtopic.php?p=672374#p672374
If a unit with "last strike" ([firststrike] special with apply_to=opponent, on any of its attacks)
was targeted by other unit for attack, wesnoth crashed.

Fix similar problems for other weapon specials like poisons, when two users of specials with
apply_to=opponent fought, one fighter only could be poisoned or slowed.

* Add a unit test for poison
* Add a unit test for firststrike and laststrike
2022-04-08 02:30:14 +02:00
Steve Cotton
071ba9d7d6 Add a unit test for [move_unit]location_id with an occupied hex
(cherry picked from commit ba1767f8b9)
2022-03-31 09:33:13 +02:00
Steve Cotton
2888f0417d Add unit tests for Lua API wesnoth.simulate_combat
(cherry picked from commit d96968b2ec)
2022-03-23 07:43:10 +01:00
Celtic Minstrel
57c2e6de4a Fix shroud unit tests not being classified as unit tests and showing up in the in-game test list 2022-03-11 09:46:33 -05:00
Celtic Minstrel
876827c644 Update deprecated uses of [replace_map] 2022-03-11 09:45:56 -05:00
Pentarctagon
11631775a4 Add code comments stating what each unit test is testing. 2022-02-18 02:32:04 +01:00
Wedge009
f983a998a2 Replace deprecated share_maps and share_view with share_vision.
Closes #6496.

share_maps=yes -> share_vision=shroud
share_view=yes -> share_vision=all
2022-02-15 22:08:03 +11:00
Steve Cotton
556c66e4d0 Refactor the backstab unit test
Based on Pentarctagon's documentation addition, and also improving
the encapsulation of the test to take a boolean value for whether
the ability should be active instead of the expected damage total.
2022-02-02 20:46:37 +01:00
Steve Cotton
eacf26a2a8 Fix [store_unit]'s stored coordinates for recalls
Units on the recall list might have x,y coordinates that are on the map, which
therefore need to be replaced with "recall,recall" within [store_unit]. The
existing code created a temporary variable, changed the coordinates, and then
returned the unchanged original instead of the temporary.

Add a new test that `[put_to_recall_list]` followed by `[modify_unit]`
doesn't move the unit back to the map.

(cherry picked from commit 096d8aba14)
2022-01-12 06:57:35 +01:00
newfrenchy83
a202146b89 correction to testing 2021-12-09 18:04:24 +01:00
newfrenchy83
0deb6dcce2 fix error in line 86 2021-12-09 18:04:24 +01:00
newfrenchy83
17e0c244ab add wmlindent in test and comment
i'm not sure to have implemented wmlindent correctly, i hope don't done error.
2021-12-09 18:04:24 +01:00
newfrenchy83
3e70b335da fix 'add' and 'sub' not added in leadership shema validation 2021-12-09 18:04:24 +01:00
Luther
bff219d41f
Expand the reduce function to both fold and reduce (#6337) 2021-12-04 17:46:12 -05:00
Steve Cotton
69ee817955
Remove the fast path of [modify_unit] (#6223)
Always use the "slow path", because it stores and unstores the unit, triggering
the desired side effects of unstoring a unit.

Fixes issue #5133, and tests that with the new unit test.

Fixes bug #4978, that changing the facing wasn't updating the display.

This corresponds to 1.16's commit 13c5d8a96e,
that commit merely disabled the fast path to be a minimal change.
2021-11-05 21:39:38 +01:00
Steve Cotton
551357f48b Fix an off-by-one in mapgen's x and y filters, and add unit tests
Fixes the currently suspected root cause of #5108, but requires further testing
to confirm that it fixes that issue.

Closes #6501 (the question of how to test the mapgen filter).

(cherry picked from commit 30f50bac68)
2021-09-01 15:48:32 +02:00
Celtic Minstrel
300b4492b8 Lua API: Ensure unit test assertions specify a message string 2021-07-30 19:22:57 -04:00
Celtic Minstrel
03ee904513 Update the shroud unit tests and add a few more for cases new in 1.16 2021-07-30 19:22:57 -04:00
Celtic Minstrel
3af768150e Add unit tests for the Lua shroud functions 2021-07-30 19:22:57 -04:00
Pentarctagon
34ed9b434b
Add a few more wesnoth version unit test checks. 2021-07-13 23:01:46 -05:00
Celtic Minstrel
4ec60b99d9 Lua: Update all mainline references to the helper module 2021-07-07 01:32:05 -04:00
Steve Cotton
f9fc806fd2 Add a unit test for wesnoth.current.synced_state
The edge-case of calling evaluate_single within an unsynced event was
surprising, and I'm not sure it's correct. However, as we're about to
release the 1.16 branch I think it's better to include that as a test
that the API doesn't change during the stable branch.
2021-07-07 02:09:49 +02:00
Steve Cotton
17edbcb90a When starting or loading a game, warn if the next scenario is unknown
Check that the scenario's next_scenario= exists, and display a warning
if it would lead to an "Unknown Scenario" error. This also checks any
[endlevel] tags in events.

The error message includes the id of the missing scenario, but is mainly
a recommendation to check the forums and report a bug in the campaign.

This version has a short, one-size-fits-all, text for the error message.
2021-06-19 22:22:19 +02:00
Celtic Minstrel
5a1e38e99b
Add wesnoth.sync module for the synchronization-related commands (#5862) 2021-06-19 15:39:10 -04:00
Celtic Minstrel
a03d59d7eb Lua: Add a new schedule module
The primary components of this are:
- wesnoth.current.schedule
- wesnoth.map.get_time_area()
- wesnoth.schedule module
2021-06-19 11:07:53 -04:00
Celtic Minstrel
d39e6b3f42 Schema: Make turns validation more generic
This means other things can now easily accept the special keyword "unlimited".
2021-06-18 13:53:34 -04:00
Celtic Minstrel
0c42cdc038
Enable translation mark validation by the schema (#5800)
- The t_string type is now a schema built-in type and no longer attempts a regex match.
- You can also specify that non-t_string types may be optionally-translatable; this case supports a regex match on the string (but note that the translation mark is not part of the match).
- Error messages involving keys with very large values ( > 128 characters) will now truncate the value.
- To account for occasional cases where the schema is intentionally violated, the --validate command-line option now automatically defines the SCHEMA_VALIDATION preprocessor define.

A key validates as type t_string if one of the following is true:
- The key is not present
- The key has at least one segment with a translation mark
- The key is blank (an empty string)

Any type other than t_string is not allowed to be translatable by default, unless you specify allow_translatable=yes in the [type] tag.

An optionally-translatable string could also be defined as a union of t_string and some other type.
2021-06-14 23:59:52 -04:00
Steve Cotton
63bb15b94e Add a unit-test for the backstab ability 2021-06-06 08:45:36 +02:00
newfrenchy83
bf6b09007c
add 'unslowable' and 'unpetrifiable' status (#5788) 2021-05-27 13:35:49 -04:00
Steve Cotton
c560b0efab Add attribute apply_to_vision to [effect]apply_to=movement
When processing [effect]apply_to=movement, if apply_to_vision is 'yes'
(which is the default) then the vision points will change by the same amount.
Previously, it sometimes affected vision and sometimes didn't; for most cases
where it makes a difference, I expect it to be a change from unanticipated
behavior to expected behavior.

Please refer to the new unit test added in this commit for more detailed docs;
that test is also a rough draft for the Wiki update needed when this merges.

The reason it sometimes affected vision was that the special value of -1 vision
points was interpreted as "use the value of the max movement points instead".
The special value of -1 is still supported and frequently used, and refactor that
is out of scope for this commit - it's easy to check when the code path changed
in this commit is used, however it's considerably more complex to find all
routes that create a unit with vision set to -1.

I'm expecting one add-on, Rebirth In Nature, to need a large update for this;
as well as a trivial change needed to the Add Creature Pack.

There are several mods that have their own handling for vision, recalculate the
values frequently, and are expected to continue working as before, as they'll
just overwrite any changes that the engine makes.
* Proper Flying Mod / Proper Vision Mod
* LotI
* Blessed Altar Mod
* Shards Era's `CALCULATE_WEAPONS_ONLY` macro
* Castle of Evil Spirit

Rebirth In Nature is an RPG-style campaign that expects the player's unit to
have vision separated from movement along with right-click menus that change
the character's movement, this will probably need `apply_to_vision=no` in
many places. OTOH, its `item_id=mobility` uses `apply_to=movement` followed by
`apply_to=vision` to implement in 1.14 what this change will make default
behavior in 1.16.

There are a few sharpshooter units which have vision better than their
movement. If given a buff which boosts their movement, this will give
them a buff to vision too; likely a change towards expected behavior.
* Archaic Era's Royal Ranger
* Ageless Era's Royal Ranger and Dwarvish Forest Sniper
* Eastern Europe at War's Yacht and Great Yacht
* Era of More Units's Lone Wolf
* Southernerns has several sharpshooters
* WWII Era has several sharpshooters
* War of Dominions has some guard towers with very low movement

Silver Age has abilities that modify vision based on time-of-day, but unlike
the Proper Flying Mod and LotI these are done by adding and removing objects
that add or subtract one vision point, these should be unaffected by this
change. Unrelated to that, it declares values for `[unit_type]vision=` even
when the value is the same as max moves - like the sharpshooters this means
that buffs to their movement wouldn't have buffed their vision but now do.

There are few units with vision less than movement. Generally these seem to be
missile weapons that are represented as units, and they probably won't meet any
apply_to=movement statements - even if a movement power-up is available, the
player would probably choose a different unit.

The Add Creature Pack has two creatures (the Cactose Elder and Carnivore Fatal
Plant) that have reduced vision, along with AMLAs that increase those units'
movement; these AMLAs will need to use `apply_to_vision=no`. These two
creatures are used in Castle of Evil Spirit, but they won't get enough
experience to get an AMLA there.

Fixes #3356.
2021-05-13 18:02:36 +02:00
Celtic Minstrel
574bc1a36e Resolve [terrain_mask]mask_file= relative to the [binary_path] like map_file= is 2021-05-11 14:52:22 -04:00
Celtic Minstrel
9bf189a615 Move wesnoth.create_side -> wesnoth.sides.create 2021-05-11 14:52:19 -04:00
Celtic Minstrel
2a1fc43860 Add a versions userdata for a cleaner way to compare and manipulate game versions 2021-05-11 14:50:29 -04:00
Celtic Minstrel
b20e226f30 Unit test to verify that [event]delayed_variable_substitution=no works 2021-05-08 17:15:02 -04:00
Steve Cotton
df41f13e41 Rewrite the WML unit test for sighted events
The old version's [event]name=sighted had a {RETURN} statement in it,
which meant the test stopped on the first sighting. Most of the test
wasn't testing anything.
2021-05-06 01:21:59 +02:00
newfrenchy83
00452c0187
add 'ability_id_active' attribute to filter (#5739)
Add 'ability_id_active' attribute to filter

Until now, only the type of ability could be filtered with activity, and id only for unit who have ability, same if she's inactive.
2021-05-03 14:38:05 -05:00
Pentarctagon
afded0db32
Remove extraneous translation marks from tests. 2021-04-28 13:40:56 -05:00