Blame agen5/test/define.test

Packit Service 96b5d3
#! /bin/sh
Packit Service 96b5d3
#  -*- Mode: Shell-script -*-
Packit Service 96b5d3
# define.test --- test evalstack functionality
Packit Service 96b5d3
#
Packit Service 96b5d3
# Author:            Bruce Korb <bkorb@gnu.org>
Packit Service 96b5d3
##
Packit Service 96b5d3
## This file is part of AutoGen.
Packit Service 96b5d3
## AutoGen Copyright (C) 1992-2016 by Bruce Korb - all rights reserved
Packit Service 96b5d3
##
Packit Service 96b5d3
## AutoGen is free software: you can redistribute it and/or modify it
Packit Service 96b5d3
## under the terms of the GNU General Public License as published by the
Packit Service 96b5d3
## Free Software Foundation, either version 3 of the License, or
Packit Service 96b5d3
## (at your option) any later version.
Packit Service 96b5d3
##
Packit Service 96b5d3
## AutoGen is distributed in the hope that it will be useful, but
Packit Service 96b5d3
## WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 96b5d3
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 96b5d3
## See the GNU General Public License for more details.
Packit Service 96b5d3
##
Packit Service 96b5d3
## You should have received a copy of the GNU General Public License along
Packit Service 96b5d3
## with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 96b5d3
##
Packit Service 96b5d3
#
Packit Service 96b5d3
# ----------------------------------------------------------------------
Packit Service 96b5d3
Packit Service 96b5d3
. ./defs
Packit Service 96b5d3
Packit Service 96b5d3
# # # # # # # TEMPLATE LIBRARY FILE # # # # # #
Packit Service 96b5d3
Packit Service 96b5d3
echo creating $testname.tlib
Packit Service 96b5d3
cat > $testname.tlib <<'_EOF_'
Packit Service 96b5d3
[+ AutoGen5 Template Library +]
Packit Service 96b5d3
[+
Packit Service 96b5d3
Packit Service 96b5d3
# * * * * * * * * * * * *
Packit Service 96b5d3
Packit Service 96b5d3
      VISUAL SEPARATION
Packit Service 96b5d3
+][+
Packit Service 96b5d3
Packit Service 96b5d3
DEFINE first_macro
Packit Service 96b5d3
+][+(for-index)+] Argument list:
Packit Service 96b5d3
	[+
Packit Service 96b5d3
  FOR arg "\n\t"
Packit Service 96b5d3
    +]arg[ [+(for-index)+] ] = [+ arg +][+
Packit Service 96b5d3
  ENDFOR +][+
Packit Service 96b5d3
ENDDEF +][+
Packit Service 96b5d3
Packit Service 96b5d3
# * * * * * * * * * * * *
Packit Service 96b5d3
Packit Service 96b5d3
      VISUAL SEPARATION
Packit Service 96b5d3
+][+
Packit Service 96b5d3
Packit Service 96b5d3
DEFINE last_macro
Packit Service 96b5d3
  +]This is the last (number [+(for-index)+]) macro.[+
Packit Service 96b5d3
ENDDEF +]
Packit Service 96b5d3
_EOF_
Packit Service 96b5d3
Packit Service 96b5d3
Packit Service 96b5d3
# # # # # # # # # # TEMPLATE FILE # # # # # # # # #
Packit Service 96b5d3
Packit Service 96b5d3
echo creating $testname.tpl
Packit Service 96b5d3
cat > $testname.tpl <<'_EOF_'
Packit Service 96b5d3
[= AutoGen5 Template test =]
Packit Service 96b5d3
[=
Packit Service 96b5d3
Packit Service 96b5d3
DEFINE nest     =][=
Packit Service 96b5d3
  IF (exist? "name") =]
Packit Service 96b5d3
level [=(shell "printf '%u\\n' " (get "level"))
Packit Service 96b5d3
=] iteration [=(for-index)=] Nested Name:  [=name=][=
Packit Service 96b5d3
  ENDIF         =][=
Packit Service 96b5d3
Packit Service 96b5d3
  FOR .nesting  =][=
Packit Service 96b5d3
    nest        =][=
Packit Service 96b5d3
  ENDFOR        =][=
Packit Service 96b5d3
Packit Service 96b5d3
ENDDEF nest     =][=
Packit Service 96b5d3
Packit Service 96b5d3
FOR value
Packit Service 96b5d3
Packit Service 96b5d3
=][=
Packit Service 96b5d3
  IF (or (first-for?) (last-for?)) =][=
Packit Service 96b5d3
    INVOKE (string-append (get "value") "_macro")
Packit Service 96b5d3
       arg = one  arg = "the second arg = the second"
Packit Service 96b5d3
       arg = (shell "LC_ALL=C date +'%A, %D'") arg = 'done.' =][=
Packit Service 96b5d3
  ELSE =]
Packit Service 96b5d3
Packit Service 96b5d3
     non first/last value: [=value=] = [= (for-index) =]
Packit Service 96b5d3
[=ENDIF         =][=
Packit Service 96b5d3
ENDFOR          =]
Packit Service 96b5d3
[=invoke nest   =]
Packit Service 96b5d3
Done.
Packit Service 96b5d3
_EOF_
Packit Service 96b5d3
Packit Service 96b5d3
Packit Service 96b5d3
# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #
Packit Service 96b5d3
Packit Service 96b5d3
echo creating $testname.def
Packit Service 96b5d3
cat > $testname.def <<_EOF_
Packit Service 96b5d3
autogen definitions $testname;
Packit Service 96b5d3
Packit Service 96b5d3
value = first;
Packit Service 96b5d3
value[2] = secondary;
Packit Service 96b5d3
value[4] = tertiary;
Packit Service 96b5d3
value[6] = last;
Packit Service 96b5d3
Packit Service 96b5d3
level = 0;
Packit Service 96b5d3
nesting[1] = {
Packit Service 96b5d3
  level = 1;
Packit Service 96b5d3
  name = primary;
Packit Service 96b5d3
  nesting[1] = {
Packit Service 96b5d3
    level = 0x2;
Packit Service 96b5d3
    name = secondary;
Packit Service 96b5d3
  }, {
Packit Service 96b5d3
    level = 0x2;
Packit Service 96b5d3
    /* no name defined - default to primary level */
Packit Service 96b5d3
    nesting[1] = {
Packit Service 96b5d3
      level = 3;
Packit Service 96b5d3
      name = tertiary;
Packit Service 96b5d3
    };
Packit Service 96b5d3
  };
Packit Service 96b5d3
};
Packit Service 96b5d3
_EOF_
Packit Service 96b5d3
Packit Service 96b5d3
# this is the output we should expect to see
Packit Service 96b5d3
cat > $testname.samp <<_EOF_
Packit Service 96b5d3
0 Argument list:
Packit Service 96b5d3
	arg[ 0 ] = one
Packit Service 96b5d3
	arg[ 1 ] = the second arg = the second
Packit Service 96b5d3
	arg[ 2 ] = `LC_ALL=C date +'%A, %D'`
Packit Service 96b5d3
	arg[ 3 ] = done.
Packit Service 96b5d3
Packit Service 96b5d3
     non first/last value: secondary = 2
Packit Service 96b5d3
Packit Service 96b5d3
Packit Service 96b5d3
     non first/last value: tertiary = 4
Packit Service 96b5d3
This is the last (number 6) macro.
Packit Service 96b5d3
Packit Service 96b5d3
level 1 iteration 1 Nested Name:  primary
Packit Service 96b5d3
level 2 iteration 1 Nested Name:  secondary
Packit Service 96b5d3
level 2 iteration 2 Nested Name:  primary
Packit Service 96b5d3
level 3 iteration 1 Nested Name:  tertiary
Packit Service 96b5d3
Done.
Packit Service 96b5d3
_EOF_
Packit Service 96b5d3
Packit Service 96b5d3
run_ag x --lib=$testname.tlib $testname.def || \
Packit Service 96b5d3
  failure "autogen failed"
Packit Service 96b5d3
set -x
Packit Service 96b5d3
cmp -s $testname.samp $testname.test || \
Packit Service 96b5d3
  failure "`diff $testname.samp $testname.test`"
Packit Service 96b5d3
Packit Service 96b5d3
cleanup
Packit Service 96b5d3
Packit Service 96b5d3
## Local Variables:
Packit Service 96b5d3
## mode: shell-script
Packit Service 96b5d3
## indent-tabs-mode: nil
Packit Service 96b5d3
## sh-indentation: 2
Packit Service 96b5d3
## sh-basic-offset: 2
Packit Service 96b5d3
## End:
Packit Service 96b5d3
Packit Service 96b5d3
# end of define.test