tinymux/testcases/assert_cmd.mux
Stephen Dennis f8503bb740 tests: @dolist/now/break propagation and inline ;| piping (#788)
- assert_cmd.mux TC008: @dolist/now/break stops the loop on an inner
  @break AND aborts the rest of the enclosing list (the breaking
  @dolist lives in its own triggered attribute so the verification
  survives the propagated break).
- dolist_cmd.mux TC003: ;| inside a @dolist/now body carries %|
  between segments, per iteration.
- include_fn.mux TC010: ;| inside an @include body.

smoke.flat regenerated (1115 tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 09:00:41 -06:00

199 lines
5.7 KiB
Text

#
# assert_cmd.mux - Test Cases for @assert and @break commands.
#
# Each case drives a real @dolist over the list "a b c" and accumulates the
# elements that the loop body actually records into tcNNN_result. @break and
# @assert abort the *current* iteration's command list, so a matched element
# is skipped while the queued @dolist continues with the next element:
#
# no break/assert fires -> "a b c" (every element recorded)
# break/assert fires on b -> "a c" (b skipped, loop continues)
#
# The verification compares the trimmed result to that expected string with
# strmatch() (semantic, not an opaque SHA1) and logs the actual result on
# failure. See issue #765 (the previous helpers used a non-existent
# @dolist/inline switch, so the loop body never ran) and #755.
#
@create test_assert_cmd
-
@set test_assert_cmd=INHERIT QUIET
-
#
# Beginning of Test Cases
#
&tr.tc000 test_assert_cmd=
@log smoke=Beginning @assert/@break command test cases.
-
#
# Test Case #1 - @assert true never breaks; every element is recorded.
#
&tr.tc001 test_assert_cmd=
&tc001_result me=;
@dolist a b c=
{@assert/inline 1;&tc001_result me=[get(me/tc001_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc001_result))),a b c)=
{
@log smoke=TC001: assert true records all. Succeeded.
},
{
@log smoke=TC001: assert true records all. Failed (%q0).
}
}
-
#
# Test Case #2 - @break true skips the matched element ('b'); loop continues.
#
&tr.tc002 test_assert_cmd=
&tc002_result me=;
@dolist a b c=
{@break/inline strmatch(##,b);&tc002_result me=[get(me/tc002_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc002_result))),a c)=
{
@log smoke=TC002: break skips matched element. Succeeded.
},
{
@log smoke=TC002: break skips matched element. Failed (%q0).
}
}
-
#
# Test Case #3 - @break false never fires; every element is recorded.
#
&tr.tc003 test_assert_cmd=
&tc003_result me=;
@dolist a b c=
{@break/inline 0;&tc003_result me=[get(me/tc003_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc003_result))),a b c)=
{
@log smoke=TC003: break false records all. Succeeded.
},
{
@log smoke=TC003: break false records all. Failed (%q0).
}
}
-
#
# Test Case #4 - @assert false skips the matched element ('b'); loop continues.
# assert not(strmatch(##,b)) is false on 'b' -> b skipped.
#
&tr.tc004 test_assert_cmd=
&tc004_result me=;
@dolist a b c=
{@assert/inline not(strmatch(##,b));&tc004_result me=[get(me/tc004_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc004_result))),a c)=
{
@log smoke=TC004: assert false skips matched element. Succeeded.
},
{
@log smoke=TC004: assert false skips matched element. Failed (%q0).
}
}
-
#
# Inline (@dolist/now) cases: @break/@assert stop the whole loop, not just
# the current element. break on 'b' -> only 'a' recorded.
#
# Test Case #5 - @break true stops the inline loop ('b' onward dropped).
#
&tr.tc005 test_assert_cmd=
&tc005_result me=;
@dolist/now a b c=
{@break/inline strmatch(##,b);&tc005_result me=[get(me/tc005_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc005_result))),a)=
{
@log smoke=TC005: break stops inline dolist. Succeeded.
},
{
@log smoke=TC005: break stops inline dolist. Failed (%q0).
}
}
-
#
# Test Case #6 - @break false never fires; inline loop records every element.
# (Regression guard: inline iteration must not stop early.)
#
&tr.tc006 test_assert_cmd=
&tc006_result me=;
@dolist/now a b c=
{@break/inline 0;&tc006_result me=[get(me/tc006_result)] ##};
@wait 0.5=
{
@if strmatch(setr(0,trim(get(me/tc006_result))),a b c)=
{
@log smoke=TC006: inline dolist records all. Succeeded.
},
{
@log smoke=TC006: inline dolist records all. Failed (%q0).
}
}
-
#
# Test Case #7 - inline break stops the loop but stays contained: a command
# after the @dolist/now in the same list still runs.
#
&tr.tc007 test_assert_cmd=
&tc007_result me=;
&tc007_after me=;
@dolist/now a b c=
{@break/inline strmatch(##,b);&tc007_result me=[get(me/tc007_result)] ##};
&tc007_after me=DONE;
@wait 0.5=
{
@if and(strmatch(trim(get(me/tc007_result)),a),strmatch(get(me/tc007_after),DONE))=
{
@log smoke=TC007: inline break is contained. Succeeded.
},
{
@log smoke=TC007: inline break is contained. Failed (r=[trim(get(me/tc007_result))] after=[get(me/tc007_after)]).
}
}
-
#
# Test Case #8 - @dolist/now/break: an inner @break stops the loop AND
# propagates to the enclosing command list (#788), so the
# command after the @dolist never runs. The breaking
# @dolist lives in its own triggered attribute because the
# propagated break aborts THAT list -- the verification
# must live outside it.
#
&tc008_body test_assert_cmd=
@dolist/now/break a b c=
{@break/inline strmatch(##,b);&tc008_result me=[get(me/tc008_result)] ##};
&tc008_after me=DONE
-
&tr.tc008 test_assert_cmd=
&tc008_result me=;
&tc008_after me=NOTRUN;
@trig me/tc008_body;
@wait 0.5=
{
@if and(strmatch(trim(get(me/tc008_result)),a),strmatch(get(me/tc008_after),NOTRUN))=
{
@log smoke=TC008: dolist/now/break propagates. Succeeded.;
@trig me/tr.done
},
{
@log smoke=TC008: dolist/now/break propagates. Failed (r=[trim(get(me/tc008_result))] after=[get(me/tc008_after)]).;
@trig me/tr.done
}
}
-
&tr.done test_assert_cmd=
@log smoke=End @assert/@break command test cases.;
@notify smoke
-
drop test_assert_cmd
-
#
# End of Test Cases
#