# $NetBSD: t_lint2.sh,v 1.13 2021/12/16 09:38:54 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
lint2=/usr/libexec/lint2
std_head()
{
atf_set 'require.progs' "$lint2"
}
std_body()
{
# shellcheck disable=SC2155
local srcdir="$(atf_get_srcdir)"
# remove comments and whitespace from the .ln file
sed -e '/^#/d' -e '/^$/d' -e 's,#.*,,' -e 's,[[:space:]],,g' \
< "$srcdir/$1.ln" \
> "$1.ln"
error_cases_head()
{
std_head
}
error_cases_body()
{
test_error '' 'missing record type'
test_error '123' 'missing record type'
test_error '0X' 'not a number: '
test_error '0d' 'not a number: '
test_error '0dXYZ' 'not a number: XYZ'
test_error '0d123' 'bad line number'
test_error '0d123.XYZ' 'not a number: XYZ'
test_error '0X0.0' 'bad record type X'
# function calls
test_error '0c0.0' 'not a number: '
test_error '0c0.0uu' 'used or discovered: u'
test_error '0c0.0du' 'used or discovered: u'
test_error '0c0.0ui' 'used or discovered: i'
test_error '0c0.0di' 'used or discovered: i'
test_error '0c0.0ud' 'used or discovered: d'
test_error '0c0.0dd' 'used or discovered: d'
# Unlike 'd' and 'u', the 'i' may be repeated.
test_error '0c0.0iiiiiii1n_' 'bad type: _ '
# Negative argument numbers like in 'z-1' are accepted but ignored.
test_error '0c0.0z-1d_' 'not a number: _'
# Argument 1 is both positive '1p' and negative '1n', which is
# impossible in practice. It is not worth handling this though since
# only lint1 generates these .ln files.
test_error '0c0.0p1n1d_' 'not a number: _'
test_error '0c0.0s' 'not a number: '
test_error '0c0.0s2' 'not quote: '
test_error '0c0.0s2|' 'not quote: |'
test_error '0c0.0s2"' 'trailing data: '
test_error '0c0.0s2"%' 'missing closing quote'
# shellcheck disable=SC1003
test_error '0c0.0s2"\' 'missing after \\' '0c0\.0s2"\\'
# shellcheck disable=SC1003
test_error '0c0.0s2"%\' 'missing after \\' '0c0\.0s2"%\\'
# usage of a variable or a function
test_error '0u0.0' 'bad delim '
test_error '0u0.0_' 'bad delim _'
test_error '0u0.0x' 'not a number: '
# trailing garbage is not detected
test_error_ignored '0u0.0x3var_'
}
missing_newline_head()
{
std_head
}
missing_newline_body()
{
# Before read.c 1.72 from 2021-12-16, the error message was just 'c'
# without any textual description or context, and the line number was
# off by one, it was reported as line 0.