Home | History | Annotate | Line # | Download | only in unit-tests
opt-file.mk revision 1.8
      1  1.8  rillig # $NetBSD: opt-file.mk,v 1.8 2020/12/22 08:05:08 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Tests for the -f command line option.
      4  1.1  rillig 
      5  1.1  rillig # TODO: Implementation
      6  1.1  rillig 
      7  1.4  rillig all: .PHONY
      8  1.4  rillig all: file-ending-in-backslash
      9  1.8  rillig all: file-ending-in-backslash-mmap
     10  1.4  rillig all: file-containing-null-byte
     11  1.3  rillig 
     12  1.3  rillig # Passing '-' as the filename reads from stdin.  This is unusual but possible.
     13  1.3  rillig #
     14  1.3  rillig # In the unlikely case where a file ends in a backslash instead of a newline,
     15  1.3  rillig # that backslash is trimmed.  See ParseGetLine.
     16  1.7  rillig #
     17  1.7  rillig # make-2014.01.01.00.00.00 invoked undefined behavior, reading text from
     18  1.7  rillig # outside of the file buffer.
     19  1.7  rillig #
     20  1.7  rillig #	printf '%s' 'VAR=value\' \
     21  1.7  rillig #	| MALLOC_OPTIONS=JA make-2014.01.01.00.00.00 -r -f - -V VAR -dA 2>&1 \
     22  1.7  rillig #	| less
     23  1.7  rillig #
     24  1.7  rillig # The debug output shows how make happily uses freshly allocated memory (the
     25  1.7  rillig # <A5>) and already freed memory ('Z').
     26  1.7  rillig #
     27  1.7  rillig #	ParseReadLine (1): 'VAR=value\<A5><A5><A5><A5><A5><A5>'
     28  1.7  rillig #	Global:VAR = value\<A5><A5><A5><A5><A5><A5>value\<A5><A5><A5><A5><A5><A5>
     29  1.7  rillig #	ParseReadLine (2): 'alue\<A5><A5><A5><A5><A5><A5>'
     30  1.7  rillig #	ParseDoDependency(alue\<A5><A5><A5><A5><A5><A5>)
     31  1.7  rillig #	make-2014.01.01.00.00.00: "(stdin)" line 2: Need an operator
     32  1.7  rillig #	ParseReadLine (3): '<A5><A5><A5>ZZZZZZZZZZZZZZZZ'
     33  1.7  rillig #	ParseDoDependency(<A5><A5><A5>ZZZZZZZZZZZZZZZZ)
     34  1.7  rillig #
     35  1.3  rillig file-ending-in-backslash: .PHONY
     36  1.4  rillig 	@printf '%s' 'VAR=value\' \
     37  1.7  rillig 	| ${MAKE} -r -f - -V VAR
     38  1.4  rillig 
     39  1.8  rillig # Between parse.c 1.170 from 2010-12-25 and parse.c 1.511 from 2020-12-22,
     40  1.8  rillig # there was an out-of-bounds write in ParseGetLine, where line_end pointed at
     41  1.8  rillig # the end of the allocated buffer, in the special case where loadedfile_mmap
     42  1.8  rillig # had not added the final newline character.
     43  1.8  rillig file-ending-in-backslash-mmap: .PHONY
     44  1.8  rillig 	@printf '%s' 'VAR=value\' > opt-file-backslash
     45  1.8  rillig 	@${MAKE} -r -f opt-file-backslash -V VAR
     46  1.8  rillig 
     47  1.4  rillig # If a file contains null bytes, the rest of the line is skipped, and parsing
     48  1.5  rillig # continues in the next line.  Throughout the history of make, the behavior
     49  1.5  rillig # has changed several times, sometimes knowingly, sometimes by accident.
     50  1.5  rillig #
     51  1.5  rillig #	echo 'VAR=value' | tr 'l' '\0' > zero-byte.in
     52  1.5  rillig #	printf '%s\n' 'all:' ': VAR=${VAR:Q}' >> zero-byte.in
     53  1.5  rillig #
     54  1.5  rillig #	for year in $(seq 2003 2020); do
     55  1.5  rillig #	  echo $year:
     56  1.5  rillig #	  make-$year.01.01.00.00.00 -r -f zero-byte.in
     57  1.5  rillig #	  echo "exit status $?"
     58  1.5  rillig #	  echo
     59  1.5  rillig #	done 2>&1 \
     60  1.5  rillig #	| sed "s,$PWD/,.,"
     61  1.5  rillig #
     62  1.5  rillig # This program generated the following output:
     63  1.5  rillig #
     64  1.5  rillig #	2003 to 2007:
     65  1.5  rillig #	exit status 0
     66  1.5  rillig #
     67  1.5  rillig #	2008 to 2010:
     68  1.5  rillig #	make: "zero-byte.in" line 1: Zero byte read from file
     69  1.5  rillig #	make: Fatal errors encountered -- cannot continue
     70  1.5  rillig #
     71  1.5  rillig #	make: stopped in .
     72  1.5  rillig #	exit status 1
     73  1.5  rillig #
     74  1.5  rillig #	2011 to 2013:
     75  1.5  rillig #	make: no target to make.
     76  1.5  rillig #
     77  1.5  rillig #	make: stopped in .
     78  1.5  rillig #	exit status 2
     79  1.5  rillig #
     80  1.6  rillig #	2014 to 2020-12-06:
     81  1.5  rillig #	make: "zero-byte.in" line 1: warning: Zero byte read from file, skipping rest of line.
     82  1.5  rillig #	exit status 0
     83  1.4  rillig #
     84  1.6  rillig #	Since 2020-12-07:
     85  1.6  rillig #	make: "zero-byte.in" line 1: Zero byte read from file
     86  1.6  rillig #	make: Fatal errors encountered -- cannot continue
     87  1.6  rillig #	make: stopped in .
     88  1.6  rillig #	exit status 1
     89  1.4  rillig file-containing-null-byte: .PHONY
     90  1.4  rillig 	@printf '%s\n' 'VAR=value' 'VAR2=VALUE2' \
     91  1.4  rillig 	| tr 'l' '\0' \
     92  1.7  rillig 	| ${MAKE} -r -f - -V VAR -V VAR2
     93  1.3  rillig 
     94  1.1  rillig all:
     95  1.6  rillig 	: Making ${.TARGET}
     96