Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (63 sloc) 2.43 KB


The java2python package includes a test suite for exercising the compiler and its various translation features. This doc explains how the tests work, how to run these suite, and how to add new tests to it.

How the Test Suite Works

The test suite is a makefile that finds .java files in the same directory, converts each to Python, runs both programs, and then compares their output. If the output matches, the test is considered successful. If not, it's considered a failure.

How to Run the Test Suite

The simplest way to run the suite is to run all of it:

$ cd some_path_to/java2python/test
$ make

This will print lines like this:

[PASS] Class00
[PASS] Class01
[PASS] Class02

You can also run an individual test like this:

$ make Class02
[PASS] Class02

Notice that there isn't a suffix to the file name; you don't run make, just make Class02. If you supply an extension, nothing will happen and the test won't run.

The test directory contains two helper scripts that you can use during development. The first is runjava, which runs the Java compiler and the Java VM with the indicated file. Use it like this:

$ ./runjava
Hello, world.

The second script is runj2py, which is a handy shortcut for running the j2py script with preset command line arguments for the test configuration. You run it like this:

$ ./runj2py
#!/usr/bin/env python
""" generated source for module Class01 """
class Class01(object):

Adding New Tests

When a new compiler feature is added, or when the translation semantics change, it's a good idea to add one or more tests to the test suite. Follow this general outline:

  1. Create a Java source file that exhibits the language feature in question.

  2. Name the Java source file FeatureNN where NN is the next number in sequence for Feature, e.g.,

  3. In your Java source, write one or more values to stdout with System.out.println.

  4. Check the comparison via make FeatureNN. If the test passes, it might indicate the new feature is working correctly.

You can’t perform that action at this time.