TestCGen.java 文件源码

java
阅读 16 收藏 0 点赞 0 评论 0

项目:vtable-aabajaj2 作者:
public void checkCGen(String filename) throws Exception {
    URL testFolderURL = TestCGen.class.getClassLoader().getResource(SAMPLES_DIR);
    String testFolder = testFolderURL.getPath();
    String workingDir = getWorkingDir();

    String J_pathToFile = testFolder+"/"+filename;
    String C_filename = basename(filename)+".c";

    JTran jTran = new JTran();
    String C_code = jTran.translate(J_pathToFile, C_filename, false, false);

    Utils.writeFile(workingDir+"/"+C_filename, C_code);

    String[] indent_result_cmd = {
        "indent",
        "-bap", "-bad", "-br", "-nce", "-ncs", "-nprs", "-npcs", "-sai", "-saw",
        "-di1", "-brs", "-blf", "--indent-level4", "-nut", "-sob", "-l200",
        C_filename,
        "-o", C_filename // write on top of itself
    };

    // normalize generated code
    exec(indent_result_cmd, workingDir);

    // format the expected file as well
    String expected_C_CodeFilename = testFolder+"/"+C_filename;
    String[] indent_expected_cmd = {
        "indent",
        "-bap", "-bad", "-br", "-nce", "-ncs", "-nprs", "-npcs", "-sai", "-saw",
        "-di1", "-brs", "-blf", "--indent-level4", "-nut", "-sob", "-l200",
        expected_C_CodeFilename,
        "-o", "expected_"+C_filename
    };
    exec(indent_expected_cmd, workingDir);

    // compare with expected c file
    String[] diff_cmd = {
        "diff", "expected_"+C_filename, C_filename
    };
    Triple<Integer, String, String> result = exec(diff_cmd, workingDir);
    int execCode = result.a;
    String stdout = result.b;
    String stderr = result.c;

    assertEquals("", stdout);
    assertEquals("", stderr);
    assertEquals(0, execCode);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号