This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 47474 - [40cat] user.dir differs between running project and running tests
Summary: [40cat] user.dir differs between running project and running tests
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 4.x
Hardware: PC Windows XP
: P4 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on: 111163
Blocks: 41537
  Show dependency tree
 
Reported: 2004-08-19 13:50 UTC by dynamite
Modified: 2007-09-07 17:21 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dynamite 2004-08-19 13:50:27 UTC
[ BUILD # : 200408171800 ]
[ JDK VERSION : J2SE 1.5.0 ]

When running a project user.dir is set to the project directory, which seems sensible enough. However, when running tests it is set to netbeans bin directory which seems much less useful.

Should user.dir not be the project directory when running tests as well as the project app?
Comment 1 Jesse Glick 2004-08-19 17:52:18 UTC
Purely accidental that the CWD is set to the project dir in the case
of running the project; seems that Ant's <java> defaults the 'dir'
attr to ${basedir} (certainly not intentional on our part), and I
guess <junit> does not. Could be made to for consistency.

Anyway your program should probably not rely on the current working
directory, and your tests definitely should not. If you need to pass
some file paths to your tests, do so explicitly. I will add the
ability to put in your project.properties e.g.

test-sys-prop.sample.files=${basedir}/test-samples

which you could then use inside a unit test via

new File(System.getProperty("sample.files"))
Comment 2 dynamite 2004-08-20 09:04:54 UTC
In my particular case, the test is creating a file which then gets
used and finally tidied up. I just needed some safe place to put it.
Comment 3 Jesse Glick 2004-08-20 17:37:59 UTC
Right, common case. Pass in a scratch directory as a system property
(e.g. "${basedir}/build/test/work"). Or use java.io.File's facility
for making temporary files (set to delete on exit, for example, or
delete in tearDown).
Comment 4 Jesse Glick 2004-08-20 20:48:05 UTC
committed   * Up-To-Date  1.13       
java/j2seproject/src/org/netbeans/modules/java/j2seproject/Bundle.properties
committed   * Up-To-Date  1.24       
java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java
committed   * Up-To-Date  1.30       
java/j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl
Comment 5 David Konecny 2004-08-26 16:29:57 UTC
FYI: see issue 43194: the working directory is configurable now in
project UI in Running Project panel.
Comment 6 Jesse Glick 2004-08-27 03:07:12 UTC
*But* I asked for that to be reverted in the case of unit tests, so
that they are always run with cwd set to the project basedir, for
safety. (As mentioned here, you can pass useful paths to them using
test-sys-prop.* Ant properties.)