summaryrefslogtreecommitdiff
path: root/autoopts/test/library.test
blob: f463e3e2541cc4fc9b817f1a0b0b955e99586bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# library.test     ---  test library options
#
# Time-stamp:        "2013-03-10 07:14:58 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
#
# ----------------------------------------------------------------------

. ./defs

# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #

DEND=\<\<'- _DESC_END_'

cat > ${testname}-libopts.def <<- _EODefs_
	flag = { name = zzyzx-opts;
	  documentation;
	  lib-name = zzyzx;
	  descrip = ${DEND}
		This option introduces the options for the
		zzyzx library
		_DESC_END_;
	};
	flag = {
	  name  = library;
	  value = c;
	  ifdef = LIBOPTS;
	  descrip = "library test";
	  doc   = mumble;
	};
	_EODefs_

cat > ${testname}-lib.def <<- _EODefs_

	AutoGen definitions options;

	prog-name  = ${testname};
	prog-title = lib-${testname};
	config-header = 'config.h';

	library;
	#include ${testname}-libopts.def
	_EODefs_

cat > ${testname}-prog.def <<- _EOF_

	AutoGen definitions options;

	prog-name  = test-lib-prog;
	prog-title = 'Test ${testname} Program';
	config-header = 'config.h';

	flag = {
	  name  = program;
	  value = p;
	  descrip = "${testname} program test";
	  doc   = stumble;
	};

	#include ${testname}-libopts.def
	_EOF_

echo ${AG_L} ${testname}-lib.def
${AG_L} ${testname}-lib.def || \
  failure AutoGen could not process ${testname}-lib.def

echo ${AG_L} ${testname}-prog.def
${AG_L} ${testname}-prog.def || \
  failure AutoGen could not process ${testname}-prog.def

for f in lib prog
do
  ${SED} -e '1,/include <autoopts\/options.h>/d' \
      -e '/endif .* AUTOOPTS_.*_H_GUARD/,$d' \
      -e 's/near line [0-9]*/near line XXX/' \
      ${testname}-${f}.h > ${testname}-${f}.h-res || \
   failure could not sed ${testname}-${f}.h
done

# # # # # # # # # # TEST PROGRAM # # # # # # # # # #

cat > ${testname}-lib.c <<- _EOCode_
	#include <stdlib.h>
	#define LIBOPTS
	#include "${testname}-lib.h"
	void check_library_opt( void );
	void check_library_opt( void ) {
	  if (HAVE_OPT(LIBRARY)) return;
	  exit( EXIT_FAILURE ); }
	_EOCode_
test $? -eq 0 || failure cannot create ${testname}-lib.c

${CC} ${CFLAGS} ${INC} -o ${testname}-lib.o -c ${testname}-lib.c
test $? -eq 0 || failure cannot compile ${testname}-lib.c

cat > ${testname}-main.c <<- _EOCode_
	#include <stdio.h>
	#include <stdlib.h>
	#define LIBOPTS
	#include "${testname}-prog.c"
	extern void check_library_opt( void );
	int main( int argc, char** argv ) {
	  (void)optionProcess( &test_lib_progOptions, argc, argv );
	  check_library_opt();
	  return EXIT_SUCCESS; }
	_EOCode_

${CC} ${CFLAGS} ${INC} -o ${testname} ${testname}-main.c ${testname}-lib.o ${LIB}
test $? -eq 0 || failure cannot compile ${testname}-main.c

./${testname} -c || failure library option not detected

# # # # # # # # # # HELP OUTPUT # # # # # # # # # #

./${testname} -? | clean_help > ${testname}.help-sample

clean_help > ${testname}.help-base <<- _EOHelp_
test-lib-prog - Test library Program
USAGE:  library [ -<flag> ]...
  Flg Arg Option-Name    Description
   -p no  program        library program test

This option introduces the options for the zzyzx library:

  Flg Arg Option-Name    Description
   -c no  library        library test

version, usage and configuration options:

  Flg Arg Option-Name    Description
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager

	_EOHelp_

cmp ${testname}.help-* || \
  failure "help output mismatch:
`diff ${testname}.help-*`"

cleanup

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## End:

# end of library.test