1 /* Self tests for path_join for GDB, the GNU debugger.
3 Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/pathstuff.h"
21 #include "gdbsupport/selftest.h"
26 template <typename
...Args
>
28 test_one (const char *expected
, Args
... paths
)
30 std::string actual
= ::path_join (paths
...);
32 SELF_CHECK (actual
== expected
);
40 test_one ("/foo/bar", "/foo", "bar");
41 test_one ("/bar", "/", "bar");
42 test_one ("foo/bar/", "foo", "bar", "");
43 test_one ("foo", "", "foo");
44 test_one ("foo/bar", "foo", "", "bar");
45 test_one ("foo/", "foo", "");
46 test_one ("foo/", "foo/", "");
48 test_one ("D:/foo/bar", "D:/foo", "bar");
49 test_one ("D:/foo/bar", "D:/foo/", "bar");
52 /* The current implementation doesn't recognize backslashes as directory
53 separators on Unix-like systems, so only run these tests on Windows. If
54 we ever switch our implementation to use std::filesystem::path, they
55 should work anywhere, in theory. */
56 test_one ("D:\\foo/bar", "D:\\foo", "bar");
57 test_one ("D:\\foo\\bar", "D:\\foo\\", "bar");
58 test_one ("\\\\server\\dir\\file", "\\\\server\\dir\\", "file");
59 test_one ("\\\\server\\dir/file", "\\\\server\\dir", "file");
66 void _initialize_path_join_selftests ();
68 _initialize_path_join_selftests ()
70 selftests::register_test ("path_join",
71 selftests::path_join::test
);