Reindent unit tests and unit test macros
This doesn't cover all of the unit tests, it's the result of running wmlindent on all of them and then reviewing whether the changes were bugs in the test, or whether they're bugs in wmlindent. Note: there are two cve_2018_1999023 tests. The other one needs to be treated as a binary file, but the one changed here is plain text that loads its attack from a separate file. The change in start_position_generic.cfg doesn't seem good, but it's not particularly bad and it's what wmlindent currently does.
This commit is contained in:
parent
91d4543a3b
commit
5f1d46513a
13 changed files with 208 additions and 215 deletions
|
@ -48,21 +48,21 @@
|
|||
#enddef
|
||||
|
||||
#define ASSERT_SHROUDED FILTER STATE
|
||||
[lua]
|
||||
code=<<
|
||||
local locs = wesnoth.map.find(wml.get_child(..., 'filter'))
|
||||
local state = (...).state
|
||||
for _,loc in ipairs(locs) do
|
||||
local x, y = loc[1], loc[2]
|
||||
unit_test.assert_equal(wesnoth.sides.is_shrouded(1, loc), state, string.format('shroud check at (%d,%d)', loc[1], loc[2]))
|
||||
end
|
||||
>>
|
||||
[args]
|
||||
[filter]
|
||||
include_borders=yes
|
||||
{FILTER}
|
||||
[/filter]
|
||||
state={STATE}
|
||||
[/args]
|
||||
[/lua]
|
||||
[lua]
|
||||
code=<<
|
||||
local locs = wesnoth.map.find(wml.get_child(..., 'filter'))
|
||||
local state = (...).state
|
||||
for _,loc in ipairs(locs) do
|
||||
local x, y = loc[1], loc[2]
|
||||
unit_test.assert_equal(wesnoth.sides.is_shrouded(1, loc), state, string.format('shroud check at (%d,%d)', loc[1], loc[2]))
|
||||
end
|
||||
>>
|
||||
[args]
|
||||
[filter]
|
||||
include_borders=yes
|
||||
{FILTER}
|
||||
[/filter]
|
||||
state={STATE}
|
||||
[/args]
|
||||
[/lua]
|
||||
#enddef
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#arg TURNS
|
||||
-1#endarg
|
||||
|
||||
# side 1
|
||||
# side 1
|
||||
#arg SIDE1_CONTROLLER
|
||||
human#endarg
|
||||
|
||||
|
@ -28,7 +28,7 @@ human#endarg
|
|||
#arg SIDE1_LEADER
|
||||
Elvish Archer#endarg
|
||||
|
||||
# side 2
|
||||
# side 2
|
||||
#arg SIDE2_CONTROLLER
|
||||
human#endarg
|
||||
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
#####
|
||||
# API(s) being tested: N/A
|
||||
##
|
||||
# Actions:
|
||||
# Attempt to load bytecode.bin to bypass the lua sandbox.
|
||||
##
|
||||
# Expected end state:
|
||||
# The insecure execution of the bytecode is prevented.
|
||||
#####
|
||||
{GENERIC_UNIT_TEST "cve_2018_1999023" (
|
||||
[lua]
|
||||
code = << pcall(function() wesnoth.dofile("test/scenarios/cve_tests/bytecode.bin") end) >>
|
||||
[/lua]
|
||||
[lua]
|
||||
code = << pcall(function() wesnoth.require("test/scenarios/cve_tests/bytecode.bin") end) >>
|
||||
[/lua]
|
||||
[lua]
|
||||
code = <<
|
||||
local function f1()
|
||||
bytecode_executed = true
|
||||
end
|
||||
local f2, err = load(string.dump(f1))
|
||||
if f2 then
|
||||
f2()
|
||||
end
|
||||
pcall(function()
|
||||
f2, err = loadstring(string.dump(f1))
|
||||
if f2 then
|
||||
f2()
|
||||
end
|
||||
end)
|
||||
>>
|
||||
[/lua]
|
||||
[event]
|
||||
name = prestart
|
||||
[lua]
|
||||
code = <<
|
||||
wml.variables["execution_prevented"] = not rawget(_G, "bytecode_executed")
|
||||
>>
|
||||
[/lua]
|
||||
{ASSERT ({VARIABLE_CONDITIONAL execution_prevented equals yes})}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
#####
|
||||
# API(s) being tested: N/A
|
||||
##
|
||||
# Actions:
|
||||
# Attempt to load bytecode.bin to bypass the lua sandbox.
|
||||
##
|
||||
# Expected end state:
|
||||
# The insecure execution of the bytecode is prevented.
|
||||
#####
|
||||
{GENERIC_UNIT_TEST "cve_2018_1999023" (
|
||||
[lua]
|
||||
code = << pcall(function() wesnoth.dofile("test/scenarios/cve_tests/bytecode.bin") end) >>
|
||||
[/lua]
|
||||
[lua]
|
||||
code = << pcall(function() wesnoth.require("test/scenarios/cve_tests/bytecode.bin") end) >>
|
||||
[/lua]
|
||||
[lua]
|
||||
code = <<
|
||||
local function f1()
|
||||
bytecode_executed = true
|
||||
end
|
||||
local f2, err = load(string.dump(f1))
|
||||
if f2 then
|
||||
f2()
|
||||
end
|
||||
pcall(function()
|
||||
f2, err = loadstring(string.dump(f1))
|
||||
if f2 then
|
||||
f2()
|
||||
end
|
||||
end)
|
||||
>>
|
||||
[/lua]
|
||||
[event]
|
||||
name = prestart
|
||||
[lua]
|
||||
code = <<
|
||||
wml.variables["execution_prevented"] = not rawget(_G, "bytecode_executed")
|
||||
>>
|
||||
[/lua]
|
||||
{ASSERT ({VARIABLE_CONDITIONAL execution_prevented equals yes})}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#textdomain wesnoth-test
|
||||
|
||||
#define ASSERT_SHROUD_DATA DATA
|
||||
[lua]
|
||||
code=<<
|
||||
local data = (...).data
|
||||
unit_test.assert_equal(data, wesnoth.sides[1].shroud_data, 'data equal')
|
||||
>>
|
||||
[args]
|
||||
data={DATA}
|
||||
[/args]
|
||||
[/lua]
|
||||
[lua]
|
||||
code=<<
|
||||
local data = (...).data
|
||||
unit_test.assert_equal(data, wesnoth.sides[1].shroud_data, 'data equal')
|
||||
>>
|
||||
[args]
|
||||
data={DATA}
|
||||
[/args]
|
||||
[/lua]
|
||||
#enddef
|
||||
|
||||
#####
|
||||
|
@ -173,7 +173,7 @@
|
|||
{ASSERT_SHROUDED x,y=9,0-6 true}
|
||||
{ASSERT_SHROUDED x,y=10,0-5 true}
|
||||
{ASSERT_SHROUDED x,y=11,1-5 true}
|
||||
|
||||
|
||||
{ASSERT_SHROUDED x,y=12,2-4 false}
|
||||
{ASSERT_SHROUDED x,y=13,3-5 false}
|
||||
{ASSERT_SHROUDED x,y=14,2-4 false}
|
||||
|
@ -263,7 +263,7 @@
|
|||
{ASSERT_SHROUDED x,y=9,0-6 false}
|
||||
{ASSERT_SHROUDED x,y=10,0-5 false}
|
||||
{ASSERT_SHROUDED x,y=11,1-5 false}
|
||||
|
||||
|
||||
{ASSERT_SHROUDED x,y=12,2-4 false}
|
||||
{ASSERT_SHROUDED x,y=13,3-5 false}
|
||||
{ASSERT_SHROUDED x,y=14,2-4 false}
|
||||
|
@ -311,4 +311,3 @@
|
|||
)}
|
||||
|
||||
#undef ASSERT_SHROUD_DATA
|
||||
|
||||
|
|
|
@ -13,27 +13,27 @@
|
|||
{GENERIC_UNIT_TEST "test_scoped_vars" (
|
||||
[event]
|
||||
name = prestart
|
||||
{VARIABLE test_var 1}
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals 1}}
|
||||
{VARIABLE test_var 1}
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals 1}}
|
||||
[lua]
|
||||
code = <<
|
||||
local wml_utils = wesnoth.require "wml-utils"
|
||||
local var <close> = wml_utils.scoped_var("test_var")
|
||||
-- This runs the contents of [args] as WML actions
|
||||
wml_utils.handle_event_commands(...)
|
||||
>>
|
||||
[args]
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals ""}}
|
||||
{VARIABLE test_var 5}
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals 5}}
|
||||
[/args]
|
||||
local wml_utils = wesnoth.require "wml-utils"
|
||||
local var <close> = wml_utils.scoped_var("test_var")
|
||||
-- This runs the contents of [args] as WML actions
|
||||
wml_utils.handle_event_commands(...)
|
||||
>>
|
||||
[args]
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals ""}}
|
||||
{VARIABLE test_var 5}
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals 5}}
|
||||
[/args]
|
||||
[/lua]
|
||||
|
||||
#[inspect][/inspect]
|
||||
#[inspect][/inspect]
|
||||
{ASSERT {VARIABLE_CONDITIONAL test_var equals 1}}
|
||||
{SUCCEED}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{GENERIC_UNIT_TEST "test_force_chance_to_hit_macro" (
|
||||
{FORCE_CHANCE_TO_HIT (id=bob) (id=alice) 0 ()}
|
||||
{FORCE_CHANCE_TO_HIT (id=alice) (id=bob) 0 ()}
|
||||
|
||||
|
||||
[event]
|
||||
name=start
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
turns = -1
|
||||
id = test_relative_dir
|
||||
is_unit_test=no
|
||||
|
||||
|
||||
{DAWN}
|
||||
|
||||
[side]
|
||||
|
@ -56,7 +56,7 @@
|
|||
id=bob
|
||||
[/leader]
|
||||
[/side]
|
||||
|
||||
|
||||
[event]
|
||||
name=start
|
||||
[modify_unit]
|
||||
|
|
|
@ -96,4 +96,3 @@ end
|
|||
#undef SPLIT
|
||||
#undef AI_ASPECT_UNIT_TEST
|
||||
#undef AI_UNIT_TEST
|
||||
|
||||
|
|
|
@ -76,4 +76,3 @@
|
|||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
|
|
|
@ -10,37 +10,36 @@
|
|||
# One of the two special traits excludes another trait to be already had by Bob.
|
||||
# Bob should either not have the trait or have only the excluded one.
|
||||
#####
|
||||
|
||||
{GENERIC_UNIT_TEST "trait_exclusion_test" (
|
||||
[event]
|
||||
name=start
|
||||
{UNIT 1 (Test Unit Exclude) 1 1 (id=excluder1)}
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 1
|
||||
[store_unit]
|
||||
[filter]
|
||||
side=1
|
||||
id=excluder1
|
||||
[/filter]
|
||||
variable=excluded
|
||||
kill=no
|
||||
[/store_unit]
|
||||
[if]
|
||||
# Check if the first randomly generated trait is the excluded one, then the
|
||||
# next trait slot should be empty
|
||||
{VARIABLE_CONDITIONAL excluded.modifications.trait[0].id equals "test_excluded"}
|
||||
[then]
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[1].id equals $nil})}
|
||||
[/then]
|
||||
[else]
|
||||
# Otherwise if it is "test_exclude" then the next slot should be empty as well
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[0].id equals "test_exclude"})}
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[1].id equals $nil})}
|
||||
[/else]
|
||||
[/if]
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{UNIT 1 (Test Unit Exclude) 1 1 (id=excluder1)}
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 1
|
||||
[store_unit]
|
||||
[filter]
|
||||
side=1
|
||||
id=excluder1
|
||||
[/filter]
|
||||
variable=excluded
|
||||
kill=no
|
||||
[/store_unit]
|
||||
[if]
|
||||
# Check if the first randomly generated trait is the excluded one, then the
|
||||
# next trait slot should be empty
|
||||
{VARIABLE_CONDITIONAL excluded.modifications.trait[0].id equals "test_excluded"}
|
||||
[then]
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[1].id equals $nil})}
|
||||
[/then]
|
||||
[else]
|
||||
# Otherwise if it is "test_exclude" then the next slot should be empty as well
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[0].id equals "test_exclude"})}
|
||||
{ASSERT ({VARIABLE_CONDITIONAL excluded.modifications.trait[1].id equals $nil})}
|
||||
[/else]
|
||||
[/if]
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
#####
|
||||
|
@ -53,25 +52,23 @@
|
|||
# One of the two special traits needs another trait to be already had by Bob.
|
||||
# Bob only have the trait if it also has the one it requires one.
|
||||
#####
|
||||
|
||||
|
||||
{GENERIC_UNIT_TEST "trait_requirement_test" (
|
||||
[event]
|
||||
name=start
|
||||
{UNIT 1 (Test Unit Require) 1 1 (id=requirer1)}
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 1
|
||||
[store_unit]
|
||||
[filter]
|
||||
side=1
|
||||
id=requirer1
|
||||
[/filter]
|
||||
variable=required
|
||||
kill=no
|
||||
[/store_unit]
|
||||
# Check if the second randomly generated trait is the one requiring the other one
|
||||
{ASSERT ({VARIABLE_CONDITIONAL required.modifications.trait[1].id equals "test_require"})}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{UNIT 1 (Test Unit Require) 1 1 (id=requirer1)}
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 1
|
||||
[store_unit]
|
||||
[filter]
|
||||
side=1
|
||||
id=requirer1
|
||||
[/filter]
|
||||
variable=required
|
||||
kill=no
|
||||
[/store_unit]
|
||||
# Check if the second randomly generated trait is the one requiring the other one
|
||||
{ASSERT ({VARIABLE_CONDITIONAL required.modifications.trait[1].id equals "test_require"})}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
|
|
@ -1,36 +1,35 @@
|
|||
#textdomain wesnoth-test
|
||||
|
||||
[units]
|
||||
{test/units/}
|
||||
|
||||
[race]
|
||||
id=test
|
||||
name= _ "test"
|
||||
female_name= _ "test"
|
||||
plural_name= _ "tests"
|
||||
description= _ "test race"
|
||||
num_traits=2
|
||||
undead_variation=wolf
|
||||
{ORCISH_NAMES}
|
||||
[/race]
|
||||
|
||||
[movetype]
|
||||
name=fly
|
||||
flying=yes
|
||||
[movement_costs]
|
||||
{FLY_MOVE}
|
||||
cave=3
|
||||
fungus=3
|
||||
[/movement_costs]
|
||||
[defense]
|
||||
{FLY_DEFENSE 50}
|
||||
cave=80
|
||||
fungus=-70
|
||||
[/defense]
|
||||
{FLY_RESISTANCE}
|
||||
[special_note]
|
||||
note={INTERNAL:SPECIAL_NOTES_DEFENSE_CAP}
|
||||
[/special_note]
|
||||
[/movetype]
|
||||
|
||||
{test/units/}
|
||||
|
||||
[race]
|
||||
id=test
|
||||
name= _ "test"
|
||||
female_name= _ "test"
|
||||
plural_name= _ "tests"
|
||||
description= _ "test race"
|
||||
num_traits=2
|
||||
undead_variation=wolf
|
||||
{ORCISH_NAMES}
|
||||
[/race]
|
||||
|
||||
[movetype]
|
||||
name=fly
|
||||
flying=yes
|
||||
[movement_costs]
|
||||
{FLY_MOVE}
|
||||
cave=3
|
||||
fungus=3
|
||||
[/movement_costs]
|
||||
[defense]
|
||||
{FLY_DEFENSE 50}
|
||||
cave=80
|
||||
fungus=-70
|
||||
[/defense]
|
||||
{FLY_RESISTANCE}
|
||||
[special_note]
|
||||
note={INTERNAL:SPECIAL_NOTES_DEFENSE_CAP}
|
||||
[/special_note]
|
||||
[/movetype]
|
||||
[/units]
|
||||
|
|
|
@ -32,24 +32,24 @@
|
|||
# This unit is used for testing the exclude traits functionality.
|
||||
|
||||
[unit_type]
|
||||
id=Test Unit Exclude
|
||||
name=_ "dummy_unit^Test Unit Exclude"
|
||||
race=test
|
||||
image="misc/blank-hex.png"
|
||||
ignore_race_traits=yes
|
||||
{TRAIT_TEST_EXCLUDE}
|
||||
{TRAIT_TEST_EXCLUDED}
|
||||
hitpoints=1
|
||||
movement_type=fly
|
||||
movement=1
|
||||
experience=1
|
||||
level=1
|
||||
alignment=neutral
|
||||
advances_to=null
|
||||
cost=1
|
||||
usage=scout
|
||||
hide_help=yes
|
||||
do_not_list=yes
|
||||
id=Test Unit Exclude
|
||||
name=_ "dummy_unit^Test Unit Exclude"
|
||||
race=test
|
||||
image="misc/blank-hex.png"
|
||||
ignore_race_traits=yes
|
||||
{TRAIT_TEST_EXCLUDE}
|
||||
{TRAIT_TEST_EXCLUDED}
|
||||
hitpoints=1
|
||||
movement_type=fly
|
||||
movement=1
|
||||
experience=1
|
||||
level=1
|
||||
alignment=neutral
|
||||
advances_to=null
|
||||
cost=1
|
||||
usage=scout
|
||||
hide_help=yes
|
||||
do_not_list=yes
|
||||
[/unit_type]
|
||||
|
||||
#undef TRAIT_TEST_EXCLUDE
|
||||
|
|
|
@ -32,24 +32,24 @@
|
|||
# This unit is used for testing the require traits functionality.
|
||||
|
||||
[unit_type]
|
||||
id=Test Unit Require
|
||||
name=_ "dummy_unit^Test Unit Require"
|
||||
race=test
|
||||
image="misc/blank-hex.png"
|
||||
ignore_race_traits=yes
|
||||
{TRAIT_TEST_REQUIRE}
|
||||
{TRAIT_TEST_REQUIRED}
|
||||
hitpoints=1
|
||||
movement_type=fly
|
||||
movement=1
|
||||
experience=1
|
||||
level=1
|
||||
alignment=neutral
|
||||
advances_to=null
|
||||
cost=1
|
||||
usage=scout
|
||||
hide_help=yes
|
||||
do_not_list=yes
|
||||
id=Test Unit Require
|
||||
name=_ "dummy_unit^Test Unit Require"
|
||||
race=test
|
||||
image="misc/blank-hex.png"
|
||||
ignore_race_traits=yes
|
||||
{TRAIT_TEST_REQUIRE}
|
||||
{TRAIT_TEST_REQUIRED}
|
||||
hitpoints=1
|
||||
movement_type=fly
|
||||
movement=1
|
||||
experience=1
|
||||
level=1
|
||||
alignment=neutral
|
||||
advances_to=null
|
||||
cost=1
|
||||
usage=scout
|
||||
hide_help=yes
|
||||
do_not_list=yes
|
||||
[/unit_type]
|
||||
|
||||
#undef TRAIT_TEST_REQUIRE
|
||||
|
|
Loading…
Add table
Reference in a new issue