Mark many merge tests as skip-against-old-server.
[svn.git] / subversion / tests / libsvn_subr / opt-test.c
bloba3931be109a4f9a77003ab3832171ef6ae36fd72
1 /*
2 * opt-test.c -- test the option functions
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 #include <string.h>
20 #include "svn_opt.h"
21 #include <apr_general.h>
23 #include "../svn_test.h"
26 static svn_error_t *
27 test_parse_peg_rev(const char **msg,
28 svn_boolean_t msg_only,
29 svn_test_opts_t *opts,
30 apr_pool_t *pool)
32 apr_size_t i;
33 static struct {
34 const char *input;
35 const char *path; /* NULL means an error is expected. */
36 svn_opt_revision_t peg;
37 } const tests[] = {
38 { "foo/bar", "foo/bar", {svn_opt_revision_unspecified} },
39 { "foo/bar@13", "foo/bar", {svn_opt_revision_number, {13}} },
40 { "foo/bar@HEAD", "foo/bar", {svn_opt_revision_head} },
41 { "foo/bar@{1999-12-31}", "foo/bar", {svn_opt_revision_date, {0}} },
42 { "http://a/b@27", "http://a/b", {svn_opt_revision_number, {27}} },
43 { "http://a/b@COMMITTED", "http://a/b", {svn_opt_revision_committed} },
44 { "foo/bar@1:2", NULL, {svn_opt_revision_unspecified} },
45 { "foo/bar@baz", NULL, {svn_opt_revision_unspecified} },
46 { "foo/bar@", "foo/bar", {svn_opt_revision_unspecified} },
47 { "foo/bar/@13", "foo/bar/", {svn_opt_revision_number, {13}} },
48 { "foo/bar@@13", "foo/bar@", {svn_opt_revision_number, {13}} },
49 { "foo/@bar@HEAD", "foo/@bar", {svn_opt_revision_head} },
50 { "foo@/bar", "foo@/bar", {svn_opt_revision_unspecified} },
51 { "foo@HEAD/bar", "foo@HEAD/bar", {svn_opt_revision_unspecified} },
54 *msg = "test svn_opt_parse_path";
55 if (msg_only)
56 return SVN_NO_ERROR;
58 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
60 const char *path;
61 svn_opt_revision_t peg;
62 svn_error_t *err;
64 err = svn_opt_parse_path(&peg, &path, tests[i].input, pool);
65 if (err)
67 svn_error_clear(err);
68 if (tests[i].path)
70 return svn_error_createf
71 (SVN_ERR_TEST_FAILED, NULL,
72 "svn_opt_parse_path ('%s') returned an error instead of '%s'",
73 tests[i].input, tests[i].path);
76 else
78 if ((path == NULL)
79 || (tests[i].path == NULL)
80 || (strcmp(path, tests[i].path) != 0)
81 || (peg.kind != tests[i].peg.kind)
82 || (peg.kind == svn_opt_revision_number && peg.value.number != tests[i].peg.value.number))
83 return svn_error_createf
84 (SVN_ERR_TEST_FAILED, NULL,
85 "svn_opt_parse_path ('%s') returned '%s' instead of '%s'", tests[i].input,
86 path ? path : "NULL", tests[i].path ? tests[i].path : "NULL");
90 return SVN_NO_ERROR;
93 static svn_error_t *
94 test_svn_opt_args_to_target_array2(const char **msg,
95 svn_boolean_t msg_only,
96 svn_test_opts_t *opts,
97 apr_pool_t *pool)
99 apr_size_t i;
100 static struct {
101 const char *input;
102 const char *output; /* NULL means an error is expected. */
103 } const tests[] = {
104 { ".", "" },
105 { ".@BASE", "@BASE" },
106 { "foo///bar", "foo/bar" },
107 { "foo///bar@13", "foo/bar@13" },
108 { "foo///bar@HEAD", "foo/bar@HEAD" },
109 { "foo///bar@{1999-12-31}", "foo/bar@{1999-12-31}" },
110 { "http://a//b////", "http://a/b" },
111 { "http://a///b@27", "http://a/b@27" },
112 { "http://a/b//@COMMITTED", "http://a/b@COMMITTED" },
113 { "foo///bar@1:2", "foo/bar@1:2" },
114 { "foo///bar@baz", "foo/bar@baz" },
115 { "foo///bar@", "foo/bar@" },
116 { "foo///bar///@13", "foo/bar@13" },
117 { "foo///bar@@13", "foo/bar@@13" },
118 { "foo///@bar@HEAD", "foo/@bar@HEAD" },
119 { "foo@///bar", "foo@/bar" },
120 { "foo@HEAD///bar", "foo@HEAD/bar" },
123 *msg = "test svn_opt_args_to_target_array2";
124 if (msg_only)
125 return SVN_NO_ERROR;
127 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
129 const char *input = tests[i].input;
130 const char *expected_output = tests[i].output;
131 apr_array_header_t *targets;
132 apr_getopt_t *os;
133 const int argc = 2;
134 const char *argv[] = { "opt-test", input, NULL };
135 apr_status_t apr_err;
136 svn_error_t *err;
138 apr_err = apr_getopt_init(&os, pool, argc, argv);
139 if (apr_err)
140 return svn_error_wrap_apr(apr_err,
141 "Error initializing command line arguments");
143 err = svn_opt_args_to_target_array2(&targets, os, NULL, pool);
145 if (expected_output)
147 const char *actual_output;
149 if (err)
150 return err;
151 if (argc - 1 != targets->nelts)
152 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
153 "Passed %d target(s) to "
154 "svn_opt_args_to_target_array2() but "
155 "got %d back.",
156 argc - 1,
157 targets->nelts);
159 actual_output = APR_ARRAY_IDX(targets, 0, const char *);
161 if (! svn_path_is_canonical(actual_output, pool))
162 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
163 "Input '%s' to "
164 "svn_opt_args_to_target_array2() should "
165 "have returned a canonical path but "
166 "'%s' is not.",
167 input,
168 actual_output);
170 if (strcmp(expected_output, actual_output) != 0)
171 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
172 "Input '%s' to "
173 "svn_opt_args_to_target_array2() should "
174 "have returned '%s' but returned '%s'.",
175 input,
176 expected_output,
177 actual_output);
179 else
181 if (! err)
182 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
183 "Unexpected success in passing '%s' "
184 "to svn_opt_args_to_target_array2().",
185 input);
189 return SVN_NO_ERROR;
193 /* The test table. */
195 struct svn_test_descriptor_t test_funcs[] =
197 SVN_TEST_NULL,
198 SVN_TEST_PASS(test_parse_peg_rev),
199 SVN_TEST_PASS(test_svn_opt_args_to_target_array2),
200 SVN_TEST_NULL