Avoid "text file busy" in dw2-using-debug-str.exp
[binutils-gdb.git] / gdb / unittests / path-join-selftests.c
blob08fad63341d82ad392c2283e603612b51b19d704
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"
23 namespace selftests {
24 namespace path_join {
26 template <typename ...Args>
27 static void
28 test_one (const char *expected, Args... paths)
30 std::string actual = ::path_join (paths...);
32 SELF_CHECK (actual == expected);
35 /* Test path_join. */
37 static void
38 test ()
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");
51 #if defined(_WIN32)
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");
60 #endif /* _WIN32 */
66 void _initialize_path_join_selftests ();
67 void
68 _initialize_path_join_selftests ()
70 selftests::register_test ("path_join",
71 selftests::path_join::test);