[Debtags-commits] [svn] r1637 - in tagcoll/trunk: tagcoll tests
tests/data tools
Enrico Zini
enrico at costa.debian.org
Sun Mar 5 14:27:11 UTC 2006
Author: enrico
Date: Sun Mar 5 14:27:09 2006
New Revision: 1637
Added:
tagcoll/trunk/tests/data/test-collection
tagcoll/trunk/tests/data/test-collection-colorsonly
tagcoll/trunk/tests/data/test-collection-diffed
tagcoll/trunk/tests/data/test-collection-faceted
tagcoll/trunk/tests/data/test-collection-grepped
tagcoll/trunk/tests/data/test-collection-items
tagcoll/trunk/tests/data/test-collection-reversed
Removed:
tagcoll/trunk/tools/CommandlineParser.cc
tagcoll/trunk/tools/CommandlineParser.h
Modified:
tagcoll/trunk/tagcoll/Commandline.cc
tagcoll/trunk/tests/Makefile.am
tagcoll/trunk/tools/Makefile.am
tagcoll/trunk/tools/TagcollOptions.h
tagcoll/trunk/tools/tagcoll.cc
Log:
Started to write testing scripts for the commandline tools as well
Fixed some of the bugs that came out
Modified: tagcoll/trunk/tagcoll/Commandline.cc
==============================================================================
--- tagcoll/trunk/tagcoll/Commandline.cc (original)
+++ tagcoll/trunk/tagcoll/Commandline.cc Sun Mar 5 14:27:09 2006
@@ -554,7 +554,11 @@
i != o.groups().end(); i++)
{
if (!(*i)->description.empty())
+ {
+ out << endl;
writer.outstring((*i)->description + ":");
+ out << endl;
+ }
for (vector<Option*>::const_iterator j = (*i)->options.begin();
j != (*i)->options.end(); j++)
writer.outlist(" " + (*j)->fullUsage(), maxLeftCol + 3, (*j)->description);
@@ -563,6 +567,7 @@
{
out << endl;
writer.outstring("Other options:");
+ out << endl;
for (vector<Option*>::const_iterator j = o.options().begin();
j != o.options().end(); j++)
writer.outlist(" " + (*j)->fullUsage(), maxLeftCol + 3, (*j)->description);
@@ -832,72 +837,6 @@
addHook(section, placement, text);
fclose(in);
}
-#if 0
-void Help::outputMan(std::ostream& out, const OptionParser& o, int section)
-{
- HelpWriter writer(out);
-
- out << "Usage: " << m_app << " [options] " << o.primaryAlias << " [options] " << o.usage << endl;
- out << endl;
- if (!o.aliases.empty())
- {
- out << "Command aliases: ";
- for (vector<string>::const_iterator i = o.aliases.begin();
- i != o.aliases.end(); i++)
- if (i == o.aliases.begin())
- out << *i;
- else
- out << ", " << *i;
- out << "." << endl;
- out << endl;
- }
- writer.outstring("Description: " + o.description);
-
- // Compute size of option display
- size_t maxLeftCol = 0;
- for (vector<OptionGroup*>::const_iterator i = o.m_groups.begin();
- i != o.m_groups.end(); i++)
- for (vector<Option*>::const_iterator j = (*i)->options.begin();
- j != (*i)->options.end(); j++)
- {
- size_t w = (*j)->fullUsage().size();
- if (w > maxLeftCol)
- maxLeftCol = w;
- }
- for (vector<Option*>::const_iterator j = o.m_options.begin();
- j != o.m_options.end(); j++)
- {
- size_t w = (*j)->fullUsage().size();
- if (w > maxLeftCol)
- maxLeftCol = w;
- }
-
- if (maxLeftCol)
- {
- // Output the options
- out << endl;
- out << "Options are:" << endl;
- for (vector<OptionGroup*>::const_iterator i = o.m_groups.begin();
- i != o.m_groups.end(); i++)
- {
- if (!(*i)->description.empty())
- writer.outstring((*i)->description + ":");
- for (vector<Option*>::const_iterator j = (*i)->options.begin();
- j != (*i)->options.end(); j++)
- writer.outlist(" " + (*j)->fullUsage(), maxLeftCol + 3, (*j)->description);
- }
- if (!o.m_options.empty())
- {
- out << endl;
- writer.outstring("Other options:");
- for (vector<Option*>::const_iterator j = o.m_options.begin();
- j != o.m_options.end(); j++)
- writer.outlist(" " + (*j)->fullUsage(), maxLeftCol + 3, (*j)->description);
- }
- }
- out << endl;
-}
-#endif
}
}
Modified: tagcoll/trunk/tests/Makefile.am
==============================================================================
--- tagcoll/trunk/tests/Makefile.am (original)
+++ tagcoll/trunk/tests/Makefile.am Sun Mar 5 14:27:09 2006
@@ -1,4 +1,4 @@
-TESTS = libtagcoll-test
+TESTS = libtagcoll-test tagcoll-test
check_PROGRAMS = libtagcoll-test
libtagcoll_test_SOURCES = tut-main.cpp
# Disabled: it failed, but it also looks meaningless as it is
Modified: tagcoll/trunk/tools/Makefile.am
==============================================================================
--- tagcoll/trunk/tools/Makefile.am (original)
+++ tagcoll/trunk/tools/Makefile.am Sun Mar 5 14:27:09 2006
@@ -6,10 +6,10 @@
tagcoll_SOURCES = tagcoll.cc
tagcoll_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
-taggrep_SOURCES = taggrep.cc CommandlineParser.cc
+taggrep_SOURCES = taggrep.cc
taggrep_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
-tagidx_SOURCES = tagidx.cc CommandlineParser.cc
+tagidx_SOURCES = tagidx.cc
tagidx_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
manpage_SOURCES = manpage.cc
Modified: tagcoll/trunk/tools/TagcollOptions.h
==============================================================================
--- tagcoll/trunk/tools/TagcollOptions.h (original)
+++ tagcoll/trunk/tools/TagcollOptions.h Sun Mar 5 14:27:09 2006
@@ -54,16 +54,16 @@
ExistingFileOption* extimpl;
ExistingFileOption* rename;
ExistingFileOption* patch;
- StringOption* rmunfaceted;
+ BoolOption* rmunfaceted;
StringOption* rmtags;
InputGroup()
{
- add(derived = new ExistingFileOption("derived-tags-from", 'e', "derived"));
- add(extimpl = new ExistingFileOption("extimpl", 'i', "implications-from"));
- add(rename = new ExistingFileOption("rename", 'r', "rename-from"));
+ add(derived = new ExistingFileOption("derived-tags-from", 0, "derived"));
+ add(extimpl = new ExistingFileOption("extimpl", 0, "implications-from"));
+ add(rename = new ExistingFileOption("rename", 0, "rename-from"));
add(patch = new ExistingFileOption("patch", 'p', "patch-with"));
- add(rmunfaceted = new StringOption("rmunfaceted", 0, "remove-unfaceted"));
+ add(rmunfaceted = new BoolOption("rmunfaceted", 0, "remove-unfaceted"));
add(rmtags = new StringOption("rmtags", 0, "remove-tags"));
derived->description = "expand derived tags using the given list";
@@ -87,14 +87,17 @@
{
BoolOption* group;
BoolOption* redundant;
+ BoolOption* itemsOnly;
OutputGroup()
{
add(group = new BoolOption("group", 'g', "group"));
add(redundant = new BoolOption("redundant", 0, "redundant"));
+ add(itemsOnly = new BoolOption("items", 'i', "items"));
group->description = "group items with the same tagset in the output collection";
group->longNames.push_back("group-items");
redundant->description = "when implications are provided, expand them explicitly in the output";
+ itemsOnly->description = "output only the names of the items, without the tags";
description = "Options controlling transformations of output data";
}
~OutputGroup()
@@ -309,21 +312,11 @@
add(&cp->helpGroup);
}
} grep;
- struct Items : public OptionParser
- {
- Items(TagcollOptions* cp) : OptionParser("items")
- {
- usage = "[files...]";
- description = "output only the items of the input collection";
- add(&cp->inputGroup);
- add(&cp->helpGroup);
- }
- } items;
TagcollOptions() : MainParser<CommandParser>("tagcoll"),
generic(this),
help(this), copy(this), reverse(this), diff(this), related(this), implications(this),
- hierarchy(this), cleanhierarchy(this), findspecials(this), grep(this), items(this)
+ hierarchy(this), cleanhierarchy(this), findspecials(this), grep(this)
{
add(generic);
add(help);
@@ -336,7 +329,6 @@
add(cleanhierarchy);
add(findspecials);
add(grep);
- add(items);
usage = "<command> [options and arguments]";
description = "Perform various operations on a tagged collection";
Modified: tagcoll/trunk/tools/tagcoll.cc
==============================================================================
--- tagcoll/trunk/tools/tagcoll.cc (original)
+++ tagcoll/trunk/tools/tagcoll.cc Sun Mar 5 14:27:09 2006
@@ -281,6 +281,35 @@
ItemsOnly(Consumer<ITEM, TAG>& cons) : Filter<ITEM, TAG>(cons) {}
};
+template<typename ITEM, typename TAG>
+class Reverser : public Consumer<ITEM, TAG>
+{
+protected:
+ Consumer<TAG, ITEM>* consumer;
+ TAG reversedNull;
+
+ virtual void consumeItemUntagged(const ITEM& item)
+ {
+ consumer->consume(reversedNull, OpSet<ITEM>() + item);
+ }
+ virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags)
+ {
+ consumer->consume(tags, OpSet<ITEM>() + item);
+ }
+ virtual void consumeItemsUntagged(const OpSet<ITEM>& items)
+ {
+ consumer->consume(reversedNull, items);
+ }
+ virtual void consumeItem(const OpSet<ITEM>& items, const OpSet<TAG>& tags)
+ {
+ consumer->consume(tags, items);
+ }
+
+public:
+ Reverser(Consumer<TAG, ITEM>& cons, const TAG& reversedNull = TAG()) :
+ consumer(&cons), reversedNull(reversedNull) {}
+};
+
class Reader
{
// Prepare the input filter chain
@@ -384,6 +413,7 @@
TrivialConverter<string, string> conv;
TextFormat<string, string> output;
ItemGrouper<string, string>* grouper;
+ bool itemsOnly;
protected:
/// Process an untagged item
@@ -398,7 +428,9 @@
/// Process a tagged item, with its tags
virtual void consumeItem(const string& item, const OpSet<string>& tags)
{
- if (grouper)
+ if (itemsOnly)
+ consumeItemUntagged(item);
+ else if (grouper)
grouper->consume(item, tags);
else
output.consume(item, tags);
@@ -419,7 +451,9 @@
/// Process a set of items identically tagged, with their tags
virtual void consumeItems(const OpSet<string>& items, const OpSet<string>& tags)
{
- if (grouper)
+ if (itemsOnly)
+ consumeItemsUntagged(items);
+ else if (grouper)
grouper->consume(items, tags);
else
// Explicitly split groups
@@ -434,6 +468,7 @@
{
if (opts.outputGroup.group->boolValue())
grouper = new ItemGrouper<string, string>;
+ itemsOnly = opts.outputGroup.itemsOnly->boolValue();
}
~Writer()
{
@@ -636,16 +671,16 @@
}
else if (opts.lastCommand() == &opts.reverse)
{
- ItemGrouper<string, string> reverser;
- reader.output(opts, reverser);
-
- /*
+ string revnull;
if (opts.reverse.untaggedTag->boolValue())
- reverser.setUntaggedItemName(opts.reverse.untaggedTag->stringValue());
- */
+ revnull = opts.reverse.untaggedTag->stringValue();
+
+ InputMerger<string, string> reversed;
+ Reverser<string, string> reverser(reversed, revnull);
+ reader.output(opts, reverser);
Writer writer(opts);
- reverser.outputReversed(writer);
+ reversed.output(writer);
}
else if (opts.lastCommand() == &opts.copy)
{
@@ -703,12 +738,6 @@
FilterItemsByExpression<string, string> filter(writer, opts.next());
reader.output(opts, filter);
}
- else if (opts.lastCommand() == &opts.items)
- {
- Writer writer(opts);
- ItemsOnly<string, string> filter(writer);
- reader.output(opts, filter);
- }
else
throw commandline::BadOption(string("unhandled command ") +
(opts.lastCommand() ? opts.lastCommand()->name() : "(null)"));
More information about the Debtags-commits
mailing list