##
## %CopyrightBegin%
##
## Copyright Ericsson AB 2021-2022. All Rights Reserved.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## %CopyrightEnd%
##

[global ERLPROMPT=[0-9]*>]

# Directory holding input files for feature tests
[global input=input]

[global erlcserver=true]

[macro ok]
    !echo ==$$?==
    ?==0==
    ?SH-PROMPT:
[endmacro]

[macro notok]
    !echo ==$$?==
    ?==[1-9][0-9]*==
    ?SH-PROMPT:
[endmacro]

[macro compile file opts]
    !erlc $opts -o $outdir $input/$file
[endmacro]

[macro erl-compile file opts]
    !compile:file("$input/$file", $opts ++ [report_errors,{outdir,"$outdir"}]).
[endmacro]

# Create a tmp directory and bind outdir
[macro setup]
    [newshell setup]
    !mktemp -d
    ?(/tmp.*)
    [global outdir=$1]
    ?SH-PROMPT:
    # Make sure there is no erl_crash.dump present
    !rm -f erl_crash.dump
    ?SH-PROMPT:
[endmacro]

[macro start-erl args]
    !erl -pa $outdir $args
    ?$ERLPROMPT
[endmacro]

[macro quit-erl]
    !q().
    ?SH-PROMPT:
[endmacro]

# Nifty way to compare that two lists have the same members
# One drawback is that it is not easy to debug, i.e., see the actual
# members.
[macro same-members l1 l2]
    !{L1, L2} = {$l1, $l2}.
    ?$ERLPROMPT
    !maps:from_keys(L1,foo) == maps:from_keys(L2,foo).
    ?true
    ?$ERLPROMPT
    !f(L1).
    ?$ERLPROMPT
    !f(L2).
    ?$ERLPROMPT
[endmacro]

[macro no-dump]
    !ls erl_crash.dump
    ?SH-PROMPT:
    !echo ==$?==
    ?==2==
    ?SH-PROMPT:
[endmacro]
