zen0wu / topcoder-greed

greedy editor for topcoder arena
Apache License 2.0
229 stars 48 forks source link

A CWD issue with regarding to filetest template #91

Open wookayin opened 10 years ago

wookayin commented 10 years ago

Well, Greed 2.0 now accepts and encourages the filetest template as a default way to run the test cases -- this is great compared to the legacy test template.

But there is a slight problem wrt the filetest template, especially for IDE users -- I thought we could discuss on it to find a great solution, if any.

The problem

Using filetest template, we read the testcase input file from the current working directory (CWD). This is slightly problematic on IDE environment, for example, Eclipse or Visual Studio.

Usually IDE users (and I) use a single workspace, solution or project to solve topcoder problems, then CWD of the running program is usually the directory where the workspace/project is located. However, the input file is located at the same directory as the source code; under this environment, the testcase input file is not found, hence no tests are run.

Well, one can customize his template and workspace settings, but as long as the template is default, this might be confusing to most users.

A solution?

I think, if possible, we could provide a great way such that wherever the testcase is located and whatever the current working directory is, the test cases from the input file could be successfully loaded.

Possibly, I am devising a way using __FILE__ macro (for C++ and python) to get the absolute path of the source code, assuming the test input and the source code are located in the same directory. But no way for Java and C#.

vexorian commented 10 years ago

I think it is up to IDE settings to determine the work folder. I remember that when I used folders, it was possible. User could also add contest folder to path environment variable.

Greed 2.0 has many facilities that can help with this, the after execution

If you'd really like to change the template files. Then the easiest solution would be to add a way to paste a template's ${GeneratedFileName} into the source code.

Longer term solution would be to include templates for popular IDEs so that they generate project files in the contest folder instead of using the same project for every problem.

zen0wu commented 10 years ago

I've never used IDE for TC contest. What's the usual best practice? For example, I use java, choosing to put the sample file in the same folder with the source is probably not a good idea. I will choose to put the sample in the src/main/resources and the source in src/main/java.

And I think we should choose more general solutions to this instead of using language specific feature. The problem lies where the way of the source hooks to the sample file name is pretty awkward. This can be worked out if we come out with a better hooking solution, like mixed in the design of the template dependency system.

vexorian commented 10 years ago

A possible hacky workaround would be to add a sampleFilePath template option to file test. Then filetest opens "${sampleFilePath}${Problem.Name}.sample".

zen0wu commented 10 years ago

Yes, this is a possible solution. What I was thinking is that, if we have dependency tracking system, we can bind things like OutputFileFullPath to the template, and if filetest can access the properties of its dependent templates, this problem is solved. But this is surely more complicated.

zen0wu commented 10 years ago

I just surveyed, this is possible in Java, using the following code

  URL path = ClassName.class.getResource("ClassName.class");
  File d = new File(path.getPath()).getParentFile();

Still not sure how to do this in C#, but I'm pretty confident it's possible.

Also, I've implemented the template dependency and the access of dependent templates' properties while rendering, which can change the hard-coded file name like ${Problem.Name}.sample to ${Dependencies.filetest.GeneratedFileName}.

The prefix part of path must be implemented using language specific tricks I guess, the solution @vexorian came up with (binding the absolute sampleFilePath) is not portable, when I want to migrate my code, and using relative path is such a pain in the ass. So I guess if all the languages can get the path of its current running file, that's the way we should go with. Just define the behaviour of the filetest template as finding the sample file in the same folder, if user want something different, they have to do some configurations.

PS: This is the last feature I'm currently planning on 2.0, will be a RC later. And new features will be added to later versions.

zen0wu commented 10 years ago

I was wrong. This is still not possible in Java, you can only get the path of the classfile, not the source file. It seems we are only left with the awkward relative path solution, or ignore C# and java for this feature.