Index: subversion/tests/clients/cmdline/date_tests.py =================================================================== --- subversion/tests/clients/cmdline/date_tests.py (revision 0) +++ subversion/tests/clients/cmdline/date_tests.py (revision 0) @@ -0,0 +1,176 @@ +#!/usr/bin/env python +# +# date_tests.py: testing date cases. +# +# Subversion is a tool for revision control. +# See http://subversion.tigris.org for more information. +# +# ==================================================================== +# Copyright (c) 2000-2004 CollabNet. All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://subversion.tigris.org/license-1.html. +# If newer versions of this license are posted there, you may use a +# newer version instead, at your option. +# +###################################################################### + +# General modules +import os, time + +# Our testing module +import svntest + +# (abbreviation) +Skip = svntest.testcase.Skip +XFail = svntest.testcase.XFail +Item = svntest.wc.StateItem + +#---------------------------------------------------------------------- +# Is Subversion A Day Early? Yes, so modify test time accordingly. + +t = list(time.localtime()) +t[2] += 2 #day +t[3] += 2 #hour +t = tuple(t) + +time_array = [ + time.strftime('%Y-%m-%d', t), + time.strftime('%H:%M', t), + time.strftime('%Y-%m-%d %H:%M', t), + time.strftime("%H:%M:%S", t)+'.000000', + time.strftime('%Y%m%dT%H%M', t), + time.strftime('%Y%m%dT%H%M%z', t), + time.strftime('%Y-%m-%dT%H:%M%z', t), + time.strftime('%Y-%m-%d %H:%M %z', t), + time.strftime('%Y-%m-%dT%H:%M', t), + time.strftime('%Y-%m-%d %H:%M', t), + ] + +###################################################################### +# Tests +# +# Each test must return on success or raise on failure. + +#---------------------------------------------------------------------- + +#---------------------------------------------------------------------- +# Test log with date option. +def log_with_date_option(sbox): + "get log with -r {date}" + sbox.build() + + wc_dir = sbox.wc_dir + + mu_path = os.path.join(wc_dir, 'A', 'mu') + + for i in range(0, len(time_array)): + out, err = svntest.main.run_svn(1, 'log', mu_path, '-r', + '{' + str(time_array[i]) + '}' + ) + if not(err == [] and out[3] == 'Log message for revision 1.\n'): + raise svntest.Failure + +#---------------------------------------------------------------------- +# The output of GNU date was not being accepted by svn commands +# Test the fix. +def cat_with_date_option(sbox): + "use GNU date command in revision input" + sbox.build() + + wc_dir = sbox.wc_dir + + mu_path = os.path.join(wc_dir, 'A', 'mu') + + # The Success Case: output and no errors. + arg = os.popen("date --iso-8601=seconds -d '+2 hours'").readline() + svntest.actions.run_and_verify_svn('cat a file using GNU date', + ["This is the file 'mu'."], None, + 'cat', '-r', '{' + + str(arg).strip('\n') + '}', mu_path) + + # The Failure Case: no output and some errors. + arg = os.popen("date --iso-8601=seconds -d '-2 hours'").readline() + svntest.actions.run_and_verify_svn('cat a file using GNU date', + [], svntest.SVNAnyOutput, 'cat', '-r', + '{' + str(arg).strip('\n') + '}', + mu_path) + +#---------------------------------------------------------------------- +# Date is stored as an unversiond property in the reop. If we try +# to meddle with it, we may land in trouble. Here is a test. +def cat_with_date_prop_modified(sbox): + "change the date property" + + sbox.build() + mu_path = os.path.join(sbox.wc_dir, 'A', 'mu') + + # Create the revprop-change hook + if os.name == 'posix': + hook = os.path.join(svntest.main.current_repo_dir, 'hooks', + 'pre-revprop-change') + svntest.main.file_append(hook, "#!/bin/sh\n\nexit 0\n") + os.chmod(hook, 0755) + elif sys.platform == 'win32': + hook = os.path.join(svntest.main.current_repo_dir, + 'hooks', 'pre-revprop-change.bat') + svntest.main.file_append(hook, "@exit 0\n") + + # Test: everything ok? + arg = time.strftime('%Y-%m-%d %H:%M', t) + svntest.actions.run_and_verify_svn('Cat a file with svn:date property set', + ["This is the file 'mu'."], [], + 'cat', '-r', + '{' + str(arg) + '}', mu_path) + + # Set: property svn:date with a bogus date + out = ["property 'svn:date' set on repository revision 1\n"] + svntest.actions.run_and_verify_svn(None, out, [], 'propset', + "--revprop", "-r", '1', + '-R', 'svn:date', + time.strftime('%Y-%m-%dT%H:%M:%S'), + sbox.wc_dir) + + e_out, err = svntest.main.run_svn (1, 'cat', '-r', + '{' + str(arg) + '}', mu_path) + if err.pop() != 'svn: Bogus date\n': + raise svntest.Failure + + # We did a mistake in setting up the date. + # Can we reset it? Format is in libsvn_subr/time.c + svntest.actions.run_and_verify_svn(None, out, [], + 'propset', "--revprop", "-r", '1', + '-R', 'svn:date', + time.strftime('%Y-%m-%dT%H:%M:%S') + + '.000000Z', + sbox.wc_dir) + + # Yes, we can! + svntest.actions.run_and_verify_svn('Cat a file with svn:date property set', + ["This is the file 'mu'."], [], + 'cat', '-r', + '{' + str(arg) + '}', mu_path) + + +######################################################################## +# Run the tests + + +# list all tests here, starting with None: + +test_list = [ None, + log_with_date_option, + Skip(cat_with_date_option, os.name == 'win32'), + # If we learn how to write a pre-revprop-change hook for + # non-Posix platforms, we won't have to skip here: + Skip(cat_with_date_prop_modified, + (os.name != 'posix' and sys.platform != 'win32')), + ] + +if __name__ == '__main__': + svntest.main.run_tests(test_list) + # NOTREACHED + + +### End of file.