Author: stsp Date: Thu Jun 19 10:28:45 2014 New Revision: 1603816 URL: http://svn.apache.org/r1603816 Log: Fix fallout from r1537147 and other revision which involved changes to the way the --srcdir option is handled in the C tests.
Originally, this option was used only by config-test.c and was required, ie. the test failed if the option wasn't given (i.e. opt.srcdir == NULL). Since r1537147 these tests would crash if no --srcdir option was given. Some tests in checksum-test.c and repos-test.c have since started using the value of --srcdir, also without checking for NULL. Add a new helper function svn_test_get_srcdir() for these tests, which falls back to the current working directory if --srcdir isn't given. This allows tests to pass if invoked from within their directory: cd subversion/tests/libsvn_subr && ./config-test The test runner has always been passing --srcdir to C tests, so the standard 'make check' procedure wasn't affected by this problem. * subversion/tests/libsvn_repos/repos-test.c (test_config_pool): Use svn_test_get_srcdir(). * subversion/tests/libsvn_subr/checksum-test.c (zlib_expansion_test): Use svn_test_get_srcdir(). * subversion/tests/libsvn_subr/config-test.c (get_config_file_path): New helper function which uses svn_test_get_srcdir() to build the test configuration file's path. (test_text_retrieval, test_boolean_retrieval, test_has_section_case_insensitive, test_has_section_case_sensitive, test_has_option_case_sensitive, test_stream_interface, test_read_only_mode): Use get_config_file_path(). * subversion/tests/svn_test.h (svn_test_get_srcdir): Declare. * subversion/tests/svn_test_main.c (svn_test_get_srcdir): New helper function to obtain the value of the --srcdir option. Modified: subversion/trunk/subversion/tests/libsvn_repos/repos-test.c subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c subversion/trunk/subversion/tests/libsvn_subr/config-test.c subversion/trunk/subversion/tests/svn_test.h subversion/trunk/subversion/tests/svn_test_main.c Modified: subversion/trunk/subversion/tests/libsvn_repos/repos-test.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_repos/repos-test.c?rev=1603816&r1=1603815&r2=1603816&view=diff ============================================================================== --- subversion/trunk/subversion/tests/libsvn_repos/repos-test.c (original) +++ subversion/trunk/subversion/tests/libsvn_repos/repos-test.c Thu Jun 19 10:28:45 2014 @@ -3331,6 +3331,7 @@ test_config_pool(const svn_test_opts_t * svn_fs_root_t *root, *rev_root; svn_revnum_t rev; const char *repo_root_url; + const char *srcdir; svn_error_t *err; svn_repos__config_pool_t *config_pool; @@ -3348,9 +3349,10 @@ test_config_pool(const svn_test_opts_t * config_pool_pool)); /* have two different configurations */ + SVN_ERR(svn_test_get_srcdir(&srcdir, opts, pool)); SVN_ERR(svn_stringbuf_from_file2( &cfg_buffer1, - svn_dirent_join(opts->srcdir, + svn_dirent_join(srcdir, "../libsvn_subr/config-test.cfg", pool), pool)); Modified: subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c?rev=1603816&r1=1603815&r2=1603816&view=diff ============================================================================== --- subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c (original) +++ subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c Thu Jun 19 10:28:45 2014 @@ -208,12 +208,14 @@ zlib_expansion_test(const svn_test_opts_ apr_pool_t *pool) { const char *data_path; + const char *srcdir; svn_stringbuf_t *deflated; Byte dst_buffer[256 * 1024]; Byte *src_buffer; uInt sz; - data_path = svn_dirent_join(opts->srcdir, "zlib.deflated", pool); + SVN_ERR(svn_test_get_srcdir(&srcdir, opts, pool)); + data_path = svn_dirent_join(srcdir, "zlib.deflated", pool); SVN_ERR(svn_stringbuf_from_file2(&deflated, data_path, pool)); src_buffer = (Byte*)deflated->data; Modified: subversion/trunk/subversion/tests/libsvn_subr/config-test.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/config-test.c?rev=1603816&r1=1603815&r2=1603816&view=diff ============================================================================== --- subversion/trunk/subversion/tests/libsvn_subr/config-test.c (original) +++ subversion/trunk/subversion/tests/libsvn_subr/config-test.c Thu Jun 19 10:28:45 2014 @@ -55,6 +55,18 @@ fail(apr_pool_t *pool, const char *fmt, return svn_error_create(SVN_ERR_TEST_FAILED, SVN_NO_ERROR, msg); } +static svn_error_t * +get_config_file_path(const char **cfg_file, + const svn_test_opts_t *opts, + apr_pool_t *pool) +{ + const char *srcdir; + + SVN_ERR(svn_test_get_srcdir(&srcdir, opts, pool)); + *cfg_file = svn_dirent_join(srcdir, "config-test.cfg", pool); + + return SVN_NO_ERROR; +} static const char *config_keys[] = { "foo", "a", "b", "c", "d", "e", "f", "g", "h", "i", NULL }; @@ -72,7 +84,7 @@ test_text_retrieval(const svn_test_opts_ int i; const char *cfg_file; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); /* Test values retrieved from our ConfigParser instance against @@ -121,7 +133,7 @@ test_boolean_retrieval(const svn_test_op int i; const char *cfg_file; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); for (i = 0; true_keys[i] != NULL; i++) @@ -179,7 +191,7 @@ test_has_section_case_insensitive(const svn_config_t *cfg; const char *cfg_file; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); if (! svn_config_has_section(cfg, "section1")) @@ -207,7 +219,7 @@ test_has_section_case_sensitive(const sv svn_config_t *cfg; const char *cfg_file; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); if (! svn_config_has_section(cfg, "section1")) @@ -248,7 +260,7 @@ test_has_option_case_sensitive(const svn }; static const int test_data_size = sizeof(test_data)/sizeof(*test_data); - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, TRUE, pool)); for (i = 0; i < test_data_size; ++i) @@ -276,7 +288,7 @@ test_stream_interface(const svn_test_opt const char *cfg_file; svn_stream_t *stream; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_stream_open_readonly(&stream, cfg_file, pool, pool)); SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); @@ -314,7 +326,7 @@ test_read_only_mode(const svn_test_opts_ svn_config_t *cfg2; const char *cfg_file; - cfg_file = svn_dirent_join(opts->srcdir, "config-test.cfg", pool); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); /* setting CFG to r/o mode shall toggle the r/o mode and expand values */ Modified: subversion/trunk/subversion/tests/svn_test.h URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test.h?rev=1603816&r1=1603815&r2=1603816&view=diff ============================================================================== --- subversion/trunk/subversion/tests/svn_test.h (original) +++ subversion/trunk/subversion/tests/svn_test.h Thu Jun 19 10:28:45 2014 @@ -244,6 +244,14 @@ const char * svn_test_data_path(const char* basename, apr_pool_t *result_pool); +/* Some tests require the --srcdir option and should use this function + * to get it. If not provided, print a warning and attempt to run the + * tests under the assumption that --srcdir is the current directory. */ +svn_error_t * +svn_test_get_srcdir(const char **srcdir, + const svn_test_opts_t *opts, + apr_pool_t *pool); + #ifdef __cplusplus } #endif /* __cplusplus */ Modified: subversion/trunk/subversion/tests/svn_test_main.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test_main.c?rev=1603816&r1=1603815&r2=1603816&view=diff ============================================================================== --- subversion/trunk/subversion/tests/svn_test_main.c (original) +++ subversion/trunk/subversion/tests/svn_test_main.c Thu Jun 19 10:28:45 2014 @@ -664,6 +664,26 @@ svn_test_data_path(const char *base_name return svn_dirent_join(data_path, base_name, result_pool); } +svn_error_t * +svn_test_get_srcdir(const char **srcdir, + const svn_test_opts_t *opts, + apr_pool_t *pool) +{ + const char *cwd; + + if (opts->srcdir) + { + *srcdir = opts->srcdir; + return SVN_NO_ERROR; + } + + fprintf(stderr, "WARNING: missing '--srcdir' option"); + SVN_ERR(svn_dirent_get_absolute(&cwd, ".", pool)); + fprintf(stderr, ", assuming '%s'\n", cwd); + *srcdir = cwd; + + return SVN_NO_ERROR; +} /* Standard svn test program */ int