[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/
commit: 36b47b9434c7166c3b4b4d62de07d530294c Author: Fabian Groffen gentoo org> AuthorDate: Thu Jun 13 18:31:48 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Thu Jun 13 18:31:48 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=36b47bcc tests/qatom: add exact usage from Puppet provider as test Signed-off-by: Fabian Groffen gentoo.org> tests/qatom/dotest | 4 1 file changed, 4 insertions(+) diff --git a/tests/qatom/dotest b/tests/qatom/dotest index 0d04f40..f478f1c 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -64,6 +64,10 @@ test f20 "cat/pkg"-F '%[CATEGORY]%[PF]' \ test f21 "pkg-123-r4:5::repo" \ -F '%[PF]%[SLOT]%[REPO]' \ "cat/pkg-123-r4:5::repo" +# Puppet portage provider +test p01 "[app-admin] [syslog-ng] [] [] [] [] []" \ + -F "[%[CATEGORY]] [%[PN]] [%[PV]] [%[PR]] [%[SLOT]] [%[pfx]] [%[sfx]]" \ + "app-admin/syslog-ng" # Comparison tests test c01 "cat/pkg-123-r3 == pkg" \
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/, /, libq/
commit: b2418b1406551ce5b540aaf8d332ec53ddd52e01 Author: Fabian Groffen gentoo org> AuthorDate: Thu Jun 13 18:13:57 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Thu Jun 13 18:13:57 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b2418b14 libq/atom: make atom_format smarter to unbreak Puppet The default portage provider in Puppet uses qatom in a rather clumpsy way. The newer formatting broke it because they don't use explicit formatting. Make atom_format somewhat smarter to unbreak Puppet's usage. Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c| 38 ++ libq/atom.h| 4 ++-- qatom.c| 2 +- qcheck.c | 6 +++--- qdepends.c | 6 +++--- qfile.c| 4 ++-- qgrep.c| 2 +- qlist.c| 4 ++-- qlop.c | 24 qmerge.c | 2 +- qsearch.c | 2 +- qsize.c| 2 +- quse.c | 6 +++--- tests/qatom/dotest | 12 +--- 14 files changed, 63 insertions(+), 51 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 12a393a..8ce7f18 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -683,7 +683,7 @@ atom_to_string_r(char *buf, size_t buflen, depend_atom *a) /** * Run printf on an atom. The format field takes the form: * %{keyword}: Always display the field that matches "keyword" or - * %[keyword]: Only display the field when it's set (or pverbose) + * %[keyword]: Only display the field when it's set * The possible "keywords" are: * CATEGORY P PN PV PVR PF PR SLOT SUBSLOT REPO USE *- these are all the standard portage variables (so see ebuild(5)) @@ -695,14 +695,14 @@ atom_format_r( char *buf, size_t buflen, const char *format, - const depend_atom *atom, - int pverbose) + const depend_atom *atom) { char bracket; const char *fmt; const char *p; size_t len; bool showit; + bool connected; char *ret; if (!atom) { @@ -725,21 +725,25 @@ atom_format_r( return ret; } else if (fmt != p) { append_buf(buf, buflen, "%.*s", (int)(fmt - p), p); + connected = false; + } else { + connected = true; } bracket = fmt[1]; if (bracket == '{' || bracket == '[') { + connected &= bracket == '['; fmt += 2; - p = strchr(fmt, bracket == '{' ? '}' : ']'); - if (p) { + if ((p = strchr(fmt, bracket == '{' ? '}' : ']')) != NULL) { len = p - fmt; - showit = (bracket == '{') || pverbose; + showit = bracket == '{'; #define HN(X) (X ? X : "") if (!strncmp("CATEGORY", fmt, len)) { + connected = (p[1] == '%') & (bracket == '['); if (showit || atom->CATEGORY) append_buf(buf, buflen, "%s%s%s%s", BOLD, HN(atom->CATEGORY), - bracket == '[' ? "/" : "", NORM); + connected ? "/" : "", NORM); } else if (!strncmp("P", fmt, len)) { if (showit || atom->P) append_buf(buf, buflen, "%s%s%s", @@ -772,21 +776,21 @@ atom_format_r( if (showit || atom->SLOT) append_buf(buf, buflen, "%s%s%s%s", YELLOW, - bracket == '[' ? ":" : "", + connected ? ":" : "", atom->SLOT ? atom->SLOT : "", NORM); } else if (!strncmp("SUBSLOT", fmt, len)) { if (showit || atom->SUBSLOT) append_buf(buf, buflen, "%s%s%s%s%s", YELLOW, - bracket == '[' ? "/" : "", + connected ? "/" : "",
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/
commit: 93a6fe6ffa64230847644beb1592eb7567e8ea2d Author: Fabian Groffen gentoo org> AuthorDate: Mon May 6 07:30:33 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Mon May 6 07:30:33 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=93a6fe6f tests: adapt qatom new output Signed-off-by: Fabian Groffen gentoo.org> tests/qatom/dotest | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qatom/dotest b/tests/qatom/dotest index 2e16b25..24bd67b 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -30,6 +30,7 @@ test l07 "cat pkg 123 = *" "=cat/pkg-123*" # Explicit format. test f01 "cat"-F '%{CATEGORY}' "cat/pkg" +test f19 "cat/" -F '%[CATEGORY]' "cat/pkg" test f02 ""-F '%{CATEGORY}' "pkg" test f03 "" -F '%[CATEGORY]' "pkg" test f04 "cat"-F '%{CATEGORY}' "cat/pkg-123-r4:5" @@ -39,7 +40,8 @@ test f07 "123"-F '%{PV}' "cat/pkg-123-r4:5" test f08 "123-r4" -F '%{PVR}' "cat/pkg-123-r4:5" test f09 "pkg-123-r4" -F '%{PF}' "cat/pkg-123-r4:5" test f10 "r4" -F '%{PR}' "cat/pkg-123-r4:5" -test f11 ":5" -F '%{SLOT}' "cat/pkg-123-r4:5" +test f11 "5" -F '%{SLOT}' "cat/pkg-123-r4:5" +test f18 "repo" -F '%{REPO}' "cat/pkg-123-r4:5::repo" test f12 "pkg-c" -F '%{PN}' "cat/pkg-c" # bug #639978 test f13 "mod_perl 1.5_p20180304 r5" \ -F '%{PN} %{PV} %{PR}' \
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/, libq/
commit: a7d916ac978023fe35dcd8666d7bc913bab3b0a9 Author: Fabian Groffen gentoo org> AuthorDate: Fri May 18 16:55:58 2018 + Commit: Fabian Groffen gentoo org> CommitDate: Fri May 18 16:55:58 2018 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a7d916ac atom_explode: find the last version-like component We need to keep on searching until we reached the end of the package/version string, since package names may contain things which are valid versions, as long as they don't end with them. Bug: https://bugs.gentoo.org/567336 libq/atom_explode.c | 41 +++-- tests/qatom/dotest | 3 +++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/libq/atom_explode.c b/libq/atom_explode.c index 07d9cec..a4ba569 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -193,27 +193,32 @@ atom_explode(const char *atom) * doesn't validate as version :( */ ptr = ret->PN; - while ((ptr = strchr(ptr, '-')) != NULL) { + { + char *lastpv = NULL; char *pv; - ptr++; - if (!isdigit(*ptr)) - continue; - /* so we should have something like "-2" here, see if this -* checks out as valid version string */ - pv = ptr; - while (*++ptr != '\0') { - if (*ptr != '.' && !isdigit(*ptr)) - break; - } - /* allow for 1 optional suffix letter */ - if (*ptr >= 'a' && *ptr <= 'z') - ret->letter = *ptr++; - if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { - ptr = pv; - break; /* valid */ + while ((ptr = strchr(ptr, '-')) != NULL) { + ptr++; + if (!isdigit(*ptr)) + continue; + + /* so we should have something like "-2" here, see if this +* checks out as valid version string */ + pv = ptr; + while (*++ptr != '\0') { + if (*ptr != '.' && !isdigit(*ptr)) + break; + } + /* allow for 1 optional suffix letter */ + if (*ptr >= 'a' && *ptr <= 'z') + ret->letter = *ptr++; + if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { + lastpv = pv; + continue; /* valid, keep searching */ + } + ret->letter = '\0'; } - ret->letter = '\0'; + ptr = lastpv; } if (ptr == NULL) { diff --git a/tests/qatom/dotest b/tests/qatom/dotest index 01900e6..c879624 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -51,5 +51,8 @@ test f15 "app-emacs diff-mode-" \ test f16 "media-fonts font-adobe-100dpi 1.0.3 r1" \ -F '%{CATEGORY} %{PN} %{PV} %{PR}' \ "media-fonts/font-adobe-100dpi-1.0.3-r1" +test f17 "games-rpg eschalon-book-1-demo 106 r1" \ + -F '%{CATEGORY} %{PN} %{PV} %{PR}' \ + "games-rpg/eschalon-book-1-demo-106-r1" end
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/, libq/
commit: 712cbd379172e444c399a48d08d76a402e822697 Author: Fabian Groffen gentoo org> AuthorDate: Thu Apr 12 18:28:20 2018 + Commit: Fabian Groffen gentoo org> CommitDate: Thu Apr 12 18:28:20 2018 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=712cbd37 atom_explode: try harder to find correct PV It's not enough to find a hyphen followed by something that looks like a version, it needs to be verified it really is, else it is part of the package name. Bug: https://bugs.gentoo.org/653032 libq/atom_explode.c | 51 --- tests/qatom/dotest | 3 +++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libq/atom_explode.c b/libq/atom_explode.c index ec0fc5a..07d9cec 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -189,13 +189,31 @@ atom_explode(const char *atom) * SLOT, REPO or '*' * PN must not end in a hyphen followed by anything matching version * syntax, version syntax starts with a number, so "-[0-9]" is a -* separator from PN to PV* */ +* separator from PN to PV* -- except it doesn't when the thing +* doesn't validate as version :( */ ptr = ret->PN; while ((ptr = strchr(ptr, '-')) != NULL) { + char *pv; ptr++; - if (*ptr >= '0' && *ptr <= '9') - break; + if (!isdigit(*ptr)) + continue; + + /* so we should have something like "-2" here, see if this +* checks out as valid version string */ + pv = ptr; + while (*++ptr != '\0') { + if (*ptr != '.' && !isdigit(*ptr)) + break; + } + /* allow for 1 optional suffix letter */ + if (*ptr >= 'a' && *ptr <= 'z') + ret->letter = *ptr++; + if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { + ptr = pv; + break; /* valid */ + } + ret->letter = '\0'; } if (ptr == NULL) { @@ -216,7 +234,7 @@ atom_explode(const char *atom) } break; } - --ptr; + ptr--; } strcpy(ret->P, ret->PN); ret->PV[-1] = '\0'; @@ -256,29 +274,8 @@ atom_explode(const char *atom) ret->suffixes[idx] = t; } - /* skip back to the "end" */ - for (ptr = ret->PV; *ptr != '\0' && *ptr != '_'; ptr++) - ; - ptr--; - - /* allow for 1 optional suffix letter */ - if (*ptr >= 'a' && *ptr <= 'z') - ret->letter = *ptr--; - - /* eat the trailing version number [.0-9]+ */ - while (ptr > ret->PV) { - if (*ptr != '.' && !isdigit(*ptr)) - break; - ptr--; - } - - if (ptr != ret->PV) { - /* PV isn't exactly a number */ - ret->PV = ret->PVR = NULL; - } else { - ptr = stpcpy(ret->PVR, ret->PV); - sprintf(ptr, "-r%i", ret->PR_int); - } + ptr = stpcpy(ret->PVR, ret->PV); + sprintf(ptr, "-r%i", ret->PR_int); return ret; } diff --git a/tests/qatom/dotest b/tests/qatom/dotest index a0e6a34..01900e6 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -48,5 +48,8 @@ test f14 "foo-r1" -F '%{PN}' "foo-r1" # bug #526596 test f15 "app-emacs diff-mode-" \ -F '%{CATEGORY} %{PN}' \ "app-emacs/diff-mode-" +test f16 "media-fonts font-adobe-100dpi 1.0.3 r1" \ + -F '%{CATEGORY} %{PN} %{PV} %{PR}' \ + "media-fonts/font-adobe-100dpi-1.0.3-r1" end
[gentoo-commits] proj/portage-utils:master commit in: /, tests/qatom/
commit: 17c3a565b626fbace414fae18c733dc578263824 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 2 15:41:41 2018 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 2 15:41:41 2018 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=17c3a565 qatom: print unset members as instead of relying on libc Some libcs do NOT do the favour of turning a NULL-pointer into the string "(null)", but segfault instead. This is just a friendly guesture of libcs which do, but it is nowhere standard or that this should result in "(null)". While "(null)" is actually a developer concept, and possibly out of context for users, check for printing NULL-pointers and replace them with "" instead. qatom.c| 20 tests/qatom/dotest | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/qatom.c b/qatom.c index 7f981c3..b542de8 100644 --- a/qatom.c +++ b/qatom.c @@ -59,21 +59,22 @@ qatom_printf(const char *format, const depend_atom *atom, int pverbose) if (p) { size_t len = p - fmt; bool showit = (bracket == '{') || pverbose; +#define HN(X) (X ? X : "") if (!strncmp("CATEGORY", fmt, len)) { if (showit || atom->CATEGORY) - printf("%s", atom->CATEGORY); + printf("%s", HN(atom->CATEGORY)); } else if (!strncmp("P", fmt, len)) { if (showit || atom->P) - printf("%s", atom->P); + printf("%s", HN(atom->P)); } else if (!strncmp("PN", fmt, len)) { if (showit || atom->PN) - printf("%s", atom->PN); + printf("%s", HN(atom->PN)); } else if (!strncmp("PV", fmt, len)) { if (showit || atom->PV) - printf("%s", atom->PV); + printf("%s", HN(atom->PV)); } else if (!strncmp("PVR", fmt, len)) { if (showit || atom->PVR) - printf("%s", atom->PVR); + printf("%s", HN(atom->PVR)); } else if (!strncmp("PF", fmt, len)) { printf("%s", atom->PN); if (atom->PV) @@ -85,16 +86,19 @@ qatom_printf(const char *format, const depend_atom *atom, int pverbose) printf("r%i", atom->PR_int); } else if (!strncmp("SLOT", fmt, len)) { if (showit || atom->SLOT) - printf(":%s", atom->SLOT ? : "-"); + printf(":%s", atom->SLOT ? atom->SLOT : "-"); } else if (!strncmp("pfx", fmt, len)) { if (showit || atom->pfx_op != ATOM_OP_NONE) - fputs(atom->pfx_op == ATOM_OP_NONE ? "-" : atom_op_str[atom->pfx_op], stdout); + fputs(atom->pfx_op == ATOM_OP_NONE ? + "-" : atom_op_str[atom->pfx_op], stdout); } else if (!strncmp("sfx", fmt, len)) { if (showit || atom->sfx_op != ATOM_OP_NONE) - fputs(atom->sfx_op == ATOM_OP_NONE ? "-" : atom_op_str[atom->sfx_op], stdout); + fputs(atom->sfx_op == ATOM_OP_NONE ? + "-" : atom_op_str[atom->sfx_op], stdout); } else printf("", (int)len, fmt); ++p; +#undef HN } else p = fmt + 1; } else diff --git a/tests/qatom/dotest b/tests/qatom/dotest index c14001f..4bb0460 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -19,8 +19,8 @@ test() { } # Legacy format. -test l01 "(null) pkg (null)" "pkg" -test l02 "cat pkg (null)" "cat/pkg" +test l01 " pkg " "pkg" +test l02 "cat pkg " "cat/pkg" test l03 "cat pkg 123" "cat/pkg-123" test l04 "cat pkg 123 r4" "cat/pkg-123-r4" test l05 "cat pkg 123 r4 :5" "cat/pkg
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/
commit: 41674dc19543e278e09f552f12f5cb7c7590c431 Author: Fabian Groffen gentoo org> AuthorDate: Fri Dec 29 11:52:13 2017 + Commit: Fabian Groffen gentoo org> CommitDate: Fri Dec 29 11:52:13 2017 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=41674dc1 tests/qatom/dotest: fix bug reference I managed to mix up two bugs, the bug this is all about is #639978 tests/qatom/dotest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qatom/dotest b/tests/qatom/dotest index 1ca2367..c14001f 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -40,6 +40,6 @@ test f08 "123-r4" -F '%{PVR}' "cat/pkg-123-r4:5" test f09 "pkg-123-r4" -F '%{PF}' "cat/pkg-123-r4:5" test f10 "r4" -F '%{PR}' "cat/pkg-123-r4:5" test f11 ":5" -F '%{SLOT}' "cat/pkg-123-r4:5" -test f12 "pkg-c" -F '%{PN}' "cat/pkg-c" # bug #638816 +test f12 "pkg-c" -F '%{PN}' "cat/pkg-c" # bug #639978 end
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/
commit: 1ce0f46acdd9c4d32832bcb8ae2b82c021528a09 Author: Fabian Groffen gentoo org> AuthorDate: Thu Dec 28 16:08:03 2017 + Commit: Fabian Groffen gentoo org> CommitDate: Thu Dec 28 16:08:03 2017 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1ce0f46a tests: add test for bug #638816 tests/qatom/dotest | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qatom/dotest b/tests/qatom/dotest index e616a36..1ca2367 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -40,5 +40,6 @@ test f08 "123-r4" -F '%{PVR}' "cat/pkg-123-r4:5" test f09 "pkg-123-r4" -F '%{PF}' "cat/pkg-123-r4:5" test f10 "r4" -F '%{PR}' "cat/pkg-123-r4:5" test f11 ":5" -F '%{SLOT}' "cat/pkg-123-r4:5" +test f12 "pkg-c" -F '%{PN}' "cat/pkg-c" # bug #638816 end
[gentoo-commits] proj/portage-utils:master commit in: tests/qatom/, tests/qfile/, tests/qdepends/, tests/profile/, tests/mkdir/, ...
commit: ab8ec404a6f4442e0a577b43f9f211c88f58 Author: Mike Frysinger gentoo org> AuthorDate: Thu Nov 26 10:05:19 2015 + Commit: Mike Frysinger gentoo org> CommitDate: Thu Nov 26 10:05:19 2015 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ab8ec404 tests: abort if init.sh cannot be loaded This keeps people from running things like `./quse/dotest`. All the test code currently expects you're in the subdir to run dotest. tests/atom_explode/dotest | 2 +- tests/install/dotest | 4 ++-- tests/mkdir/dotest| 2 +- tests/profile/dotest | 2 +- tests/qatom/dotest| 2 +- tests/qcheck/dotest | 2 +- tests/qdepends/dotest | 2 +- tests/qfile/dotest| 2 +- tests/qlist/dotest| 2 +- tests/qlop/dotest | 2 +- tests/qmerge/dotest | 2 +- tests/qtbz2/dotest| 2 +- tests/quse/dotest | 2 +- tests/qxpak/dotest| 2 +- tests/reinitialize/dotest | 2 +- tests/source/dotest | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/atom_explode/dotest b/tests/atom_explode/dotest index c4dc913..41d282a 100755 --- a/tests/atom_explode/dotest +++ b/tests/atom_explode/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 : ${PORTDIR:=$(portageq envvar PORTDIR)} pushd "${PORTDIR}"/metadata/md5-cache >/dev/null || { echo SKIPPED; exit 0 ; } diff --git a/tests/install/dotest b/tests/install/dotest index 246b465..1c790d1 100755 --- a/tests/install/dotest +++ b/tests/install/dotest @@ -1,8 +1,8 @@ #!/bin/bash -rm -f q +. ../init.sh || exit 1 -. ../init.sh +rm -f q applets=$(q -Ch | \ sed -n '/^Currently defined applets:/,/^Options/p' | \ diff --git a/tests/mkdir/dotest b/tests/mkdir/dotest index 1034aa3..a47012d 100755 --- a/tests/mkdir/dotest +++ b/tests/mkdir/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/profile/dotest b/tests/profile/dotest index b4e94c5..2b77ee9 100755 --- a/tests/profile/dotest +++ b/tests/profile/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 qenv() { # get q to dump its processed env so we can check diff --git a/tests/qatom/dotest b/tests/qatom/dotest index 5580b98..e616a36 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 test() { local num=$1 exp=$2 ret=0 out diff --git a/tests/qcheck/dotest b/tests/qcheck/dotest index 9122321..a0e91fa 100755 --- a/tests/qcheck/dotest +++ b/tests/qcheck/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qdepends/dotest b/tests/qdepends/dotest index 8421577..672fb15 100755 --- a/tests/qdepends/dotest +++ b/tests/qdepends/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qfile/dotest b/tests/qfile/dotest index 68f54fb..32ca841 100755 --- a/tests/qfile/dotest +++ b/tests/qfile/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 tests=( "q file -Cq /bin/bash /bin/X" diff --git a/tests/qlist/dotest b/tests/qlist/dotest index 586ac1d..ddcd761 100755 --- a/tests/qlist/dotest +++ b/tests/qlist/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qlop/dotest b/tests/qlop/dotest index 8182e67..6525594 100755 --- a/tests/qlop/dotest +++ b/tests/qlop/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qmerge/dotest b/tests/qmerge/dotest index e5a9c23..3fc01f2 100755 --- a/tests/qmerge/dotest +++ b/tests/qmerge/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qtbz2/dotest b/tests/qtbz2/dotest index 1f10ac1..fec6d0a 100755 --- a/tests/qtbz2/dotest +++ b/tests/qtbz2/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/quse/dotest b/tests/quse/dotest index 0b204a4..da7d95e 100755 --- a/tests/quse/dotest +++ b/tests/quse/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/qxpak/dotest b/tests/qxpak/dotest index c892c84..6c4c78a 100755 --- a/tests/qxpak/dotest +++ b/tests/qxpak/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 set -e diff --git a/tests/reinitialize/dotest b/tests/reinitialize/dotest index c4e3a50..4b51f6d 100755 --- a/tests/reinitialize/dotest +++ b/tests/reinitialize/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 q -Cr tend $? "q -CR" diff --git a/tests/source/dotest b/tests/source/dotest index cff4ddf..f39addf 100755 --- a/tests/source/dotest +++ b/tests/source/dotest @@ -1,6 +1,6 @@ #!/bin/bash -. ../init.sh +. ../init.sh || exit 1 testit() { if [ -s $1 ] ; then
[gentoo-commits] proj/portage-utils:master commit in: /, tests/qatom/, tests/
commit: b07aa71dfb7d6377fe0ca519e7d835f59ae3573d Author: Mike Frysinger gentoo org> AuthorDate: Thu Oct 15 20:17:02 2015 + Commit: Mike Frysinger gentoo org> CommitDate: Thu Oct 15 21:02:35 2015 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b07aa71d qatom: add a --format flag for controlling output Rather than forcing people to deal with the ad-hoc output and run it through another program to reassemble things, add a --format flag so they can explicitly get the output hey care about. This drops support for the letter field, but no one was really using that in the first place. If anyone does care, we can re-add it as a new field. This does change the output slightly from existing behavior: there will be extra spaces between the latter fields, but this shouldn't break existing programs as they generally split on whitespace. qatom.c | 104 +++ tests/Makefile | 2 +- tests/qatom/Makefile | 11 ++ tests/qatom/dotest | 44 ++ 4 files changed, 144 insertions(+), 17 deletions(-) diff --git a/qatom.c b/qatom.c index f2c7ae4..16445dd 100644 --- a/qatom.c +++ b/qatom.c @@ -8,20 +8,104 @@ #ifdef APPLET_qatom -#define QATOM_FLAGS "c" COMMON_FLAGS +#define QATOM_FORMAT "%{CATEGORY} %{PN} %{PV} %[PR] %[SLOT] %[pfx] %[sfx]" + +#define QATOM_FLAGS "F:c" COMMON_FLAGS static struct option const qatom_long_opts[] = { + {"format", a_argument, NULL, 'F'}, {"compare", no_argument, NULL, 'c'}, COMMON_LONG_OPTS }; static const char * const qatom_opts_help[] = { + "Custom output format (default: " QATOM_FORMAT ")", "Compare two atoms", COMMON_OPTS_HELP }; #define qatom_usage(ret) usage(ret, QATOM_FLAGS, qatom_long_opts, qatom_opts_help, lookup_applet_idx("qatom")) +/* Run printf on an atom! The format field takes the form: + * %{keyword}: Always display the field that matches "keyword" + * %[keyword]: Only display the field when it's valid (or pverbose) + * The possible "keywords" are: + * CATEGORY P PN PV PVR PF PR SLOT + *- these are all the standard portage variables (so see ebuild(5)) + * pfx - the version qualifier if set (e.g. > < = !) + * sfx - the version qualifier if set (e.g. *) + */ +_q_static +void qatom_printf(const char *format, const depend_atom *atom, int pverbose) +{ + char bracket; + const char *fmt, *p; + + if (!atom) { + printf("(NULL:atom)"); + return; + } + + p = format; + while (*p != '\0') { + fmt = strchr(p, '%'); + if (fmt == NULL) { + printf("%s", p); + return; + } else if (fmt != p) + printf("%.*s", (int)(fmt - p), p); + + bracket = fmt[1]; + if (bracket == '{' || bracket == '[') { + fmt += 2; + p = strchr(fmt, bracket == '{' ? '}' : ']'); + if (p) { + size_t len = p - fmt; + bool showit = (bracket == '{') || pverbose; + if (!strncmp("CATEGORY", fmt, len)) { + if (showit || atom->CATEGORY) + printf("%s", atom->CATEGORY); + } else if (!strncmp("P", fmt, len)) { + if (showit || atom->P) + printf("%s", atom->P); + } else if (!strncmp("PN", fmt, len)) { + if (showit || atom->PN) + printf("%s", atom->PN); + } else if (!strncmp("PV", fmt, len)) { + if (showit || atom->PV) + printf("%s", atom->PV); + } else if (!strncmp("PVR", fmt, len)) { + if (showit || atom->PVR) + printf("%s", atom->PVR); + } else if (!strncmp("PF", fmt, len)) { + printf("%s", atom->PN); + if (atom->PV) + printf("-%s", atom->PV); + if (atom->PR_int) + printf("-r%i", atom->PR_int); + } else if (!strncmp("PR", fmt, len)) { + if (showit || atom->PR_int) + printf("r%i", atom->PR_int); + } else if (!strncmp("SLOT", fmt, len)) { +