package picocli; import org.junit.Test; import java.io.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * This JUnit test kicks off the autocompletion tests written in Tcl and Except * using the DejaGnu test framework, and passes if these tests all pass * (evidenced by the last line of output from the DejaGnu tests * to start with "# of expected passes"). *
* In order for this test to run, the following packages must be installed: *
** This test will only run on unix-based systems where the above packages are installed. * (For example, the tests will run on WSL - Windows Subsystem for Linux - if the above * packages are installed.) * If dejagnu is not installed, this test is ignored. *
* The starting point of the completion tests is the {@code dejagnu.tests/runCompletion} script. * This is a wrapper script that starts the dejagnu {@code runtest} with option {@code --tool completion}. *
* The dejagnu tests themselves live in {@code dejagnu.tests/completion}; * the *.exp scripts in that directory source the completion scripts, and then delegate to * an accompanying *.exp script in the {@code dejagnu.tests/lib/completions} directory * where the various completion scenarios are verified. *
* You can run the DejaGnu completion tests manually as follows: *
** cd src/test/dejagnu.tests * ./runCompletion **
* To get more verbose output, add the {@code -v} option. Adding this option multiple times * increases the verbosity. * Log files by default are written to a directory named {@code log} in the current directory. * This can be changed with the {@code --log-dir} option. For example: *
** # create completion.log and completion.sum log files in the build/dejagnu-logs directory * cd src/test/dejagnu.tests * ./runCompletion -v --log-dir ../../../build/dejagnu-logs **/ public class AutoCompleteDejaGnuTest { @Test public void tryRunDejaGnuCompletionTests() throws Exception { //System.out.println(System.getProperty("user.dir")); // ignores test if dejagnu not installed org.junit.Assume.assumeTrue("dejagnu must be installed to run this test", isDejaGnuInstalled()); runDejaGnuCompletionTests(); } private void runDejaGnuCompletionTests() throws Exception { final File testDir = new File("src/test/dejagnu.tests"); assertTrue(testDir.getAbsolutePath() + " should exist", testDir.exists()); File runCompletionScript = new File(testDir, "runCompletion"); assertTrue(runCompletionScript.getAbsolutePath() + " should exist", runCompletionScript.exists()); final int TIMEOUT_RUNTEST_COMPLETION = 60; // how many seconds to wait for the `./runCompletion` process to complete final AtomicInteger runtestExitStatus = new AtomicInteger(Integer.MIN_VALUE); final AtomicReference