Date: Fri, 5 Jul 2013 01:01:34 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254077 - soc2013/mattbw/tests/get-details-output Message-ID: <201307050101.r6511YdL037694@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Fri Jul 5 01:01:34 2013 New Revision: 254077 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254077 Log: Added initial output test for GetDetails. Added: soc2013/mattbw/tests/get-details-output/ soc2013/mattbw/tests/get-details-output/Makefile soc2013/mattbw/tests/get-details-output/getcat.1 soc2013/mattbw/tests/get-details-output/getcat.c soc2013/mattbw/tests/get-details-output/strip_messages.awk soc2013/mattbw/tests/get-details-output/test-output.sh (contents, props changed) Added: soc2013/mattbw/tests/get-details-output/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/get-details-output/Makefile Fri Jul 5 01:01:34 2013 (r254077) @@ -0,0 +1,12 @@ +# $FreeBSD$ + +PROG= getcat +SRCS= getcat.c ../../backend/groups.c + +CFLAGS+= `pkgconf --cflags pkg glib-2.0` +CFLAGS+= -I/usr/local/include/PackageKit -I/usr/local/include/PackageKit/backend +CFLAGS+= -I../../backend +CFLAGS+= -DPK_COMPILATION +LDFLAGS+= `pkgconf --libs pkg glib-2.0` -lpackagekit-glib2 + +.include <bsd.prog.mk> Added: soc2013/mattbw/tests/get-details-output/getcat.1 ============================================================================== Added: soc2013/mattbw/tests/get-details-output/getcat.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/get-details-output/getcat.c Fri Jul 5 01:01:34 2013 (r254077) @@ -0,0 +1,51 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * Gets the group name of a pkgng origin, eg 'ports-mgmt/pkg' -> 'admin-tools'. + */ +const char *USAGE = "usage: %s origin\n"; + +#include <stdio.h> + +#include <glib.h> +#include "pkg.h" +#include "pk-backend.h" + +#include "groups.h" + + +int +main(int argc, char **argv) +{ + int ret; + + ret = 0; + if (argc != 2) { + ret = 1; + fprintf(stderr, USAGE, argv[0]); + } else { + printf("%s\n", + pk_group_enum_to_string(group_from_origin(argv[1]))); + } + + return ret; +} Added: soc2013/mattbw/tests/get-details-output/strip_messages.awk ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/get-details-output/strip_messages.awk Fri Jul 5 01:01:34 2013 (r254077) @@ -0,0 +1,4 @@ +# Strips in-band auxiliary messages from a `pkcon` run, leaving only the results +BEGIN { in_description=0 } +!/Message:.*/ && in_description { print } +/Results:/ { in_description=1 } Added: soc2013/mattbw/tests/get-details-output/test-output.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/get-details-output/test-output.sh Fri Jul 5 01:01:34 2013 (r254077) @@ -0,0 +1,59 @@ +#!/bin/sh + +# Tests pkcon against pkg to make sure the pkg backend works correctly for GetDetails. +# +# More black-box tests should be written later + +if [ $# -eq 1 ] +then + PACKAGE="$1" +else + PACKAGE="pkg" +fi + +echo "using package ${PACKAGE}" + +# Get the expected ABI through some invasive inspection of the pkg config dump +ARCH="`pkg -vv | grep ABI | sed 's/ *ABI: *//'`" + +CMD_GETCAT="./getcat" + +# Get the PackageKit group of the package +ORIGIN="`pkg query \"%o\" ${PACKAGE}`" +GROUP="`${CMD_GETCAT} ${ORIGIN}`" + +# Get the licences by mashing the `pkg query` licence list and or/and/single identifier +# into one "licence or licence or licence" string. +LICENSE=`\ + pkg query "%L %l" "${PACKAGE}" | # "licence or\nlicence or\n" + tr "\n" " " | # "licence or licence or ", note space + sed 's/ *[^ ]* *$//'` # "licence or licence" + +# Build a format string for the query that mocks up a pkcon GetDetails result +FMT="Package description + package: %n-%v.${ARCH} + license: ${LICENSE} + group: ${GROUP} + description: %e + size: %sb bytes + url: %w" + +# Now run both queries and diff them +PKG_FILE="${PACKAGE}-pkg" +PKCON_FILE="${PACKAGE}-pkcon" + +pkg query "${FMT}" "${PACKAGE}" > "${PKG_FILE}" +pkcon get-details "${PACKAGE};;;installed" | awk -f "strip_messages.awk" > "${PKCON_FILE}" + +DIFF="`diff -rupN \"${PACKAGE}-pkg\" \"${PACKAGE}-pkcon\"`" +if [ -n "${DIFF}" ] +then + echo "test failed with diff:" + echo "${DIFF}" + RETURN=1 +else + echo "test succeeded" + RETURN=0 +fi + +return $RETURN
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307050101.r6511YdL037694>