diff --git a/test/IntegrationTests.hx b/test/IntegrationTests.hx index 6b0e79a44..c448cd0a4 100644 --- a/test/IntegrationTests.hx +++ b/test/IntegrationTests.hx @@ -248,6 +248,7 @@ class IntegrationTests extends TestBase { runner.add(new tests.integration.TestLibpath()); runner.add(new tests.integration.TestGit()); runner.add(new tests.integration.TestHg()); + runner.add(new tests.integration.TestMisc()); final success = runner.run(); if (!success) { diff --git a/test/libraries/InstallDeps/empty.hxml b/test/libraries/InstallDeps/empty.hxml new file mode 100644 index 000000000..e69de29bb diff --git a/test/libraries/libFoo/other_foo_haxelib.json b/test/libraries/libFoo/other_foo_haxelib.json new file mode 100644 index 000000000..20341bedf --- /dev/null +++ b/test/libraries/libFoo/other_foo_haxelib.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "Foo": "" + } +} diff --git a/test/tests/integration/TestInstall.hx b/test/tests/integration/TestInstall.hx index 6ad3ada7d..faeff9395 100644 --- a/test/tests/integration/TestInstall.hx +++ b/test/tests/integration/TestInstall.hx @@ -9,6 +9,11 @@ class TestInstall extends IntegrationTests { assertSuccess(r); final r = haxelib(["submit", Path.join([IntegrationTests.projectRoot, "test/libraries/libBar.zip"]), bar.pw]).result(); assertSuccess(r); + + final r = haxelib(["register", foo.user, foo.email, foo.fullname, foo.pw, foo.pw]).result(); + assertSuccess(r); + final r = haxelib(["submit", Path.join([IntegrationTests.projectRoot, "test/libraries/libFoo.zip"]), foo.pw]).result(); + assertSuccess(r); } function testNormal():Void { @@ -81,6 +86,24 @@ class TestInstall extends IntegrationTests { } } + function testFromHaxelibJsonWithSkipDependencies() { + final haxelibJson = Path.join([IntegrationTests.projectRoot, "test/libraries/libFoo/other_foo_haxelib.json"]); + + { + final r = haxelib(["install", haxelibJson, "--skip-dependencies"]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["list"]).result(); + assertSuccess(r); + // Foo was still installed + assertTrue(r.out.indexOf("Foo") >= 0); + // but bar wasn't + assertTrue(r.out.indexOf("Bar") < 0); + } + } + function testFromHxml() { final hxml = Path.join([IntegrationTests.projectRoot, "test/libraries/libFoo/build.hxml"]); @@ -111,5 +134,4 @@ class TestInstall extends IntegrationTests { assertSuccess(r); } } - } diff --git a/test/tests/integration/TestLibpath.hx b/test/tests/integration/TestLibpath.hx index a67613201..4482ee8e6 100644 --- a/test/tests/integration/TestLibpath.hx +++ b/test/tests/integration/TestLibpath.hx @@ -1,6 +1,10 @@ package tests.integration; class TestLibpath extends IntegrationTests { + static final barDevPath = "libraries/libBar2/"; + static final barPath = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/1,0,0"]).addTrailingSlash(); + static final bar2Path = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/2,0,0"]).addTrailingSlash(); + override function setup() { super.setup(); @@ -52,4 +56,46 @@ class TestLibpath extends IntegrationTests { r.out.trim() ); } + + function testVersionSpecification():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + final r = haxelib(["install", "libraries/libBar2.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the dev version will be run + final r = haxelib(["libpath", "Bar"]).result(); + assertSuccess(r); + assertEquals(bar2Path, r.out.trim()); + + // if we specify a version, we want that and not the dev version + final r = haxelib(["libpath", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertEquals(barPath, r.out.trim()); + + // if we specify a missing version, we fail. + final r = haxelib(["libpath", "Bar:1.1.0"]).result(); + assertFail(r); + assertEquals("Error: Library Bar version 1.1.0 is not installed", r.err.trim()); + } + + function testVersionOverriding() { + // # 249 + final r = haxelib(["dev", "Bar", barDevPath]).result(); + assertSuccess(r); + + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the dev version will be run + final r = haxelib(["libpath", "Bar"]).result(); + assertSuccess(r); + final devPath = sys.FileSystem.absolutePath(barDevPath).addTrailingSlash(); + assertEquals(devPath, r.out.trim()); + + // if we specify a version, we want that and not the dev version + final r = haxelib(["libpath", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertEquals(barPath, r.out.trim()); + } } diff --git a/test/tests/integration/TestList.hx b/test/tests/integration/TestList.hx index 5c3087817..d14f593a5 100644 --- a/test/tests/integration/TestList.hx +++ b/test/tests/integration/TestList.hx @@ -1,5 +1,6 @@ package tests.integration; +import sys.FileSystem; import haxelib.SemVer; class TestList extends IntegrationTests { @@ -111,4 +112,29 @@ class TestList extends IntegrationTests { } } } + + function testInvalidDirectories():Void { + FileSystem.createDirectory('${projectRoot}$repo/LIBRARY'); + + final r = haxelib(["list"]).result(); + assertSuccess(r); + // the command should not crash + assertEquals("", r.out); + // LIBRARY is not a valid project directory, so it is not listed + } + + function testInvalidVersions():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + + FileSystem.createDirectory('${projectRoot}$repo/bar/invalid/'); + + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + // the command should not crash + + assertTrue(r.out.indexOf("Bar") >= 0); + assertTrue(r.out.indexOf("[1.0.0]") >= 0); + assertTrue(r.out.indexOf("invalid") < 0); + } } diff --git a/test/tests/integration/TestMisc.hx b/test/tests/integration/TestMisc.hx new file mode 100644 index 000000000..27446ddd7 --- /dev/null +++ b/test/tests/integration/TestMisc.hx @@ -0,0 +1,12 @@ +package tests.integration; + +class TestMisc extends IntegrationTests { + function testCwdWhenPassingToUpdatedHaxelib() { + // so that the call is passed on + haxelib(["dev", "haxelib", IntegrationTests.projectRoot]); + + final r = haxelib(["install", "empty.hxml", "--cwd", "libraries/InstallDeps"]).result(); + assertSuccess(r); + assertTrue(r.out.startsWith("Installing all libraries from")); + } +} diff --git a/test/tests/integration/TestPath.hx b/test/tests/integration/TestPath.hx index f2b54f8be..ad263ea99 100644 --- a/test/tests/integration/TestPath.hx +++ b/test/tests/integration/TestPath.hx @@ -3,14 +3,35 @@ package tests.integration; using Lambda; class TestPath extends IntegrationTests { + static final barDevPath = "libraries/libBar2/"; + static final barPath = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/1,0,0"]).addTrailingSlash(); + static final bar2Path = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/2,0,0"]).addTrailingSlash(); + static final bazPath = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "baz/0,1,0-alpha,0"]).addTrailingSlash(); + #if !system_haxelib - function testMain():Void { + function testBadHaxelibJson():Void { final r = haxelib(["dev", "BadHaxelibJson", Path.join([IntegrationTests.projectRoot, "test/libraries/libBadHaxelibJson"])]).result(); assertSuccess(r); final r = haxelib(["path", "BadHaxelibJson"]).result(); assertFail(r); } #end + + function testMultipleLibraries():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + final r = haxelib(["install", "libraries/libBaz.zip"]).result(); + assertSuccess(r); + + final r = haxelib(["path", "Bar", "Baz"]).result(); + assertSuccess(r); + assertOutputEquals([barPath, '-D Bar=1.0.0', bazPath, '-D Baz=0.1.0-alpha.0'], r.out.trim()); + + final r = haxelib(["path", "Baz", "Bar"]).result(); + assertSuccess(r); + assertOutputEquals([bazPath, '-D Baz=0.1.0-alpha.0', barPath, '-D Bar=1.0.0'], r.out.trim()); + } + // for issue #529 function testCapitalization():Void { final r = haxelib(["dev", "Bar", Path.join([IntegrationTests.projectRoot, "test/libraries/libBar"])]).result(); @@ -23,4 +44,70 @@ class TestPath extends IntegrationTests { assertSuccess(r); assertEquals(firstOut, r.out); } + + function testVersionSpecification():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + final r = haxelib(["install", "libraries/libBar2.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the set version will be run + final r = haxelib(["path", "Bar"]).result(); + assertSuccess(r); + assertOutputEquals([bar2Path, '-D Bar=2.0.0'], r.out.trim()); + + // if we specify a version, we want that + final r = haxelib(["path", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertOutputEquals([barPath, '-D Bar=1.0.0'], r.out.trim()); + + // if we specify a missing version, we fail. + final r = haxelib(["path", "Bar:1.1.0"]).result(); + assertFail(r); + assertEquals("Error: Library Bar version 1.1.0 is not installed", r.err.trim()); + } + + function testVersionOverriding():Void { + // # 249 + final r = haxelib(["dev", "Bar", barDevPath]).result(); + assertSuccess(r); + + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the dev version will be run + final r = haxelib(["path", "Bar"]).result(); + assertSuccess(r); + final devPath = sys.FileSystem.absolutePath(barDevPath).addTrailingSlash(); + assertOutputEquals([devPath, '-D Bar=2.0.0'], r.out.trim()); + + // if we specify a version, we want that and not the dev version + final r = haxelib(["path", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertOutputEquals([barPath, '-D Bar=1.0.0'], r.out.trim()); + } + + function testMultipleLibraryVersions():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + final r = haxelib(["install", "libraries/libBar2.zip"]).result(); + assertSuccess(r); + + final r = haxelib(["path", "Bar:2.0.0", "Bar"]).result(); + assertSuccess(r); + assertOutputEquals([bar2Path, '-D Bar=2.0.0'], r.out.trim()); + + final r = haxelib(["path", "Bar:1.0.0", "Bar"]).result(); + assertSuccess(r); + assertOutputEquals([barPath, '-D Bar=1.0.0'], r.out.trim()); + + final r = haxelib(["path", "Bar:2.0.0", "Bar:1.0.0"]).result(); + assertFail(r); + assertEquals('Error: Cannot process `Bar:1.0.0`: Library Bar has two versions included : 2.0.0 and 1.0.0', r.err.trim()); + + // differently capitalized + final r = haxelib(["path", "Bar:2.0.0", "bar:1.0.0"]).result(); + assertFail(r); + assertEquals('Error: Cannot process `bar:1.0.0`: Library Bar has two versions included : 2.0.0 and 1.0.0', r.err.trim()); + } } diff --git a/test/tests/integration/TestRemove.hx b/test/tests/integration/TestRemove.hx index e7d305e5e..d8503fb33 100644 --- a/test/tests/integration/TestRemove.hx +++ b/test/tests/integration/TestRemove.hx @@ -1,9 +1,18 @@ package tests.integration; class TestRemove extends IntegrationTests { + final gitLibPath = "libraries/libBar"; + override function setup() { + super.setup(); + Utils.makeGitRepo(gitLibPath); + } + override function tearDown() { + Utils.resetGitRepo(gitLibPath); + super.tearDown(); + } function testNormal():Void { final r = haxelib(["install", "libraries/libBar.zip"]).result(); assertSuccess(r); @@ -66,4 +75,22 @@ class TestRemove extends IntegrationTests { assertTrue(r.out.indexOf("1.0.0") < 0); assertTrue(r.out.indexOf("[2.0.0]") >= 0); } + + function testRemovalWithDevSet() { + final r = haxelib(["git", "Bar", gitLibPath, "main", "git/bar/"]).result(); + assertSuccess(r); + + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + + final r = haxelib(["remove", "Bar", "git"]).result(); + assertFail(r); + + assertOutputEquals([ + "Error: Cannot remove library `Bar` version `git`: It holds the `dev` version of `Bar`", + "Use `haxelib dev Bar` to unset the dev path" + ], + r.err.trim() + ); + } } diff --git a/test/tests/integration/TestRun.hx b/test/tests/integration/TestRun.hx index e03eaf6be..c2e07db1c 100644 --- a/test/tests/integration/TestRun.hx +++ b/test/tests/integration/TestRun.hx @@ -20,6 +20,9 @@ class TestRun extends IntegrationTests { #if (haxe_ver >= 4.0) static final libEnvironment = "libraries/libEnvironment/"; + static final barDevPath = "libraries/libBar2/"; + static final barPath = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/1,0,0"]).addTrailingSlash(); + static final bar2Path = Path.join([IntegrationTests.projectRoot, IntegrationTests.repo, "bar/2,0,0"]).addTrailingSlash(); override function tearDown() { Utils.resetGitRepo(libEnvironment); @@ -118,5 +121,48 @@ class TestRun extends IntegrationTests { assertSuccess(r); assertEquals("Environment", r.out); } + + function testVersionSpecification():Void { + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + final r = haxelib(["install", "libraries/libBar2.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the set version will be run + final r = haxelib(["run", "Bar"]).result(); + assertSuccess(r); + assertEquals('Bar2 run.n script', r.out); + + // if we specify a version, we run that + final r = haxelib(["run", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertEquals('Bar Run.hx script', r.out); + + // if we specify a missing version, we fail. + final r = haxelib(["run", "Bar:1.1.0"]).result(); + assertFail(r); + assertEquals("Error: Library Bar version 1.1.0 is not installed", r.err.trim()); + } + + function testVersionOverriding():Void { + final bazPath = "libraries/libBaz"; + + // # 249 + final r = haxelib(["dev", "Bar", bazPath]).result(); + assertSuccess(r); + + final r = haxelib(["install", "libraries/libBar.zip"]).result(); + assertSuccess(r); + + // if no version is specified, the dev version will be run + final r = haxelib(["run", "Bar"]).result(); + assertSuccess(r); + assertEquals('Baz tools.Main script', r.out); + + // if we specify a version, we want that and not the dev version + final r = haxelib(["run", "Bar:1.0.0"]).result(); + assertSuccess(r); + assertEquals('Bar Run.hx script', r.out); + } #end } diff --git a/test/tests/integration/TestSet.hx b/test/tests/integration/TestSet.hx index 4edb0d0e2..e30bac16a 100644 --- a/test/tests/integration/TestSet.hx +++ b/test/tests/integration/TestSet.hx @@ -1,5 +1,7 @@ package tests.integration; +import sys.FileSystem; + class TestSet extends IntegrationTests { override function setup() { @@ -15,6 +17,12 @@ class TestSet extends IntegrationTests { assertSuccess(r); } + override function tearDown() { + Utils.resetGitRepo('libraries/libBar'); + + super.tearDown(); + } + function test():Void { { final r = haxelib(["install", "Bar"]).result(); @@ -145,4 +153,44 @@ class TestSet extends IntegrationTests { assertTrue(r.out.indexOf("2.0.0") >= 0); } } + + function testGit() { + final gitPath = '${projectRoot}test/libraries/libBar'; + + Utils.makeGitRepo(gitPath); + + final r = haxelib(["git", "Bar", gitPath]).result(); + assertSuccess(r); + + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("[git]") >= 0); + + final r = haxelib(["install", "Bar"]).result(); + assertSuccess(r); + + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("[2.0.0]") >= 0); + assertTrue(r.out.indexOf("git") >= 0); + + final r = haxelib(["set", "Bar", "git"]).result(); + assertSuccess(r); + + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("2.0.0") >= 0); + assertTrue(r.out.indexOf("[git]") >= 0); + } + + function testInvalidVersion() { + // #526 + final r = haxelib(["install", "Bar"]).result(); + assertSuccess(r); + + FileSystem.createDirectory(Path.join([projectRoot, repo, "bar", "invalid"])); + + final r = haxelib(["set", "Bar", "invalid"]).result(); + assertFail(r); + } } diff --git a/test/tests/integration/TestUpdate.hx b/test/tests/integration/TestUpdate.hx index 038c165f4..f9c0e655d 100644 --- a/test/tests/integration/TestUpdate.hx +++ b/test/tests/integration/TestUpdate.hx @@ -1,6 +1,19 @@ package tests.integration; class TestUpdate extends IntegrationTests { + + final gitLibPath = 'libraries/libBar'; + + override function setup() { + super.setup(); + Utils.makeGitRepo(gitLibPath); + } + + override function tearDown() { + Utils.resetGitRepo(gitLibPath); + super.tearDown(); + } + function test():Void { { final r = haxelib(["register", bar.user, bar.email, bar.fullname, bar.pw, bar.pw]).result(); @@ -129,4 +142,62 @@ class TestUpdate extends IntegrationTests { assertTrue(r.out.indexOf("Bar") < 0); } } + + function testUpdatingWithGitVersion():Void { + // #364 + { + final r = haxelib(["git", "Bar", gitLibPath]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["update", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("Library Bar git repository is already up to date") >= 0); + + // Don't show update message if vcs lib was already up to date + assertTrue(r.out.indexOf("Bar was updated") < 0); + } + + { + final r = haxelib(["register", bar.user, bar.email, bar.fullname, bar.pw, bar.pw]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["submit", Path.join([IntegrationTests.projectRoot, "test/libraries/libBar.zip"]), bar.pw]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["install", "Bar"]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("[1.0.0]") >= 0); + assertTrue(r.out.indexOf("git") >= 0); + } + + { + final r = haxelib(["submit", Path.join([IntegrationTests.projectRoot, "test/libraries/libBar2.zip"]), bar.pw]).result(); + assertSuccess(r); + } + + { + final r = haxelib(["update", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("Library Bar git repository is already up to date") < 0); + } + + { + final r = haxelib(["list", "Bar"]).result(); + assertSuccess(r); + assertTrue(r.out.indexOf("[2.0.0]") >= 0); + assertTrue(r.out.indexOf("1.0.0") >= 0); + assertTrue(r.out.indexOf("git") >= 0); + } + } } diff --git a/test/tests/integration/Utils.hx b/test/tests/integration/Utils.hx index c026e4e4c..c874ec696 100644 --- a/test/tests/integration/Utils.hx +++ b/test/tests/integration/Utils.hx @@ -16,6 +16,8 @@ function makeGitRepo(libPath:String) { runCommand(cmd, ["init"]); runCommand(cmd, ["add", "-A"]); runCommand(cmd, ["commit", "-m", "Create repo"]); + // different systems may have different default branch names set + runCommand(cmd, ["branch", "--move", "main"]); Sys.setCwd(oldCwd); }