Home | History | Annotate | Line # | Download | only in lint1
t_usage.sh revision 1.7
      1 # $NetBSD: t_usage.sh,v 1.7 2023/06/24 08:11:12 rillig Exp $
      2 #
      3 # Copyright (c) 2023 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 : "${lint1:=/usr/libexec/lint1}"
     29 
     30 
     31 suppress_messages_head()
     32 {
     33 	:
     34 }
     35 
     36 suppress_messages_body()
     37 {
     38 	printf 'typedef int dummy;\n' > code.c
     39 
     40 	# Message IDs are 0-based.
     41 	atf_check \
     42 	    "$lint1" -X 0 code.c /dev/null
     43 
     44 	# The largest known message.
     45 	atf_check \
     46 	    "$lint1" -X 352 code.c /dev/null
     47 
     48 	# Larger than the largest known message.
     49 	atf_check \
     50 	    -s 'exit:1' \
     51 	    -e "inline:lint1: invalid message ID '353'\n" \
     52 	    "$lint1" -X 353 code.c /dev/null
     53 
     54 	# Whitespace is not allowed before a message ID.
     55 	atf_check \
     56 	    -s 'exit:1' \
     57 	    -e "inline:lint1: invalid message ID ' 1'\n" \
     58 	    "$lint1" -X ' 1' code.c /dev/null
     59 
     60 	# Whitespace is not allowed after a message ID.
     61 	atf_check \
     62 	    -s 'exit:1' \
     63 	    -e "inline:lint1: invalid message ID '1 '\n" \
     64 	    "$lint1" -X '1 ' code.c /dev/null
     65 
     66 	# Multiple message IDs can be comma-separated.
     67 	atf_check \
     68 	    "$lint1" -X '1,2,3,4' code.c /dev/null
     69 
     70 	# Whitespace is not allowed after a comma.
     71 	atf_check \
     72 	    -s 'exit:1' \
     73 	    -e "inline:lint1: invalid message ID ' 2'\n" \
     74 	    "$lint1" -X '1, 2, 3, 4' code.c /dev/null
     75 
     76 	# Trailing commas are not allowed.
     77 	atf_check \
     78 	    -s 'exit:1' \
     79 	    -e "inline:lint1: invalid message ID ''\n" \
     80 	    "$lint1" -X '1,,,,,,,' code.c /dev/null
     81 }
     82 
     83 enable_queries_head()
     84 {
     85 	:
     86 }
     87 
     88 enable_queries_body()
     89 {
     90 	printf 'typedef int dummy;\n' > code.c
     91 
     92 	# Query IDs are 1-based.
     93 	atf_check \
     94 	    -s 'exit:1' \
     95 	    -e "inline:lint1: invalid query ID '0'\n" \
     96 	    "$lint1" -q 0 code.c /dev/null
     97 
     98 	# The largest known query.
     99 	atf_check \
    100 	    "$lint1" -q 14 code.c /dev/null
    101 
    102 	# Larger than the largest known query.
    103 	atf_check \
    104 	    -s 'exit:1' \
    105 	    -e "inline:lint1: invalid query ID '15'\n" \
    106 	    "$lint1" -q 15 code.c /dev/null
    107 
    108 	# Whitespace is not allowed before a query ID.
    109 	atf_check \
    110 	    -s 'exit:1' \
    111 	    -e "inline:lint1: invalid query ID ' 1'\n" \
    112 	    "$lint1" -q ' 1' code.c /dev/null
    113 
    114 	# Whitespace is not allowed after a query ID.
    115 	atf_check \
    116 	    -s 'exit:1' \
    117 	    -e "inline:lint1: invalid query ID '1 '\n" \
    118 	    "$lint1" -q '1 ' code.c /dev/null
    119 
    120 	# Multiple query IDs can be comma-separated.
    121 	atf_check \
    122 	    "$lint1" -q '1,2,3,4' code.c /dev/null
    123 
    124 	# Whitespace is not allowed after a comma.
    125 	atf_check \
    126 	    -s 'exit:1' \
    127 	    -e "inline:lint1: invalid query ID ' 2'\n" \
    128 	    "$lint1" -q '1, 2, 3, 4' code.c /dev/null
    129 
    130 	# Trailing commas are not allowed.
    131 	atf_check \
    132 	    -s 'exit:1' \
    133 	    -e "inline:lint1: invalid query ID ''\n" \
    134 	    "$lint1" -q '1,,,,,,,' code.c /dev/null
    135 }
    136 
    137 atf_init_test_cases()
    138 {
    139 	atf_add_test_case 'suppress_messages'
    140 	atf_add_test_case 'enable_queries'
    141 }
    142