Home | History | Annotate | Line # | Download | only in unit-tests
directive-include.mk revision 1.12
      1 # $NetBSD: directive-include.mk,v 1.12 2023/06/01 20:56:35 rillig Exp $
      2 #
      3 # Tests for the .include directive, which includes another file.
      4 
      5 # TODO: Implementation
      6 
      7 .MAKEFLAGS: -dc
      8 
      9 # All included files are recorded in the variable .MAKE.MAKEFILES.
     10 # In this test, only the basenames of the files are compared since
     11 # the directories can differ.
     12 .include "/dev/null"
     13 .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
     14 .  error
     15 .endif
     16 
     17 # Each file is recorded only once in the variable .MAKE.MAKEFILES.
     18 # Between 2015-11-26 and 2020-10-31, the very last file could be repeated,
     19 # due to an off-by-one bug in ParseTrackInput.
     20 .include "/dev/null"
     21 .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
     22 .  error
     23 .endif
     24 
     25 # expect+1: Could not find nonexistent.mk
     26 .include "nonexistent.mk"
     27 .include "/dev/null"		# size 0
     28 # including a directory technically succeeds, but shouldn't.
     29 #.include "."			# directory
     30 
     31 # As of 2020-11-21, anything after the delimiter '"' is ignored.
     32 .include "/dev/null" and ignore anything in the rest of the line.
     33 
     34 # The filename to be included can contain expressions.
     35 DEV=	null
     36 .include "/dev/${DEV}"
     37 
     38 # Expressions in double quotes or angle quotes are first parsed naively, to
     39 # find the closing '"'.  In a second step, the expressions are expanded.  This
     40 # means that the expressions cannot include the characters '"' or '>'.  This
     41 # restriction is not practically relevant since the expressions inside
     42 # '.include' directives are typically kept as simple as possible.
     43 #
     44 # If the whole line were expanded before parsing, the filename to be included
     45 # would be empty, and the closing '"' would be in the trailing part of the
     46 # line, which is ignored as of 2021-12-03.
     47 DQUOT=	"
     48 # expect+1: Could not find "
     49 .include "${DQUOT}"
     50 
     51 # When the expression in a filename cannot be evaluated, the failing
     52 # expression is skipped and the file is included nevertheless.
     53 # FIXME: Add proper error handling, no file must be included here.
     54 # expect+2: Could not find nonexistent.mk
     55 # expect+1: Unknown modifier "Z"
     56 .include "nonexistent${:U123:Z}.mk"
     57 
     58 # The traditional include directive is seldom used.
     59 include /dev/null		# comment
     60 # expect+1: Cannot open /nonexistent
     61 include /nonexistent		# comment
     62 sinclude /nonexistent		# comment
     63 include ${:U/dev/null}		# comment
     64 include /dev/null /dev/null
     65 # expect+1: Invalid line type
     66 include
     67 
     68 # XXX: trailing whitespace in diagnostic, missing quotes around filename
     69 ### TODO: expect+1: Could not find
     70 # The following include directive behaves differently, depending on whether
     71 # the current file has a slash or is a relative filename.  In the first case,
     72 # make opens the directory of the current file and tries to read from it,
     73 # resulting in the error message """ line 1: Zero byte read from file".
     74 # In the second case, the error message is "Could not find ", without quotes
     75 # or any other indicator for the empty filename at the end of the line.
     76 #include ${:U}
     77 
     78 
     79 # Since parse.c 1.612 from 2022-01-01 and before parse.c 1.620 from
     80 # 2022-01-07, including an empty regular file called bmake_malloc(0), which
     81 # may return a null pointer.  On OpenBSD, this led to a segmentation fault in
     82 # Buf_InitSize, which assumes that bmake_malloc never returns NULL, just like
     83 # all other places in the code.
     84 _!=		> directive-include-empty
     85 .include "${.CURDIR}/directive-include-empty"
     86 _!=		rm directive-include-empty
     87 
     88 
     89 all:
     90