Analyzing source code

Analyzing source code

de către Ian Warren-
Număr de răspunsuri: 2

Hi Richard,

I have been experimenting with CodeRunner, using Python and Java class question types. 

CodeRunner is working well for testing the Java classes I want students to write, but I'm wanting to do something a bit different. Essentially, in addition to testing class functionality, I'm wanting to parse students' source code to carry out some tests that rely on analyzing their source code. I am using a Python library that parses Java source code.

Based on an earlier post and your videos, I can see how to access the students' source code in the customization area of a CodeRunner question /question type. However, if I specify the question type to be Java, the customization code must also be implemented in Java (?).

Are you able to suggest a way that I can use CodeRunner to accept Java source submissions but to allow me to process them using Python? I was thinking of something like a Python question type that reads a Java source file supplied by the student. Do you think this is workable, or is there a simpler / alternate technique that you would suggest?

Thanks.

Ian

Ca răspuns la Ian Warren

Re: Analyzing source code

de către Richard Lobb-

Wow - a voice from my past. Hi Ian.

I often write Python questions that run other languages, but you have to explicitly compile and run the target language within the customised Python script. You can see examples here and here in the documentation. The multilanguage question type is probably the most relevant to you as it runs Java as one of the target languages - you can just rip out all the code for the other languages.

The sandbox language field of the advanced customisation panel sets the language of the template code. In your case it should be python3, which will in any case be set when you select a python3 base question type. The Ace language field of the advanced customisation panel sets the language used by the Ace editor, which students use to enter their code. You should set that to Java, so students get appropriate syntax colouring. Note that the multilanguage question type has a comma separated list of Ace languages, which results in a dropdown being presented to the students so they can select the language of their own code. Setting the field to just 'java' will disable that dropdown and lock in Java as the language.


Ca răspuns la Richard Lobb

Re: Analyzing source code

de către Ian Warren-

Hi Richard,

Thanks for your prompt and helpful reply. That's just the steer that I was looking for! I think I've got a framework now with which to implement a set of questions for a Java course I'm teaching into. Using CodeRunner, I'll be able to use a mix of functional testing and code analysis.

CodeRunner is an interesting and versatile tool.

I trust all is well with you.

Thanks again.

Ian