11.2Srillig# $NetBSD: t_groups.sh,v 1.2 2024/04/28 07:27:42 rillig Exp $
21.1Sjruoho#
31.1Sjruoho# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
41.1Sjruoho# All rights reserved.
51.1Sjruoho#
61.1Sjruoho# Redistribution and use in source and binary forms, with or without
71.1Sjruoho# modification, are permitted provided that the following conditions
81.1Sjruoho# are met:
91.1Sjruoho# 1. Redistributions of source code must retain the above copyright
101.1Sjruoho#    notice, this list of conditions and the following disclaimer.
111.1Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
121.1Sjruoho#    notice, this list of conditions and the following disclaimer in the
131.1Sjruoho#    documentation and/or other materials provided with the distribution.
141.1Sjruoho#
151.1Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Sjruoho# POSSIBILITY OF SUCH DAMAGE.
261.1Sjruoho#
271.1Sjruoho
281.1Sjruohocreate_run_groups() {
291.1Sjruoho	cat >run_groups.sh <<EOF
301.1Sjruoho#! /bin/sh
311.1Sjruoho[ -f ./groups ] || ln -s $(atf_get_srcdir)/h_id ./groups
321.1Sjruoho./groups "\${@}"
331.1SjruohoEOF
341.1Sjruoho	chmod +x run_groups.sh
351.1Sjruoho}
361.1Sjruoho
371.1Sjruohoatf_test_case correct
381.1Sjruohocorrect_head() {
391.1Sjruoho	atf_set "descr" "Checks that correct queries work"
401.1Sjruoho}
411.1Sjruohocorrect_body() {
421.1Sjruoho	create_run_groups
431.1Sjruoho
441.1Sjruoho	echo "users wheel" >expout
451.2Srillig	atf_check -s exit:0 -o file:expout -e empty ./run_groups.sh
461.2Srillig	atf_check -s exit:0 -o file:expout -e empty ./run_groups.sh 100
471.2Srillig	atf_check -s exit:0 -o file:expout -e empty ./run_groups.sh test
481.1Sjruoho
491.1Sjruoho	echo "wheel" >expout
501.2Srillig	atf_check -s exit:0 -o file:expout -e empty ./run_groups.sh 0
511.2Srillig	atf_check -s exit:0 -o file:expout -e empty ./run_groups.sh root
521.1Sjruoho}
531.1Sjruoho
541.1Sjruohoatf_test_case syntax
551.1Sjruohosyntax_head() {
561.1Sjruoho	atf_set "descr" "Checks the command's syntax"
571.1Sjruoho}
581.1Sjruohosyntax_body() {
591.1Sjruoho	create_run_groups
601.1Sjruoho
611.1Sjruoho	# Give an invalid flag but which is allowed by id (with which
621.1Sjruoho	# groups shares code) when using the -Gn options.
631.2Srillig	atf_check -s exit:1 -o empty -e save:stderr ./run_groups.sh -r
641.2Srillig	atf_check -s exit:0 -o ignore -e empty grep '^usage:' stderr
651.1Sjruoho}
661.1Sjruoho
671.1Sjruohoatf_init_test_cases()
681.1Sjruoho{
691.1Sjruoho	atf_add_test_case correct
701.1Sjruoho	atf_add_test_case syntax
711.1Sjruoho}
72