Changeset 744


Ignore:
Timestamp:
Jan 8, 2009, 11:37:12 PM (12 years ago)
Author:
Peter Johansson
Message:

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.

Location:
trunk
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        88autom4te.cache
        99INSTALL
        10 COPYING
        1110aclocal.m4
        1211Makefile
  • trunk/configure.ac

    r743 r744  
    1313# Copyright (C) 2006 Jari Häkkinen
    1414# Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     15# Copyright (C) 2009 Peter Johansson
    1516#
    1617# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    170171# checking if we have test repo
    171172test_repo_filename=$srcdir/test/repo;
    172 AC_CHECK_FILE([$test_repo_filename], [test_repo_found="yes"],
     173AC_CHECK_FILE([$test_repo_filename],
     174              [AC_DEFINE([HAVE_TEST_REPO],[1],[define if test repo is available])
     175               test_repo_found="yes"],
    173176              [test_repo_found="no"])
    174 AM_CONDITIONAL([HAVE_TEST_REPO], [test "$test_repo_found" = "yes"])
    175177if (test "$test_repo_found" = "yes"); then
    176178   dnl test repo is not distributed
    177179   AC_CONFIG_FILES([test/test_repo.sh], [chmod +x test/test_repo.sh])
     180   AC_CONFIG_FILES([test/svn_update.sh], [chmod +x test/svn_update.sh])
    178181   AC_CONFIG_FILES([test/check_repo_status.sh],
    179182                   [chmod +x test/check_repo_status.sh])   
  • trunk/test/Makefile.am

    r738 r744  
    44
    55# Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     6# Copyright (C) 2009 Peter Johansson
    67#
    78# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2021# along with svndigest. If not, see <http://www.gnu.org/licenses/>.
    2122
    22 check_PROGRAMS = config_test date_test gnuplot_pipe_test \
    23   parser_test trac_test utility_test
     23check_SCRIPTS = svn_update.sh
    2424
    25 # these tests are only for developers since we do not distribute test repository
    26 if HAVE_TEST_REPO
    27 check_PROGRAMS += copyright_test stats_test
    28 endif
     25check_PROGRAMS = config_test copyright_test date_test gnuplot_pipe_test \
     26  parser_test stats_test trac_test utility_test
    2927
    30 TESTS = $(check_PROGRAMS)
    31 # these tests are only for developers since we do not distribute test repository
    32 if HAVE_TEST_REPO
    33 TESTS += test_repo.sh
    34 endif
    35 TESTS += check_repo_status.sh
     28TESTS = $(check_PROGRAMS) test_repo.sh check_repo_status.sh
    3629
    3730# tests not yet passing are listed here
     
    6255utility_test_SOURCES = utility_test.cc
    6356
    64 toy_project = toy_project
    65 rootdir = $(abs_srcdir)/$(toy_project)
    66 targetdir = $(abs_builddir)/generated_output
     57clean-local:
     58  rm -rf generated_output toy_project
    6759
    68 # some tests need the test repo to be checked out
    69 stats_test_DEPENDENCIES = $(toy_project) $(top_builddir)/lib/libsvndigest.a
    70 copyright_test_DEPENDENCIES = $(toy_project) $(top_builddir)/lib/libsvndigest.a
    71 
    72 $(toy_project):
    73   echo Checking out test repository && \
    74   repo=`cd $(abs_srcdir)/repo && pwd` && \
    75   svn checkout file://$$repo/trunk $(toy_project);
    76 
    77 clean-local:
    78   rm -rf *.png *.tmp *~ $(targetdir)
     60mostlyclean-local:
     61  rm -f *.png *.tmp *~
  • trunk/test/Suite.cc

    r737 r744  
    22
    33/*
    4   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2008, 2009 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2020*/
    2121
     22#include <config.h>
     23
    2224#include "Suite.h"
    2325#include "environment.h"
    2426
     27#include "utility.h"
     28
     29#include <cassert>
     30#include <fstream>
     31#include <iostream>
    2532#include <string>
    2633
     
    2835namespace svndigest {
    2936namespace 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
    30109
    31110  std::string filename(const std::string& path)
  • trunk/test/Suite.h

    r693 r744  
    55
    66/*
    7   Copyright (C) 2008 Peter Johansson
     7  Copyright (C) 2008, 2009 Peter Johansson
    88
    99  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3131namespace test {
    3232
     33  class Suite
     34  {
     35  public:
     36    Suite(int argc, char* argv[], bool need_test_repo=false);
     37    ~Suite(void);
     38
     39    /**
     40       If b is false, set ok to false
     41
     42       \return b
     43    */
     44    bool add(bool b);
     45
     46    /**
     47       \return true if all tests are OK
     48     */
     49    bool ok(void) const;
     50
     51    std::ostream& out(void) const;
     52
     53    /**
     54       \return true if we are running in verbose mode
     55     */
     56    bool verbose(void) const;
     57
     58  private:
     59    std::ofstream* dev_null_;
     60    bool ok_;
     61    bool verbose_;
     62
     63    void checkout_test_wc(void) const;
     64    void update_test_wc(void) const;
     65  };
     66
    3367  /**
    3468     \return absolute path to file
  • trunk/test/copyright_test.cc

    r693 r744  
    22
    33/*
    4   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2008, 2009 Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3939{
    4040  using namespace theplu::svndigest;
    41   bool verbose=false;
    42   bool ok=true;
    43   if (argc>1 && argv[1]==std::string("-v") )
    44     verbose=true;
     41  test::Suite suite(argc, argv, true);
    4542
    4643  std::string root=test::filename("toy_project");
     
    6158
    6259  if (copyrights_old.size()!=1) {
    63     if (verbose){
    64       std::cout << copyrights_old.size() << " Copyright lines\n";
    65       for (size_t i=0; i<copyrights_old.size(); ++i)
    66         std::cout << copyrights_old[i] << "\n";
    67     }
    68     ok = false;
     60    suite.out() << copyrights_old.size() << " Copyright lines\n";
     61    for (size_t i=0; i<copyrights_old.size(); ++i)
     62      suite.out() << copyrights_old[i] << "\n";
     63    suite.add(false);
    6964  }
    70   else if (verbose)
    71     std::cout << "File contains 1 copyright line.\n";
     65  suite.out() << "File contains 1 copyright line.\n";
    7266
    7367  // warn about missing Copyright statement only in verbose mode
    74   if (verbose){
     68  if (suite.verbose()){
    7569    std::string config_str("[copyright]\nmissing-copyright-warning=yes");
    7670    std::stringstream ss(config_str);
     
    7973  }
    8074
    81   if (verbose)
    82     std::cout << "Create SVN instance" << std::endl;
     75  suite.out() << "Create SVN instance" << std::endl;
    8376  SVN* svn=SVN::instance(root);
    8477  if (!svn)
     
    8679
    8780  // Extract repository location
    88   if (verbose)
    89     std::cout << "Extract repository location" << std::endl;
     81  suite.out() << "Extract repository location" << std::endl;
    9082  std::string repo=SVNinfo(root).repos_root_url();
    91   if (verbose)
    92     std::cout << "Create File object" << std::endl;
     83  suite.out() << "Create File object" << std::endl;
    9384  File file(0,filename,"");
    9485 
    95   if (verbose)
    96     std::cout << "Get stats for file" << std::endl;
    97   file.parse(verbose, true);
     86  suite.out() << "Get stats for file" << std::endl;
     87  file.parse(suite.verbose(), true);
    9888 
    99   if (verbose)
    100     std::cout << "Updating copyright statements" << std::endl;
     89  suite.out() << "Updating copyright statements" << std::endl;
    10190  std::map<std::string, Alias> alias;
    10291  alias["jari"]=Alias("jh", 1);
    10392  alias["peter"]=Alias("pj", 2);
    10493 
    105   file.print_copyright(alias, verbose);
     94  file.print_copyright(alias, suite.verbose());
    10695
    10796  is.open(filename.c_str());
     
    114103  copyright_correct.push_back("Copyright (C) 2007, 2008 pj");
    115104  if (copyrights.size()!=copyright_correct.size()) {
    116     ok = false;
    117     if (verbose)
    118       std::cout << "ERROR: expected " << copyright_correct.size()
     105    suite.add(false);
     106    suite.out() << "ERROR: expected " << copyright_correct.size()
    119107                << " lines of Copyright (C)\n"
    120108                << "But found " << copyrights.size() << " lines.\n";
     
    123111    for (size_t i=0; i<copyrights.size(); ++i)
    124112      if (copyrights[i]!=copyright_correct[i]){
    125         ok=false;
    126         if (verbose)
    127           std::cerr << "ERROR: found '" << copyrights[i] << "'\n"
     113        suite.add(false);
     114        suite.out() << "ERROR: found '" << copyrights[i] << "'\n"
    128115                    << "expected: '" << copyright_correct[i] << "'\n";
    129116      }
     
    138125  os.close();
    139126
    140   if (ok) {
    141     if (verbose)
    142       std::cout << "Test is Ok!" << std::endl;
     127  if (suite.ok()) {
     128    suite.out() << "Test is Ok!" << std::endl;
    143129    return 0;
    144130  }
    145   if (verbose)
    146     std::cout << "Test failed." << std::endl;
     131  suite.out() << "Test failed." << std::endl;
    147132  return 1;
    148133}
  • trunk/test/stats_test.cc

    r727 r744  
    33/*
    44  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    56
    67  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    5758{
    5859  using namespace theplu::svndigest;
    59   bool verbose=false;
     60  test::Suite suite(argc, argv, true);
     61
     62  bool verbose=suite.verbose();
    6063  bool ok=true;
    61   if (argc>1 && argv[1]==std::string("-v") )
    62     verbose=true;
     64
    6365  SVN* svn=SVN::instance(test::filename("toy_project"));
    6466  if (!svn){
  • trunk/test/svn_update.sh.in

    r736 r744  
    44# $Id$
    55
    6 # Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    7 # Copyright (C) 2008 Peter Johansson
     6# Copyright (C) 2009 Peter Johansson
    87#
    98# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2322
    2423rootdir=@abs_builddir@/toy_project
    25 targetdir=@abs_builddir@/generated_output
    26 repodir=@abs_srcdir@/repo/trunk
     24
     25if test ! -e $rootdir; then
     26    repo="@abs_srcdir@/repo";
     27    svn co file://$repo/trunk $rootdir > /dev/null;
     28fi
    2729
    2830svn update $rootdir > /dev/null;
    29 
    30 if [ ! -d $targetdir ]; then
    31     mkdir $targetdir;
    32 fi
    33 
    34 @abs_top_builddir@/bin/svndigest -r $rootdir -t $targetdir \
    35 --ignore-cache --no-report $1;
    36 
    37 @abs_top_builddir@/bin/svndigest -r $rootdir -t $targetdir -f $1;
    38 
  • trunk/test/test_repo.sh.in

    r736 r744  
    55
    66# Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    7 # Copyright (C) 2008 Peter Johansson
     7# Copyright (C) 2008, 2009 Peter Johansson
    88#
    99# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2424rootdir=@abs_builddir@/toy_project
    2525targetdir=@abs_builddir@/generated_output
    26 repodir=@abs_srcdir@/repo/trunk
    2726
    28 svn update $rootdir > /dev/null;
     27test_repo_found="@test_repo_found@"
     28if test $test_repo_found = "no"; then
     29    exit 77;
     30fi
     31
     32cd @abs_builddir@ && @SHELL@ svn_update.sh;
    2933
    3034if [ ! -d $targetdir ]; then
Note: See TracChangeset for help on using the changeset viewer.