Home | History | Annotate | Line # | Download | only in unit-tests
directive-include.mk revision 1.10
      1 # $NetBSD: directive-include.mk,v 1.10 2022/01/07 08:20:00 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 .include "nonexistent.mk"
     26 .include "/dev/null"		# size 0
     27 # including a directory technically succeeds, but shouldn't.
     28 #.include "."			# directory
     29 
     30 # As of 2020-11-21, anything after the delimiter '"' is ignored.
     31 .include "/dev/null" and ignore anything in the rest of the line.
     32 
     33 # The filename to be included can contain expressions.
     34 DEV=	null
     35 .include "/dev/${DEV}"
     36 
     37 # Expressions in double quotes or angle quotes are first parsed naively, to
     38 # find the closing '"'.  In a second step, the expressions are expanded.  This
     39 # means that the expressions cannot include the characters '"' or '>'.  This
     40 # restriction is not practically relevant since the expressions inside
     41 # '.include' directives are typically kept as simple as possible.
     42 #
     43 # If the whole line were expanded before parsing, the filename to be included
     44 # would be empty, and the closing '"' would be in the trailing part of the
     45 # line, which is ignored as of 2021-12-03.
     46 DQUOT=	"
     47 .include "${DQUOT}"
     48 
     49 # When the expression in a filename cannot be evaluated, the failing
     50 # expression is skipped and the file is included nevertheless.
     51 # FIXME: Add proper error handling, no file must be included here.
     52 .include "nonexistent${:U123:Z}.mk"
     53 
     54 # The traditional include directive is seldom used.
     55 include /dev/null		# comment
     56 # expect+1: Cannot open /nonexistent
     57 include /nonexistent		# comment
     58 sinclude /nonexistent		# comment
     59 include ${:U/dev/null}		# comment
     60 include /dev/null /dev/null
     61 # expect+1: Invalid line type
     62 include
     63 
     64 # XXX: trailing whitespace in diagnostic, missing quotes around filename
     65 ### expect+1: Could not find
     66 # The following include directive behaves differently, depending on whether
     67 # the current file has a slash or is a relative filename.  In the first case,
     68 # make opens the directory of the current file and tries to read from it,
     69 # resulting in the error message """ line 1: Zero byte read from file".
     70 # In the second case, the error message is "Could not find ", without quotes
     71 # or any other indicator for the empty filename at the end of the line.
     72 #include ${:U}
     73 
     74 
     75 # Since parse.c 1.612 from 2022-01-01 and before parse.c 1.620 from
     76 # 2022-01-07, including an empty regular file called bmake_malloc(0), which
     77 # may return a null pointer.  On OpenBSD, this led to a segmentation fault in
     78 # Buf_InitSize, which assumes that bmake_malloc never returns NULL, just like
     79 # all other places in the code.
     80 _!=		> directive-include-empty
     81 .include "${.CURDIR}/directive-include-empty"
     82 _!=		rm directive-include-empty
     83 
     84 
     85 all:
     86