diff options
author | 2014-05-21 15:58:49 +0900 | |
---|---|---|
committer | 2014-05-23 19:56:57 +0900 | |
commit | 7086d88d3e77e855d7d751d71b68ae38fcefea1b (patch) | |
tree | b00b2b2ccfb7f247fcd92a1500a28ee3833cf855 /tools/dicttool/src | |
parent | 75cb258ee40a97654ae364f00e1803d0bce35da8 (diff) | |
download | latinime-7086d88d3e77e855d7d751d71b68ae38fcefea1b.tar.gz latinime-7086d88d3e77e855d7d751d71b68ae38fcefea1b.tar.xz latinime-7086d88d3e77e855d7d751d71b68ae38fcefea1b.zip |
Have dicttool test tidy up after itself.
Bug: 13776363
Change-Id: Icb1d3fc0efe71e0339b434928e8aed507f2fb590
Diffstat (limited to 'tools/dicttool/src')
-rw-r--r-- | tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java index 48817b1b1..33661c8d6 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java @@ -19,16 +19,29 @@ package com.android.inputmethod.latin.dicttool; import com.android.inputmethod.latin.makedict.BinaryDictDecoderEncoderTests; import com.android.inputmethod.latin.makedict.BinaryDictEncoderFlattenTreeTests; import com.android.inputmethod.latin.makedict.FusionDictionaryTest; +import com.android.inputmethod.latin.utils.FileUtils; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.file.Files; import java.util.ArrayList; /** * Dicttool command implementing self-tests. */ public class Test extends Dicttool.Command { + private static final String getTmpDir() { + try { + return Files.createTempDirectory("dicttool").toString(); + } catch (IOException e) { + throw new RuntimeException("Can't get temporary directory", e); + } + } + private static final String TEST_TMP_DIR_BASE = getTmpDir(); + public static final File TEST_TMP_DIR = new File(TEST_TMP_DIR_BASE); public static final String COMMAND = "test"; private static final int DEFAULT_MAX_UNIGRAMS = 1500; private long mSeed = System.currentTimeMillis(); @@ -56,8 +69,12 @@ public class Test extends Dicttool.Command { @Override public String getHelp() { - final StringBuilder s = new StringBuilder("test [-s seed] [-m maxUnigrams] [testName...]\n" - + "If seed is not specified, the current time is used.\nTest list is:\n"); + final StringBuilder s = new StringBuilder( + "test [-s seed] [-m maxUnigrams] [-n] [testName...]\n" + + "If seed is not specified, the current time is used.\n" + + "If -n option is provided, do not delete temporary files in " + + TEST_TMP_DIR_BASE + "/*.\n" + + "Test list is:\n"); for (final Method m : mAllTestMethods) { s.append(" "); s.append(m.getName()); @@ -70,17 +87,26 @@ public class Test extends Dicttool.Command { public void run() throws IllegalAccessException, InstantiationException, InvocationTargetException { int i = 0; + boolean deleteTmpDir = true; while (i < mArgs.length) { final String arg = mArgs[i++]; if ("-s".equals(arg)) { mSeed = Long.parseLong(mArgs[i++]); } else if ("-m".equals(arg)) { mMaxUnigrams = Integer.parseInt(mArgs[i++]); + } else if ("-n".equals(arg)) { + deleteTmpDir = false; } else { mUsedTestMethods.add(arg); } } - runChosenTests(); + try { + runChosenTests(); + } finally { + if (deleteTmpDir) { + FileUtils.deleteRecursively(TEST_TMP_DIR); + } + } } private void runChosenTests() throws IllegalAccessException, InstantiationException, |