コード例 #1
0
def runDecompilerTest(target, testcases):
    print 'Running decompiler test {}...'.format(target)
    tdir = tempfile.mkdtemp()

    cpath = [decompile.findJRE(), dec_class_location]
    if cpath[0] is None:
        raise RuntimeError('Unable to locate rt.jar')

    decompile.decompileClass(cpath, targets=[target], outpath=tdir, add_throws=True)
    new_fname = compileJava(target, os.path.join(tdir, target + '.java'))

    # testcases = map(tuple, tests.decompiler.registry[target])
    good_fname = os.path.join(dec_class_location, target + '.class')
    runJavaAndCompare(target, testcases, good_fname, new_fname)
    shutil.rmtree(tdir)
コード例 #2
0
ファイル: runtests.py プロジェクト: alexkasko/krakatau-java
def performTest(target, expected_results, tempbase=tempfile.gettempdir()):
    temppath = os.path.join(tempbase, target)

    cpath = [decompile.findJRE(), class_location]
    if None in cpath:
        raise RuntimeError('Unable to locate rt.jar')

    # Clear any pre-existing files and create directory if necessary
    # try:
    #     shutil.rmtree(temppath)
    # except OSError as e:
    #     print e
    try:
        os.mkdir(temppath)
    except OSError as e:
        print e
    assert(os.path.isdir(temppath))

    decompile.decompileClass(cpath, targets=[target], outpath=temppath, add_throws=True)
    # out, err = execute(['java',  '-jar', 'procyon-decompiler-0.5.25.jar', os.path.join(class_location, target+'.class')], '.')
    # if err:
    #     print 'Decompile errors:', err
    #     return False
    # with open(os.path.join(temppath, target+'.java'), 'wb') as f:
    #     f.write(out)

    print 'Attempting to compile'
    _, stderr = execute(['javac', target+'.java', '-g:none'], cwd=temppath)
    if stderr:
        print 'Compile failed:'
        print stderr
        return False

    cases = tests.registry[target]
    for args, expected in zip(cases, expected_results):
        print 'Executing {} w/ args {}'.format(target, args)
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'Failed test {} w/ args {}:'.format(target, args)
            if result[0] != expected[0]:
                print '  expected stdout:', repr(expected[0])
                print '  actual stdout  :', repr(result[0])
            if result[1] != expected[1]:
                print '  expected stderr:', repr(expected[1])
                print '  actual stderr  :', repr(result[1])
            return False
    return True
コード例 #3
0
ファイル: runtests.py プロジェクト: Mu-L/Krakatau
def runDecompilerTest(target, testcases):
    print('Running decompiler test {}...'.format(target))
    tdir = tempfile.mkdtemp()

    cpath = [decompile.findJRE(), dec_class_location]
    if cpath[0] is None:
        raise RuntimeError('Unable to locate rt.jar')

    decompile.decompileClass(cpath,
                             targets=[target],
                             outpath=tdir,
                             add_throws=True)
    new_fname = compileJava(target, os.path.join(tdir, target + '.java'))

    # testcases = map(tuple, tests.decompiler.registry[target])
    good_fname = os.path.join(dec_class_location, target + '.class')
    runJavaAndCompare(target, testcases, good_fname, new_fname)
    shutil.rmtree(tdir)
コード例 #4
0
ファイル: test_decompiler.py プロジェクト: Sputuks3/Krakatau
def performTest(temppath, testdata, cpath=class_location):
    target, cases = testdata

    clearFolder(temppath)
    cpath = [decompile.findJRE(), cpath]
    decompile.decompileClass(cpath, targets=[target], outpath=temppath)

    print 'Attempting to compile'
    out, err = execute(['javac', target+'.java'] + '-g:none -target 1.5'.split(), cwd=temppath)
    if err:
        print out, err
        return False

    for args, expected in cases:
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'expected', expected
            print 'actual', result
            return False
    return True
コード例 #5
0
def performTest(temppath, testdata, cpath=class_location):
    target, cases = testdata

    clearFolder(temppath)
    cpath = [decompile.findJRE(), cpath]
    if None in cpath:
        raise RuntimeError('Unable to locate rt.jar')
    decompile.decompileClass(cpath, targets=[target], outpath=temppath)

    print 'Attempting to compile'
    out, err = execute(['javac', target+'.java'] + '-g:none'.split(), cwd=temppath)
    if err:
        print out, err
        return False

    for args, expected in cases:
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'input', args
            print 'expected', expected
            print 'actual', result
            return False
    return True