From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A067B13835A for ; Mon, 23 Nov 2020 18:11:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9E91CE081B; Mon, 23 Nov 2020 18:11:34 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 85B64E081B for ; Mon, 23 Nov 2020 18:11:34 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AD567340C08 for ; Mon, 23 Nov 2020 18:11:32 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 35CD144F for ; Mon, 23 Nov 2020 18:11:31 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1606154472.754aa946555ccc3f6657922d91a1d2c34b419053.ulm@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/tests/eapi8-dosym.sh X-VCS-Directories: eclass/tests/ X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: 754aa946555ccc3f6657922d91a1d2c34b419053 X-VCS-Branch: master Date: Mon, 23 Nov 2020 18:11:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 1e98a430-d8ff-447f-87c9-aceabfe0a293 X-Archives-Hash: 71496122310f84a9e2567e1a388e76b2 commit: 754aa946555ccc3f6657922d91a1d2c34b419053 Author: Ulrich Müller gentoo org> AuthorDate: Tue Nov 17 20:13:14 2020 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Mon Nov 23 18:01:12 2020 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=754aa946 eclass/tests: Initial test cases for eapi8-dosym.eclass. Signed-off-by: Ulrich Müller gentoo.org> eclass/tests/eapi8-dosym.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/eclass/tests/eapi8-dosym.sh b/eclass/tests/eapi8-dosym.sh new file mode 100755 index 00000000000..e1160c42d87 --- /dev/null +++ b/eclass/tests/eapi8-dosym.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Copyright 2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +source tests-common.sh + +inherit eapi8-dosym + +dosym() { + echo "$1" +} + +# reference implementation using GNU realpath +ref_canonicalize() { + realpath -m -s "$1" +} + +ref_dosym_r() { + local link=$(realpath -m -s "/${2#/}") + realpath -m -s --relative-to="$(dirname "${link}")" "$1" +} + +randompath() { + dd if=/dev/urandom bs=128 count=1 2>/dev/null | LC_ALL=C sed \ + -e 's/[^a-zA-M]//g;s/[A-E]/\/.\//g;s/[F-J]/\/..\//g;s/[K-M]/\//g' \ + -e 's/^/\//;q' +} + +teq() { + local expected=$1; shift + tbegin "$* -> ${expected}" + local got=$("$@") + [[ ${got} == "${expected}" ]] + tend $? "returned: ${got}" +} + +for f in ref_canonicalize "_dosym8_canonicalize"; do + # canonicalize absolute paths + teq / ${f} / + teq /foo/baz/quux ${f} /foo/bar/../baz/quux + teq /foo ${f} /../../../foo + teq /bar ${f} /foo//./..///bar + teq /baz ${f} /foo/bar/../../../baz + teq /a/d/f/g ${f} /a/b/c/../../d/e/../f/g +done + +# canonicalize relative paths (not actually used) +teq . _dosym8_canonicalize . +teq foo _dosym8_canonicalize foo +teq foo _dosym8_canonicalize ./foo +teq ../foo _dosym8_canonicalize ../foo +teq ../baz _dosym8_canonicalize foo/bar/../../../baz + +for f in ref_dosym_r "dosym8 -r"; do + teq ../../bin/foo ${f} /bin/foo /usr/bin/foo + teq ../../../doc/foo-1 \ + ${f} /usr/share/doc/foo-1 /usr/share/texmf-site/doc/fonts/foo + teq ../../opt/bar/foo ${f} /opt/bar/foo /usr/bin/foo + teq ../c/d/e ${f} /a/b/c/d/e a/b/f/g + teq b/f ${f} /a/b///./c/d/../e/..//../f /a/././///g/../h + teq ../h ${f} /a/././///g/../h /a/b///./c/d/../e/..//../f + teq . ${f} /foo /foo/bar + teq .. ${f} /foo /foo/bar/baz + teq '../../fo . o/b ar' ${f} '/fo . o/b ar' '/baz / qu .. ux/qu x' + teq '../../f"o\o/b$a[]r' ${f} '/f"o\o/b$a[]r' '/ba\z/qu$u"x/qux' +done + +# set RANDOMTESTS to a positive number to enable random tests +for (( i = 0; i < RANDOMTESTS; i++ )); do + targ=$(randompath) + link=$(randompath) + out=$(ref_dosym_r "${targ}" "${link}") + teq "${out}" dosym8 -r "${targ}" "${link}" +done + +texit