diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index 48378924..1afc98ab 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -852,10 +852,11 @@ namespace { // directories (see ROOT-7114). By asking for $PWD (and not ".") it will // be registered as $PWD instead, which is stable even after chdirs. char cwdbuf[2048]; - const clang::DirectoryEntry* DE - = FM.getDirectory(getcwd_func(cwdbuf, sizeof(cwdbuf))); - (void)DE; - assert(!strcmp(DE->getName(), cwdbuf) && "Unexpected name for $PWD"); + if (!getcwd_func(cwdbuf, sizeof(cwdbuf))) { + // getcwd can fail, but that shouldn't mean we have to. + ::perror("Could not get current working directory"); + } else + FM.getDirectory(cwdbuf); // Build the virtual file, Give it a name that's likely not to ever // be #included (so we won't get a clash in clangs cache). diff --git a/test/Driver/CurrentDir.C b/test/Driver/CurrentDir.C index d59b7eb0..11b19d7e 100644 --- a/test/Driver/CurrentDir.C +++ b/test/Driver/CurrentDir.C @@ -9,22 +9,32 @@ // Test runing a file in the same directory `cling CurrentDir.C` // More info in CIFactory.cpp createCIImpl (line ~850) -// RUN: cd %S && %cling -Xclang -verify CurrentDir.C | FileCheck %s -// Test CurrentDir +// RUN: cd %S && %cling -Xclang -verify CurrentDir.C 2>&1 | FileCheck %s +// RUN: mkdir %T/Remove && cd %T/Remove && rm -rf %T/Remove && %cling -DTEST_CWDRETURN %s -Xclang -verify 2>&1 | FileCheck --check-prefix CHECK --check-prefix CHECKcwd %s +// Test testCurrentDir extern "C" { int printf(const char*, ...); char* getcwd(char *buf, std::size_t size); } +#ifdef TEST_CWDRETURN + // Make sure include still works + #include + #include +#endif + void CurrentDir() { - char thisDir[1024]; - getcwd(thisDir, sizeof(thisDir)); - /* - This would be nice, but doesn't work - printf("We are here: %s\n", thisDir); - -CHECK: We are here: %S - */ + #ifdef TEST_CWDRETURN + char thisDir[1024]; + const char *rslt = getcwd(thisDir, sizeof(thisDir)); + // Make sure cling reported the error + // CHECKcwd: Could not get current working directory: {{.*}} + + if (rslt) + printf("Working directory exists\n"); + // CHECK-NOT: Working directory exists + #endif printf("Script ran\n"); // CHECK: Script ran