From 6b90c6c8762da5f0dcd6c0f87a60f06cd0584ee6 Mon Sep 17 00:00:00 2001 From: Jasper van de Gronde Date: Tue, 1 Jul 2008 18:18:32 +0000 Subject: CxxTest unit tests can now be built on Windows, also adds CxxTest versions of most UTEST unit tests. (These new CxxTest tests are not part of make check on Linux yet.) (bzr r6106) --- buildtool.cpp | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 215 insertions(+), 6 deletions(-) (limited to 'buildtool.cpp') diff --git a/buildtool.cpp b/buildtool.cpp index 852e65124..c3b0a2953 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -3,6 +3,7 @@ * * Authors: * Bob Jamison + * Jasper van de Gronde * * Copyright (C) 2006-2008 Bob Jamison * @@ -2778,7 +2779,7 @@ public: /** * */ - String getDirectory() + String getDirectory() const { return directory; } /** @@ -2796,7 +2797,7 @@ public: /** * */ - std::vector getFiles() + std::vector getFiles() const { return files; } /** @@ -2808,7 +2809,7 @@ public: /** * */ - std::vector getIncludes() + std::vector getIncludes() const { return includes; } /** @@ -2820,19 +2821,19 @@ public: /** * */ - std::vector getExcludes() + std::vector getExcludes() const { return excludes; } /** * */ - unsigned int size() + unsigned int size() const { return files.size(); } /** * */ - String operator[](int index) + String operator[](int index) const { return files[index]; } /** @@ -6374,6 +6375,8 @@ public: TASK_NONE, TASK_CC, TASK_COPY, + TASK_CXXTEST_PART, + TASK_CXXTEST_ROOT, TASK_DELETE, TASK_ECHO, TASK_JAR, @@ -7079,6 +7082,208 @@ private: }; +/** + * Generate CxxTest files + */ +class TaskCxxTestPart: public Task +{ +public: + + TaskCxxTestPart(MakeBase &par) : Task(par) + { + type = TASK_CXXTEST_PART; + name = "cxxtestpart"; + } + + virtual ~TaskCxxTestPart() + {} + + virtual bool execute() + { + if (!listFiles(parent, fileSet)) + return false; + String fileSetDir = parent.eval(fileSet.getDirectory(), "."); + + String fullDest = parent.resolve(parent.eval(destPathOpt, ".")); + String cmd = parent.eval(commandOpt, "cxxtestgen.py"); + cmd.append(" --part -o "); + cmd.append(fullDest); + + unsigned int newFiles = 0; + for (unsigned int i=0 ; i0) + { + sourcePath.append(fileSetDir); + sourcePath.append("/"); + } + sourcePath.append(fileName); + String fullSource = parent.resolve(sourcePath); + + cmd.append(" "); + cmd.append(fullSource); + if (isNewerThan(fullSource, fullDest)) newFiles++; + } + + if (newFiles>0) { + size_t const lastSlash = fullDest.find_last_of('/'); + if (lastSlash != fullDest.npos) { + String directory(fullDest, 0, lastSlash); + if (!createDirectory(directory)) + return false; + } + + String outString, errString; + if (!executeCommand(cmd.c_str(), "", outString, errString)) + { + error(" problem: %s", errString.c_str()); + return false; + } + } + + return true; + } + + virtual bool parse(Element *elem) + { + if (!parent.getAttribute(elem, "command", commandOpt)) + return false; + if (!parent.getAttribute(elem, "out", destPathOpt)) + return false; + + std::vector children = elem->getChildren(); + for (unsigned int i=0 ; igetName(); + if (tagName == "fileset") + { + if (!parseFileSet(child, parent, fileSet)) + return false; + } + } + return true; + } + +private: + + String commandOpt; + String destPathOpt; + FileSet fileSet; + +}; + + +/** + * Generate the CxxTest root file + */ +class TaskCxxTestRoot: public Task +{ +public: + + TaskCxxTestRoot(MakeBase &par) : Task(par) + { + type = TASK_CXXTEST_ROOT; + name = "cxxtestroot"; + } + + virtual ~TaskCxxTestRoot() + {} + + virtual bool execute() + { + if (!listFiles(parent, fileSet)) + return false; + String fileSetDir = parent.eval(fileSet.getDirectory(), "."); + unsigned int newFiles = 0; + + String fullDest = parent.resolve(parent.eval(destPathOpt, ".")); + String cmd = parent.eval(commandOpt, "cxxtestgen.py"); + cmd.append(" --root -o "); + cmd.append(fullDest); + String templateFile = parent.eval(templateFileOpt, ""); + if (templateFile.size()>0) { + String fullTemplate = parent.resolve(templateFile); + cmd.append(" --template="); + cmd.append(fullTemplate); + if (isNewerThan(fullTemplate, fullDest)) newFiles++; + } + + for (unsigned int i=0 ; i0) + { + sourcePath.append(fileSetDir); + sourcePath.append("/"); + } + sourcePath.append(fileName); + String fullSource = parent.resolve(sourcePath); + + cmd.append(" "); + cmd.append(fullSource); + if (isNewerThan(fullSource, fullDest)) newFiles++; + } + + if (newFiles>0) { + size_t const lastSlash = fullDest.find_last_of('/'); + if (lastSlash != fullDest.npos) { + String directory(fullDest, 0, lastSlash); + if (!createDirectory(directory)) + return false; + } + + String outString, errString; + if (!executeCommand(cmd.c_str(), "", outString, errString)) + { + error(" problem: %s", errString.c_str()); + return false; + } + } + + return true; + } + + virtual bool parse(Element *elem) + { + if (!parent.getAttribute(elem, "command", commandOpt)) + return false; + if (!parent.getAttribute(elem, "template", templateFileOpt)) + return false; + if (!parent.getAttribute(elem, "out", destPathOpt)) + return false; + + std::vector children = elem->getChildren(); + for (unsigned int i=0 ; igetName(); + if (tagName == "fileset") + { + if (!parseFileSet(child, parent, fileSet)) + return false; + } + } + return true; + } + +private: + + String commandOpt; + String templateFileOpt; + String destPathOpt; + FileSet fileSet; + +}; + + /** * */ @@ -8481,6 +8686,10 @@ Task *Task::createTask(Element *elem, int lineNr) task = new TaskCC(parent); else if (tagName == "copy") task = new TaskCopy(parent); + else if (tagName == "cxxtestpart") + task = new TaskCxxTestPart(parent); + else if (tagName == "cxxtestroot") + task = new TaskCxxTestRoot(parent); else if (tagName == "delete") task = new TaskDelete(parent); else if (tagName == "echo") -- cgit v1.2.3