# Makefile.am for texinfo/tta/tests.
# Copyright 2012-2026 Free Software Foundation, Inc.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# autogenerated list of scripts that only run one test, and lists of 
# list-of-tests files specifying the tests to run, by category of test.
include $(srcdir)/Makefile.onetst

# should be kept in sync with autogen.sh call
$(srcdir)/Makefile.onetst: \
  ../maintain/regenerate_cmd_tests.sh $(test_driving_files_generated_list)
	cd $(srcdir) \
	&& $(SHELL) ../maintain/regenerate_cmd_tests.sh Makefile.onetst . \
	  -base '$(base_tests_dirs)' \
	  -tex_html '$(tex_html_tests_dirs)' \
	  -other '$(other_tests_dirs)'

base_tests_dirs = formatting encoded nested_formats customization coverage layout
tex_html_tests_dirs = tex_html
other_tests_dirs = other info_tex

DIST_SUBDIRS = many_input_files $(base_tests_dirs) $(tex_html_tests_dirs) $(other_tests_dirs)
SUBDIRS = . many_input_files

parser_tests_environment = srcdir="$(srcdir)"; export srcdir;

copy-tests:
	$(parser_tests_environment) $(srcdir)/parser_tests.sh -copy $(base_tests_dirs)
	cd many_input_files && $(MAKE) copy-tests

copy-tex-html:
	$(parser_tests_environment) $(srcdir)/parser_tests.sh -copy $(tex_html_tests_dirs)
	cd many_input_files && $(MAKE) copy-tex-html

copy-other-tests:
	$(parser_tests_environment) $(srcdir)/parser_tests.sh -copy $(other_tests_dirs)

clean-tests:
	$(parser_tests_environment) $(srcdir)/parser_tests.sh -clean $(base_tests_dirs) $(tex_html_tests_dirs) $(other_tests_dirs)

TESTS = $(one_test_files_generated_list)

AM_TESTS_ENVIRONMENT = srcdir="$(srcdir)"; export srcdir; t2a_srcdir="$(top_srcdir)"; export t2a_srcdir; t2a_builddir="$(top_builddir)"; export t2a_builddir;

all-checks all-check: all
	$(MAKE) $(AM_MAKEFLAGS) check TEX_HTML_TESTS=yes OTHER_TESTS=yes

# need to set SUBDIRS= otherwise the recursion in many_input_files
# tries to run the tests in TESTS which do not exist in many_input_files.
# The recursion is explicitly done after.
tex-html-checks tex-html-check: all
	$(MAKE) $(AM_MAKEFLAGS) check TEX_HTML_TESTS=yes TESTS='$(type_tex_html_one_test_files_generated_list)' SUBDIRS=
	cd many_input_files && $(MAKE) $(AM_MAKEFLAGS) check TEX_HTML_TESTS=yes

# type_other_one_test_files_generated_list is automatically defined in
# Makefile.onetst
other-checks: all
	$(MAKE) $(AM_MAKEFLAGS) check OTHER_TESTS=yes TESTS='$(type_other_one_test_files_generated_list)' SUBDIRS=

check_DATA = input_file_names_recoded_stamp.txt

input_file_names_recoded_stamp.txt: $(srcdir)/input/included_latin1.texi
	mkdir -p built_input ; if $(PERL) $(srcdir)/../maintain/copy_change_file_name_encoding.pl $(srcdir)/input/included_latin1.texi built_input ; then echo 'OK' > $@ ; else echo 'FAILED' > $@ ; fi

distclean-local:
	rm -rf input_file_names_recoded_stamp.txt non_ascii_extracted_stamp.txt built_input

# Files with non-ASCII file names
na=input/non_ascii
non_ascii_input = \
 $(na)/osé_utf8.texi \
 $(na)/osé_utf8_no_setfilename.texi \
 $(na)/çss.css \
 $(na)/cêss.css \
 $(na)/an_ïmage.png \
 $(na)/txt_çimage.txt \
 $(na)/included_akçentêd.texi \
 $(na)/tex_encodé_utf8.texi \
 $(na)/dir_înclùde/file_image.png \
 $(na)/dir_înclùde/included_file.texi

# tar archive should contain all files in a "non_ascii" directory.  This
# rule only works when run from the git repository, not from a tarball.
# Note that this target does not depend on $(non_ascii_input), so
# non_ascii.tar needs to be regenerated manually in case of any updates.
# It is also regenerated by autogen.sh at top level.
$(srcdir)/input/non_ascii.tar:
	$(SHELL) $(srcdir)/../maintain/regenerate_non_ascii_tar_file.sh $(srcdir)/input

check_DATA += non_ascii_extracted_stamp.txt

if ! HOST_IS_WINDOWS
non_ascii_extracted_stamp.txt: input/non_ascii.tar
	rm -rf built_input/non_ascii && mkdir -p built_input/non_ascii && \
	cd built_input && \
	tar xmf "$(abs_srcdir)/input/non_ascii.tar" && \
	echo OK > ../non_ascii_extracted_stamp.txt
else
non_ascii_extracted_stamp.txt:
	echo FAIL > non_ascii_extracted_stamp.txt
endif
# We skip some tests if we don't extract the non-ASCII input files.
# This avoid issues with the creation of such files on MS-Windows.
# This also avoids use by tests of non-ASCII characters on command lines
# using UTF-8 to encode those characters in the source files.
# Shell on Windows may consider those characters to be
# encoded in the current codeset, passing them incorrectly to
# the programs, and even if the shell passed them unchanged, native
# Windows perl in most cases cannot cope with non-ASCII arguments
# encoded in a different encoding than the current user codepage.


# tar m discards file modification dates from the archive.

EXTRA_DIST = run_parser_all.sh parser_tests.sh \
 README \
 escape_file_names.pl \
 $(one_test_files_generated_list) coverage_macro.texi \
 input/included_latin1.texi input/non_ascii.tar
