t_date.sh revision 1.2
11.2Skre# $NetBSD: t_date.sh,v 1.2 2020/10/30 22:03:35 kre Exp $
21.1Sjruoho#
31.1Sjruoho# Copyright (c) 2020 The NetBSD Foundation, Inc.
41.1Sjruoho# All rights reserved.
51.1Sjruoho#
61.1Sjruoho# This code is derived from software contributed to The NetBSD Foundation
71.1Sjruoho# by Jukka Ruohonen.
81.1Sjruoho#
91.1Sjruoho# Redistribution and use in source and binary forms, with or without
101.1Sjruoho# modification, are permitted provided that the following conditions
111.1Sjruoho# are met:
121.1Sjruoho# 1. Redistributions of source code must retain the above copyright
131.1Sjruoho#    notice, this list of conditions and the following disclaimer.
141.1Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
151.1Sjruoho#    notice, this list of conditions and the following disclaimer in the
161.1Sjruoho#    documentation and/or other materials provided with the distribution.
171.1Sjruoho#
181.1Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Sjruoho# POSSIBILITY OF SUCH DAMAGE.
291.1Sjruoho#
301.1Sjruohoatf_test_case overflow
311.1Sjruohooverflow_head() {
321.1Sjruoho	atf_set "descr" "Check that date(1) does not overflow (PR lib/46542)"
331.1Sjruoho}
341.1Sjruoho
351.1Sjruohooverflow_body() {
361.1Sjruoho
371.2Skre	## atf_expect_fail "PR lib/46542"	# no longer true
381.1Sjruoho
391.1Sjruoho	years="1 10 100 1000 10000 100000 1000000 10000000 \
401.1Sjruoho	      100000000 1000000000 10000000000 100000000000"
411.1Sjruoho
421.1Sjruoho	for year in $years; do
431.1Sjruoho
441.1Sjruoho		y=$(date +%Y)
451.2Skre		yy=$((y + year))
461.2Skre		yyy=$(date -d "$year years" +%Y) || continue
471.1Sjruoho
481.2Skre		if [ "$yy" -ne "$yyy" ]; then
491.1Sjruoho			atf_fail "$yy vs. $yyy"
501.1Sjruoho		fi
511.1Sjruoho	done
521.1Sjruoho}
531.1Sjruoho
541.1Sjruohoatf_init_test_cases() {
551.1Sjruoho	atf_add_test_case overflow
561.1Sjruoho}
57