Skip to content

Commit

Permalink
[tests] Add tests for multiple issues
Browse files Browse the repository at this point in the history
- HaxeFoundation#364
- HaxeFoundation#526
- Ensure `list` doesn't break with invalid directories in the repository
- Ensure `list` doesn't show invalid versions
- Ensure --skip-dependencies doesn't break installing from haxelib.json
- Ensure --cwd works
- Ensure specifying versions with run, path, and libpath commands works
properly HaxeFoundation#249
- Don't show update message if vcs lib was already up to date
- Ensure order of output of `path` is correct
- Ensure remove can't break dev path set inside git/hg version
  • Loading branch information
tobil4sk committed Jan 9, 2022
1 parent 3766155 commit 818c27b
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/IntegrationTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions test/libraries/libFoo/other_foo_haxelib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"Foo": ""
}
}
24 changes: 23 additions & 1 deletion test/tests/integration/TestInstall.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"]);

Expand Down Expand Up @@ -111,5 +134,4 @@ class TestInstall extends IntegrationTests {
assertSuccess(r);
}
}

}
46 changes: 46 additions & 0 deletions test/tests/integration/TestLibpath.hx
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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());
}
}
26 changes: 26 additions & 0 deletions test/tests/integration/TestList.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tests.integration;

import sys.FileSystem;
import haxelib.SemVer;

class TestList extends IntegrationTests {
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions test/tests/integration/TestMisc.hx
Original file line number Diff line number Diff line change
@@ -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"));
}
}
89 changes: 88 additions & 1 deletion test/tests/integration/TestPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}
}
27 changes: 27 additions & 0 deletions test/tests/integration/TestRemove.hx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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()
);
}
}
46 changes: 46 additions & 0 deletions test/tests/integration/TestRun.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 818c27b

Please sign in to comment.