Commit graph

119 commits

Author SHA1 Message Date
Steve Cotton
2b8e887bcf Fix [resistance_defaults] and [terrain_defaults] (issue #5308)
The bug introduced in fcd0ceda is fixed by ensuring that movetype::merge() is
called with the strings "movement_costs", "vision_costs" and "jamming_costs"
instead of "movement", "vision" and "jamming".

Both [terrain_defaults][movement] and [terrain_defaults][movement_costs] are
supported and equivalent, as added to the master branch in 3522eb2c.

These now work again:

    [resistance_defaults]
        id="special_res_for_test"
        default="30"
    [/resistance_defaults]

    [resistance_defaults]
        id="copy_of_arcane"
        default="(arcane)"
    [/resistance_defaults]

    [terrain_defaults]
        id="special_terrain_for_test"
        [movement]
            default="(swamp_water + 1)"
            orcishfoot="(swamp_water * 2)"
        [/movement]
    [/terrain_defaults]

Formulas can now access other parts of the movetype too, as this allowed the
code to be the same as in 1.15:

    [terrain_defaults]
        id="special_terrain_for_test"
        [movement_costs]
            default="(swamp_water + 1)"
            orcishfoot="(vision_costs.swamp_water * 2)"
        [/movement_costs]
    [/terrain_defaults]
    [terrain_defaults]
        id="special_terrain_for_test"
        [defense]
            default="(20 + 7 * movement_costs.special_terrain_for_test)"
        [/defense]
    [/terrain_defaults]

The formula handling will recognise "resistance", "movement_costs",
"vision_costs", "jamming_costs" and "defense". For [resistance_defaults], the
formula will recognise both "(arcane)" and "(resistance.arcane)" as equivalent,
similarly for [terrain_defaults] "(swamp_water)" is a shorthand for whichever
subtag is being patched.

A [terrain_defaults] tag may use data added in a previous [terrain_defaults],
as in the examples above where the second tag's [defense] is based on the first
tag's [movement_costs], this gives orcish grunts on the special terrain a 62%
chance to be hit. However, relying on data in the same [terrain_defaults] that
creates or changes it is unsupported - if the [movement_costs] and [defense]
were in a single [terrain_defaults] tag then the result would be implementation
defined, because no guarantee is made of the order in which the children of the
tag are processed.

The unit tests for [terrain_defaults] and [resistance_defaults] must stay
out-of-tree until we support some method of testing them without affecting the
core units' stats during other tests. The test added here is limited to
checking the ways that WML can read the stats, it's also a framework for the
out-of-tree parts to use.

This is a squashed cherry pick of these commits from 1.15:
* 72863e578b (the unit test)
* 0ba433203e
* 3522eb2c2a (adding the aliases)
* 0035b776d7 (fix for empty children)
2021-03-05 18:09:19 +01:00
Steve Cotton
bba67f2bb3 Separate unit test statuses for WML exceptions and strict warnings (fixes #4471)
Backported to 1.14 so that this mechanism can be used instead of a793bce96's
method of running the cve_2018_1999023 test in non-strict mode, which means
that the test now passes without making equivalent-to-a793bce96 changes to
projectfiles/VC12/WML_tests.cmd and projectfiles/VC16/WML_tests.cmd.

This was part of working out whether a subset of the "fail" tests could be run
in one Wesnoth instance. To run a test that returns TEST_FAIL_BROKE_STRICT with
any other test would require a mechanism to reset lg::broke_strict()'s flag.

All tests that fail with an {ASSERT} will also set the lg::broke_strict() flag,
the tests with the new status are only those that would pass without the strict
flag.

In the SUF tests, change a test from fail-on-success to breaks-strict, rename
the formula tests and add some comments. The rename is because "fai" is
"Formula AI", an obsolete name for WFL.

(cherry-picked from commit 7359fddecb)
2019-12-24 18:13:13 +01:00
Steve Cotton
aa9ff15a0f Add unit tests for movement and vision costs
Includes tests for changing the terrain costs, and aliased terrains,

(cherry picked from commit 358f564301)
2019-07-31 14:07:00 +02:00
josteph
36c796852b Add test for #3663 2018-10-27 20:41:29 +00:00
Jyrki Vesterinen
7f5ae37816 Extend the first CVE-2018-1999023 unit test to also try loadstring()
Like @gfgtdf pointed out, loadstring() is still supported by Lua in the
name of backwards compatibility, even though it was deprecated in Lua 5.2
and is no longer mentioned in Lua manual. Thus, as of committing this it's
actually possible to load Lua bytecode.

Let's unit test this to ensure that we don't reintroduce this
vulnerability.
2018-07-28 07:38:00 +03:00
Jyrki Vesterinen
ad90f368a3 check_utf8.sh: don't check the Lua bytecode file
This avoids one of the two files which are currently causing macOS SCons
builds to fail in the master branch.
2018-07-27 23:34:11 +03:00
gfgtdf
164ff74f0f wml test for cve-2018-1999023
this test whether we succesfully prevent the exceution and parsing of
precompiled lua chunks, which can be used to break the lua sandbox.
This test does not cover all affected functions in particular not the ai
code that loads lua chunks.
2018-07-24 02:52:57 +02:00
Toom
739df85e1d Add WML unit test for unupgradable (#3336)
* Add WML unit test for unupgradable

* Follow [do_command] requirements
2018-07-22 17:51:22 -04:00
gfgtdf
99ddf3bce8
disallow attacking with disabled attacks via [do_command]
this fixes some rare cheats in mp.
2018-06-17 22:56:50 +02:00
mattsc
1017a57f39 Replace remaining uses of FOREACH macro 2018-05-14 17:12:01 -07:00
mattsc
c9ef14ad54 Do not load helper.lua where it is not used any more 2018-05-12 17:41:42 -07:00
mattsc
0396461309 Remove unnecessary inclusions of helper.set_wml_action_metatable {} 2018-05-12 17:41:42 -07:00
mattsc
8ff8acea72 Lua code: replace deprecated helper.[gs]et_variable_array() calls 2018-05-12 17:41:40 -07:00
mattsc
acf4269f6a Lua code: replace deprecated wesnoth.get_all_vars() calls 2018-05-12 17:41:37 -07:00
mattsc
51b2dbec19 Lua code: replace deprecated wesnoth.set_variable() calls 2018-05-12 17:41:28 -07:00
mattsc
2922b19802 Lua code: replace deprecated wesnoth.get_variable() calls 2018-05-10 19:55:31 -07:00
Celtic Minstrel
ad7b0ef140 WML Unit Tests: Fix issues found by the schema validator
With this, the WML unit tests are as clean of schema errors as they can get
The two remaining errors are unit tests for dealing with invalid input,
so they are intentionally violating the schema.
2018-04-11 22:28:41 -04:00
Celtic Minstrel
ea739324df Remove some uses of set_wml_tag_metatable 2018-03-24 13:53:20 -04:00
Charles Dang
0cb9f0d622 Data/Test: wmlindent run
[ci skip]

Addresses some of the whitespace issues mentioned in #2613
2018-03-09 11:22:00 +11:00
Jyrki Vesterinen
4500fa6412 Add a unit test to ensure that Lua API rejects dollar signs in tag names 2018-02-10 08:54:23 +02:00
Matthias Krüger
b11d3fdcbe fix a bunch of typos found by codespell in data directory.
https://github.com/lucasdemarchi/codespell
2018-02-06 23:03:06 +11:00
Jyrki Vesterinen
1386e3945c Added unit tests about which WML tag names Lua API accepts 2018-01-17 23:23:13 +02:00
Charles Dang
8ae99bc86a Added some event unit tests by @Pentarctagon
Tests event execution order and events with variable names.
2018-01-11 13:12:28 -05:00
Gregory A Lundberg
eaccef65f8 Add WML unit tests for [for] tag 2017-06-21 21:18:24 -05:00
Celtic Minstrel
b6eedd3df6 Allow launching test scenarios from the titlescreen
Unit test scenarios are excluded. There is no button and no default hotkey.
2017-05-04 19:20:44 -04:00
Celtic Minstrel
8d4cf3cf62 Shorten requires where possible 2017-05-03 02:42:25 -04:00
Jyrki Vesterinen
0fe2fd4c00 Fix the modify_ai_change_default_facet unit test
The test changes the default facet, which takes effect only if no other
facet takes priority. Thus, in turns 7 and 8, the test should expect attack
depth of 7, not 8.

Thanks to @CelticMinstrel for help.
2017-03-02 19:44:50 +02:00
Celtic Minstrel
4e7a2072f0 Fix a unit test still using experimental syntax 2017-02-28 14:11:45 -05:00
Gregory A Lundberg
f4e2cc6681 Fix a unit test
For some reason the macro RESULT causes the test to crash Lua.

Don't see why. Don't know why this fixes it. But this gets the tests working.
2016-10-18 09:01:45 -05:00
Spixi
5588642c81 Allow firing an event by id instead of name. 2016-07-23 12:23:19 +02:00
gfgtdf
68e5e7d7dc fix travis tests 2016-05-20 15:36:51 +02:00
Celtic Minstrel
106f1510d3 Fix unit test 2016-03-24 12:59:59 -04:00
Celtic Minstrel
cb0fad078a WML unit tests for simple aspects 2016-03-22 07:22:22 -07:00
Celtic Minstrel
240b5f61a7 Output formula errors in unit filters to WML error stream
(And consider them to match no units)
2016-03-17 23:27:03 -04:00
Celtic Minstrel
26a2638f2c Make the formula and Lua views of a unit coincide more closely
Several keys were either missing or misnamed in the formula view.
These have been changed to match the Lua and WML names for the keys.
This affects canrecruit, moves, and max_moves, as well as status.

In addition, a large number of keys were missing entirely from the formula view.
Most of these keys have now been added and can be accessed from formulas.
A few that have little use in filters (such as image_mods or profile) are still missing.

The Lua view missed a few keys that the formula view did provide.
Although these could in principle have been obtained by using the special __cfg key,
they have now been added to the Lua view anyway.
2016-03-17 23:27:03 -04:00
Celtic Minstrel
64ddd50895 Fix [for] loop not iterating the correct number of times
(when the array length changes during the loop)
2015-12-29 23:40:36 -05:00
gfgtdf
7f13156c28 Revert "Rename team_name/user_team_name to team_id/team_name (old syntax still valid)"
And related commits.

This reverts commit 545253ec2b.
This reverts commit 1215f65eb8.
This reverts commit 11664f4024.
This reverts commit e948df3424.
This reverts commit 3781e7839f.

This commits were reverted to exclude them from wesnoth 1.13.2 release because:
1) We are still unsure about the best name oftthese attributes
2) This breaks multiple campaigns, including LoW and the tutorial.
Feel free to revert this revert after 1.13.2 when thse issues can be solved..
2015-12-10 21:29:52 +01:00
gfgtdf
0241f5687e fix failing lua_get_sides test 2015-12-09 02:26:39 +01:00
aquileia
88d4c15c87 Exclude test strings from gettext 2015-12-02 00:37:14 +01:00
Charles Dang
e948df3424 Updated unit tests to use new team id/name syntax 2015-10-26 13:40:44 +11:00
Celtic Minstrel
f224e2a073 Fix WML unit tests 2015-10-07 20:09:57 -04:00
Charles Dang
798c59c7bd Replace most instances of a single-hex [terrain_mask] action with [terrain]
One file is deliberately not converted until we get a dedicated mask test
2015-10-07 17:00:53 +11:00
Celtic Minstrel
aa2e24d1b7 Finally fix all the [for] issues. Probably.
(With unit tests to back it up!)

- Fixes [for]step=0
- Fixes [for]start,stop=0,0
- Fixes [for]start,end,step=0,1,-1
- Probably fixes several other things too
2015-10-06 13:51:28 -04:00
Celtic Minstrel
7e26e09061 Fix erroneous handling of [break]/[continue] in [elseif] 2015-09-23 00:25:31 -04:00
Celtic Minstrel
0d49eeeb39 Add SUCCEED/FAIL macros for WML test cases 2015-09-22 23:13:38 -04:00
Celtic Minstrel
aec99429c4 Merge branch 'break-continue' into foreach 2015-09-20 00:48:39 -04:00
Celtic Minstrel
3c329408ce Implement [break], [continue], [return] tags (they take no arguments) 2015-09-20 00:47:23 -04:00
Celtic Minstrel
a5184181df Fix SUF $this_unit only working within [filter_wml] 2015-09-19 00:19:26 -04:00
Ignacio R. Morelle
987f0157c2 Revert recent map code changes related to map mask handling
They break some unit tests and we can't seem to decide whether the tests
are truly at fault (that is beyond the fact that they _should_ certainly
use [terrain] instead of [terrain_mask]) or whether the issue that the
author was trying to fix at the beginning was an issue in the first
place.

This reverts the following commits:

 * commit 6b78073b49
 * commit 2f650419da
 * commit a436c46f13
 * commit fcf8b72efd
 * commit 079692d424
 * commit 730d837296
2015-08-16 00:38:31 -03:00
Charles Dang
fcf8b72efd Partially revert a436c46f13 and replace [terrain_mask] with [terrain] 2015-08-14 08:41:04 +11:00