source: trunk/test/Suite.cc @ 744

Last change on this file since 744 was 744, checked in by Peter Johansson, 14 years ago

fixes #355 - skipping tests. Added some support in test::Suite to handle the test repo. There is a bool in constructor telling if the tests needs the test repo. test::Suite uses a new script svn_update.sh to check out and update the test repo. This script is used in test_repo.sh as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: Suite.cc 744 2009-01-08 22:37:12Z peter $
2
3/*
4  Copyright (C) 2008, 2009 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "Suite.h"
25#include "environment.h"
26
27#include "utility.h"
28
29#include <cassert>
30#include <fstream>
31#include <iostream>
32#include <string>
33
34namespace theplu {
35namespace svndigest {
36namespace test {
37
38  Suite::Suite(int argc, char* argv[], bool need_test_repo)
39    : dev_null_(NULL), ok_(true), verbose_(false)
40  {
41    char* buffer=std::getenv("VERBOSE");
42    if ( (argc>1 && (argv[1]==std::string("-v") 
43                     || argv[1]==std::string("--verbose")) 
44          || (buffer && buffer == std::string("1"))) ) {
45      verbose_=true;
46    }
47    else
48      dev_null_ = new std::ofstream("/dev/null");
49
50    if (need_test_repo) {
51      bool have_test_repo=false;
52      #ifdef HAVE_TEST_REPO
53      have_test_repo=true;
54      #endif
55      if (!have_test_repo) {
56        out() << "Skipping test because test repository is not available\n";
57        exit (77);
58      }
59      update_test_wc();
60    }
61
62  }
63
64
65  Suite::~Suite(void)
66  {
67    delete dev_null_;
68  }
69
70 
71  bool Suite::add(bool b)
72  {
73    ok_ = ok_ && b;
74    return b;
75  }
76
77
78  bool Suite::ok(void) const
79  {
80    return ok_;
81  }
82
83
84  std::ostream& Suite::out(void) const
85  {
86    if (verbose())
87      return std::cout;
88    return *dev_null_;
89  }
90
91
92  void Suite::update_test_wc(void) const
93  {
94    std::string cmd = abs_builddir()+"/svn_update.sh";
95    out() << cmd << std::endl;
96    int status = system(cmd.c_str());
97    if (status) {
98      out() << "failed with status: " << status << std::endl;
99      exit (1);
100    }
101  }
102
103
104  bool Suite::verbose(void) const
105  {
106    return verbose_;
107  }
108
109
110  std::string filename(const std::string& path)
111  {
112    return abs_builddir()+"/"+path;
113  }
114
115
116}}}
Note: See TracBrowser for help on using the repository browser.