unittests: Merge SystemTests back into SupportTests.
[oota-llvm.git] / unittests / Support / Path.cpp
1 //===- llvm/unittest/Support/Path.cpp - Path tests ------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Support/PathV2.h"
11
12 #include "gtest/gtest.h"
13
14 using namespace llvm;
15
16 namespace {
17
18 TEST(Support, Path) {
19   SmallVector<StringRef, 40> paths;
20   paths.push_back("");
21   paths.push_back(".");
22   paths.push_back("..");
23   paths.push_back("foo");
24   paths.push_back("/");
25   paths.push_back("/foo");
26   paths.push_back("foo/");
27   paths.push_back("/foo/");
28   paths.push_back("foo/bar");
29   paths.push_back("/foo/bar");
30   paths.push_back("//net");
31   paths.push_back("//net/foo");
32   paths.push_back("///foo///");
33   paths.push_back("///foo///bar");
34   paths.push_back("/.");
35   paths.push_back("./");
36   paths.push_back("/..");
37   paths.push_back("../");
38   paths.push_back("foo/.");
39   paths.push_back("foo/..");
40   paths.push_back("foo/./");
41   paths.push_back("foo/./bar");
42   paths.push_back("foo/..");
43   paths.push_back("foo/../");
44   paths.push_back("foo/../bar");
45   paths.push_back("c:");
46   paths.push_back("c:/");
47   paths.push_back("c:foo");
48   paths.push_back("c:/foo");
49   paths.push_back("c:foo/");
50   paths.push_back("c:/foo/");
51   paths.push_back("c:/foo/bar");
52   paths.push_back("prn:");
53   paths.push_back("c:\\");
54   paths.push_back("c:foo");
55   paths.push_back("c:\\foo");
56   paths.push_back("c:foo\\");
57   paths.push_back("c:\\foo\\");
58   paths.push_back("c:\\foo/");
59   paths.push_back("c:/foo\\bar");
60
61   for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(),
62                                                   e = paths.end();
63                                                   i != e;
64                                                   ++i) {
65     outs() << *i << " =>\n    Iteration: [";
66     for (sys::path::const_iterator ci = sys::path::begin(*i),
67                                    ce = sys::path::end(*i);
68                                    ci != ce;
69                                    ++ci) {
70       outs() << *ci << ',';
71     }
72     outs() << "]\n";
73
74     StringRef res;
75     SmallString<16> temp_store;
76     if (error_code ec = sys::path::root_path(*i, res)) ASSERT_FALSE(ec.message().c_str());
77     outs() << "    root_path: " << res << '\n';
78     if (error_code ec = sys::path::root_name(*i, res)) ASSERT_FALSE(ec.message().c_str());
79     outs() << "    root_name: " << res << '\n';
80     if (error_code ec = sys::path::root_directory(*i, res)) ASSERT_FALSE(ec.message().c_str());
81     outs() << "    root_directory: " << res << '\n';
82
83     temp_store = *i;
84     if (error_code ec = sys::path::make_absolute(temp_store)) ASSERT_FALSE(ec.message().c_str());
85     outs() << "    make_absolute: " << temp_store << '\n';
86
87     outs().flush();
88   }
89 }
90
91 } // anonymous namespace