test/java/module/tools/jrepo/JRepoTest.java

Print this page

        

*** 47,57 **** /* * Check common error reporting. */ check(!jr.run(new String[] {" "}) && usageOK(0)); check(!jr.run(getArgs("notASubCcommand")) && usageOK(0)); ! check(!jr.run(getArgs("list -+")) && usageOK(1)); /* * Do many tests on a LocalRepository, then a few on a URLRepository * as a sanity check. */ --- 47,57 ---- /* * Check common error reporting. */ check(!jr.run(new String[] {" "}) && usageOK(0)); check(!jr.run(getArgs("notASubCcommand")) && usageOK(0)); ! check(!jr.run(getArgs("list -+")) && usageOK(-5)); /* * Do many tests on a LocalRepository, then a few on a URLRepository * as a sanity check. */
*** 67,80 **** JamUtils.recursiveDelete(jamDir); jamDir.mkdirs(); /* Check install command */ ! check(!jr.run(getArgs("install")) && usageOK(0)); ! check(!jr.run(getArgs("install repo module")) && usageOK(0)); check(!jr.run(getArgs("install -r repoDoesNotExist module")) && errorOK(1)); ! check(!jr.run(getArgs("install -p -r repoDoesNotExist module")) && errorOK(13)); // Create a directory for a local repository. File localRepoDir = new File(tmp, "JRepoTestLocalRepoDir"); JamUtils.recursiveDelete(localRepoDir); localRepoDir.mkdirs(); --- 67,80 ---- JamUtils.recursiveDelete(jamDir); jamDir.mkdirs(); /* Check install command */ ! check(!jr.run(getArgs("install")) && usageOK(-3)); ! check(!jr.run(getArgs("install repo module")) && usageOK(-3)); check(!jr.run(getArgs("install -r repoDoesNotExist module")) && errorOK(1)); ! check(!jr.run(getArgs("install -p -r repoDoesNotExist module")) && errorOK(4)); // Create a directory for a local repository. File localRepoDir = new File(tmp, "JRepoTestLocalRepoDir"); JamUtils.recursiveDelete(localRepoDir); localRepoDir.mkdirs();
*** 85,123 **** // Each install must be of a different module // Verify silent output File jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleA", "1.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); String jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -r " + repo + " " + jam)) && outputOK(0)); // Verify verbose output jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "1.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("ins -v -r " + repo + " " + jam)) && outputOK(1)); // Verify multiple versions of same named module jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "2.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "2.5", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); // Verify modules are installed check(jr.run(getArgs("list -v -r " + repo)) && outputOK(6)); // Verify -p is not applicable to install ! check(!jr.run(getArgs("install -p -r " + repo + " " + jam)) && usageOK(1)); /* Check list command */ check(!jr.run(getArgs("list")) && errorOK(0)); check(jr.run(getArgs("list -p")) && outputOK(14)); --- 85,123 ---- // Each install must be of a different module // Verify silent output File jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleA", "1.0", "platform1", "archA", false, jamDir); jamFile.deleteOnExit(); String jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -r " + repo + " " + jam)) && outputOK(0)); // Verify verbose output jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "1.0", "platform2", "archB", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("ins -v -r " + repo + " " + jam)) && outputOK(1)); // Verify multiple versions of same named module jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "2.0", "platform3", "archC", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleB", "2.5", "platform4", "archD", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); // Verify modules are installed check(jr.run(getArgs("list -v -r " + repo)) && outputOK(6)); // Verify -p is not applicable to install ! check(!jr.run(getArgs("install -p -r " + repo + " " + jam)) && usageOK(-4)); /* Check list command */ check(!jr.run(getArgs("list")) && errorOK(0)); check(jr.run(getArgs("list -p")) && outputOK(14));
*** 128,137 **** --- 128,140 ---- check(jr.run(getArgs("lis -r " + repo)) && outputOK(6)); check(jr.run(getArgs("li -p -r " + repo)) && outputOK(20)); check(jr.run(getArgs("l -v -r " + repo)) && outputOK(6)); check(jr.run(getArgs("list -p -v -r " + repo)) && outputOK(28)); + // Check that repositories are shown in sorted order + check(jr.run(getArgs("l -v -r " + repo)) && sortedOK()); + // Nonexist things are not there check(!jr.run(getArgs("list ThisWillNotBeFound")) && outputOK(0)); check(!jr.run(getArgs("list -v ThisWillNotBeFound")) && errorOK(1)); // Bootstrap repository contents are there
*** 152,172 **** check(jr.run(getArgs("list -v -r " + repo + " JRepo")) && outputOK(6)); check(jr.run(getArgs("list -p -v -r " + repo + " JR")) && outputOK(14)); /* Check uninstall command */ ! check(!jr.run(getArgs("uninstall")) && usageOK(0)); ! check(!jr.run(getArgs("uninstall repo MODULE")) && usageOK(0)); check(!jr.run(getArgs("uninstall -r repoDoesNotExist module")) && errorOK(1)); ! check(!jr.run(getArgs("uninstall -p -r repoDoesNotExist module")) && errorOK(13)); check(!jr.run(getArgs("uninstall -r " + repo + " Fred")) && errorOK(0)); check(!jr.run(getArgs("uninstall -v -r " + repo + " Fred")) && errorOK(1)); // Install one more module for tests below jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleC", "1.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("ins -v -r " + repo + " " + jam)) && outputOK(1)); // Verify a straightforward uninstall. --- 155,175 ---- check(jr.run(getArgs("list -v -r " + repo + " JRepo")) && outputOK(6)); check(jr.run(getArgs("list -p -v -r " + repo + " JR")) && outputOK(14)); /* Check uninstall command */ ! check(!jr.run(getArgs("uninstall")) && usageOK(-3)); ! check(!jr.run(getArgs("uninstall repo MODULE")) && usageOK(-3)); check(!jr.run(getArgs("uninstall -r repoDoesNotExist module")) && errorOK(1)); ! check(!jr.run(getArgs("uninstall -p -r repoDoesNotExist module")) && errorOK(4)); check(!jr.run(getArgs("uninstall -r " + repo + " Fred")) && errorOK(0)); check(!jr.run(getArgs("uninstall -v -r " + repo + " Fred")) && errorOK(1)); // Install one more module for tests below jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "JRepoModuleC", "1.0", "platform5", "archE", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("ins -v -r " + repo + " " + jam)) && outputOK(1)); // Verify a straightforward uninstall.
*** 188,203 **** check(jr.run(getArgs("un -v -f -r " + repo + " JRepoModuleB")) && outputOK(2)); check(jr.run(getArgs("list -v -r " + repo)) && outputOK(3)); // Install more modules to verify -i works jamFile = JamBuilder.createJam( ! "jrepotest", "Interact", "JRepoModuleD", "2.7", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Interact", "JRepoModuleD", "3.1", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); // This reader will let us delete the module JRepoModuleD version 3.1. --- 191,206 ---- check(jr.run(getArgs("un -v -f -r " + repo + " JRepoModuleB")) && outputOK(2)); check(jr.run(getArgs("list -v -r " + repo)) && outputOK(3)); // Install more modules to verify -i works jamFile = JamBuilder.createJam( ! "jrepotest", "Interact", "JRepoModuleD", "2.7", "platform6", "archF", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Interact", "JRepoModuleD", "3.1", "platform7", "archG", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + repo + " " + jam)) && outputOK(1)); // This reader will let us delete the module JRepoModuleD version 3.1.
*** 234,250 **** Repository urlrepo = Modules.newURLRepository("JRepoTestURLRepository", new URL(urlRepoPath), config); // Verify multiple versions of same named module jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "URLModuleX", "7.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + urlRepoPath + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "URLModuleX", "13.0", "platform", "arch", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + urlRepoPath + " " + jam)) && outputOK(1)); // Verify list --- 237,253 ---- Repository urlrepo = Modules.newURLRepository("JRepoTestURLRepository", new URL(urlRepoPath), config); // Verify multiple versions of same named module jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "URLModuleX", "7.0", "platform8", "archH", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + urlRepoPath + " " + jam)) && outputOK(1)); jamFile = JamBuilder.createJam( ! "jrepotest", "Example", "URLModuleX", "13.0", "platform9", "archI", false, jamDir); jamFile.deleteOnExit(); jam = jamFile.getCanonicalPath(); check(jr.run(getArgs("install -v -r " + urlRepoPath + " " + jam)) && outputOK(1)); // Verify list
*** 310,323 **** return checkOutput(len, berr); } /** Check that usage is provided as expected. */ static boolean usageOK(int len) throws Throwable { ! // Add number of default lines of usage output to given value. ! return checkOutput(12 + len, berr); } //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0; static boolean pass() {passed++; return true;} static boolean fail() {failed++; Thread.dumpStack(); return false;} static boolean fail(String msg) {System.err.println(msg); return fail();} --- 313,352 ---- return checkOutput(len, berr); } /** Check that usage is provided as expected. */ static boolean usageOK(int len) throws Throwable { ! // If len < 0, use negative of that, else use len + default ! return checkOutput(len < 0 ? -len : 20 + len, berr); } + /** Check that output is sorted, after skipping the firsts header line. */ + static boolean sortedOK() throws Throwable { + int numFailed = failed; + String allLines = bout.toString(); + if (debug) System.err.println("Checking sort order on '" + allLines + "'"); + BufferedReader r = new BufferedReader(new StringReader(allLines)); + check(r.readLine() != null); // Skip heading + List<String> lines = new ArrayList<String>(); + String s; + while ((s = r.readLine()) != null) { + check(!lines.contains(s)); + check(lines.add(s)); + } + String prev = lines.get(2); + for (int i = 3; i < lines.size(); i++) { + String cur = lines.get(i); + if (!check(prev.compareTo(cur) < 0)) { + System.err.println( + "'" + prev + "'\nis not less than \n'" + cur + "'"); + } + prev = cur; + } + bout.reset(); + return numFailed == failed; + } + //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0; static boolean pass() {passed++; return true;} static boolean fail() {failed++; Thread.dumpStack(); return false;} static boolean fail(String msg) {System.err.println(msg); return fail();}