This fixes https://llvm.org/PR45307.
Lets not start writing tests like this.
It breaks with the fundamental design goal of the test suite:
- c++ test.pass.cpp should be enough to compile most tests.
- ./a.out should be enough to run it.
Please add these tests to std/input.output/filesystems//fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp.
I don't necessarily agree.
First, no implementation currently has the behavior you describe.
Both libstdc++ and Boost filesystem return the environment variable as specified.
Also, on OS X, the TEMPDIR variable includes the trailing slash. If that's what the operating system does, why should we differ?
I also think there are some subtle differences in pathname resolution. Specifically around symlinks and when the basename doesn't exist.
For example, let's assume TEMPDIR is /this-directory-does-not-exist/. touch foo; cp foo $TEMPDIR fails because there is no such directory. Without the trailing slash it succeeds and copies foo to a new file called this-directory-does-not-exist.
In general trailing slashes are used to denote that the entity is a directory. I don't see a strong reason to differ.
But if you disagree, I'm willing to proceed with your fix, on the condition that you file a LWG issue about this proposing this behavior as standard.
First, this test would be a non-standard extension, so it needs to stay in libcxx/test/libcxx, not libcxx/test/std. And regarding using a .sh.cpp instead of a .pass.cpp, the only reason is that I wanted to avoid using ::setenv, which is not standard. But if we're fine with using ::setenv, then I agree a .pass.cpp is a lot simpler.
I replied on the bug report. I think I agree with you but I'd like to clarify a few things. Let's have the discussion on Bugzilla and I'll update this thread with the result of the discussion.