LEFT | RIGHT |
1 #include "file-path.hh" | 1 #include "file-path.hh" |
| 2 #include "file-name.hh" |
2 | 3 |
3 #include <limits.h> | 4 #include <limits.h> |
4 #include <unistd.h> | 5 #include <unistd.h> |
5 | 6 |
6 #include "yaffut.hh" | 7 #include "yaffut.hh" |
7 #include "config.hh" | 8 #include "config.hh" |
8 | |
9 string | |
10 get_working_directory () | |
11 { | |
12 #ifdef _GNU_SOURCE | |
13 char *cwd = get_current_dir_name(); | |
14 string scwd(cwd); | |
15 free(cwd); | |
16 return scwd; | |
17 #else | |
18 char cwd[PATH_MAX]; | |
19 // getcwd returns NULL upon a failure, contents of cwd would be undefined! | |
20 return string (getcwd (cwd, PATH_MAX)); | |
21 #endif | |
22 } | |
23 | 9 |
24 TEST (File_path, Find) | 10 TEST (File_path, Find) |
25 { | 11 { |
26 char const *extensions[] = {"ly", "", 0}; | 12 char const *extensions[] = {"ly", "", 0}; |
27 string file = "init"; | 13 string file = "init"; |
28 if (get_working_directory().empty()) | 14 if (get_working_directory().empty()) |
29 { | 15 { |
30 cerr << "Could not get current work directory\n"; | 16 cerr << "Could not get current work directory\n"; |
31 exit (1); | 17 exit (1); |
32 } | 18 } |
33 string ly_dir = string (getenv ("top-src-dir")) + "/ly"; | 19 string ly_dir = string (getenv ("top-src-dir")) + "/ly"; |
34 parse_path (string (1, PATHSEP) + ly_dir); | 20 parse_path (string (1, PATHSEP) + ly_dir); |
35 string file_name = find (file, extensions); | 21 string file_name = find (file, extensions); |
36 EQUAL (file_name.substr (file_name.rfind ('/')), "/init.ly"); | 22 EQUAL (file_name.substr (file_name.rfind ('/')), "/init.ly"); |
37 file = "init.ly"; | 23 file = "init.ly"; |
38 file_name = find (file, extensions); | 24 file_name = find (file, extensions); |
39 EQUAL (file_name, ly_dir + "/init.ly"); | 25 EQUAL (file_name, ly_dir + "/init.ly"); |
40 } | 26 } |
LEFT | RIGHT |