diff --git a/bin/set-version b/bin/set-version new file mode 100755 index 0000000..4316931 --- /dev/null +++ b/bin/set-version @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# +# Resets the project version + +import json +import sys + +version = sys.argv[1] + +for path in ["src/haxelib.json"]: + with open(path) as file: + config = json.load(file) + config["version"] = version + with open(path, "w") as file: + json.dump(config, file, indent=2, separators=(",", ": "), sort_keys=True) \ No newline at end of file diff --git a/bin/upload b/bin/upload new file mode 100755 index 0000000..46608ad --- /dev/null +++ b/bin/upload @@ -0,0 +1,69 @@ +#!/bin/bash -e +# +# Bag and tag a release to npm and haxelib + +if [ $# -lt 1 ]; then + echo "Usage: $0 VERSION" + exit 1 +fi + +if ! git diff-index --quiet HEAD --; then + echo "You have uncommitted changes" + exit 1 +fi + +VERSION=$1 +ARCHIVE=/tmp/haxelib.zip + +# FLAMBE_ROOT=`readlink -f $(dirname $0)/..` +# DEMOS_ROOT="$FLAMBE_ROOT/../flambe-demos" +# cd $FLAMBE_ROOT + +# Bump the version number +bin/set-version "$VERSION" + +# Make sure the unit tests pass +test/runtests.sh + +rm -f $ARCHIVE + +# git ls-files LICENSE.txt | zip $ARCHIVE -@ + +# Include the src directory's contents at the top-level to be nice to IDEs +# This includes the newly version-replaced haxelib.json +pushd src +git ls-files | zip $ARCHIVE -@ +popd + +# Include our haxedoc.xml as well +# bin/build-dox +# zip -j $ARCHIVE dox/haxedoc.xml + +read -p "Submit transition9 $VERSION to haxelib [Y/n]? " CONFIRM +case "$CONFIRM" in + "Y" | "y" | "") + # Upload the demos + $DEMOS_ROOT/bin/upload-all + + # Upload the API docs + rsync -avz --delete dox/ catdap:web/flambe/api/ + + # Upload the NPM module + npm publish ./command --force + + # Upload the haxelib + haxelib submit $ARCHIVE + + # Commit the version bump + git commit -a -m "Release $VERSION" + + # Tag it + git tag flambe-$VERSION + pushd $DEMOS_ROOT + git tag flambe-$VERSION + popd + + # Spam it + xdg-open "flambe@googlegroups.com?subject=Flambe $VERSION released" + ;; +esac \ No newline at end of file diff --git a/bin/upload-local b/bin/upload-local new file mode 100755 index 0000000..cf52d24 --- /dev/null +++ b/bin/upload-local @@ -0,0 +1,27 @@ +#!/bin/bash -e +# + +VERSION=$1 +ARCHIVE=/tmp/haxelib.zip + +# Bump the version number +bin/set-version "$VERSION" + +# Make sure the unit tests pass +test/runtests.sh + +rm -f $ARCHIVE + +# Include the src directory's contents at the top-level to be nice to IDEs +# This includes the newly version-replaced haxelib.json +pushd src +git ls-files | zip $ARCHIVE -@ +popd + +# Include our haxedoc.xml as well +# bin/build-dox +# zip -j $ARCHIVE dox/haxedoc.xml + +# Upload the haxelib +haxelib local $ARCHIVE + diff --git a/test/macros/LinkedListClass.hx b/test/macros/LinkedListClass.hx new file mode 100644 index 0000000..e5f91a5 --- /dev/null +++ b/test/macros/LinkedListClass.hx @@ -0,0 +1,10 @@ +package macros; + +@:build(transition9.macro.ClassMacros.addLinkedListBehaviour()) +class LinkedListClass +{ + public function new() + { + + } +} \ No newline at end of file diff --git a/test/macros/PooledClass.hx b/test/macros/PooledClass.hx new file mode 100644 index 0000000..b497a49 --- /dev/null +++ b/test/macros/PooledClass.hx @@ -0,0 +1,10 @@ +package macros; + +@:build(transition9.macro.ClassMacros.addObjectPooling()) +class PooledClass +{ + public function new() + { + + } +} \ No newline at end of file diff --git a/test/macros/PooledClassWithExistingDispose.hx b/test/macros/PooledClassWithExistingDispose.hx new file mode 100644 index 0000000..46e28ff --- /dev/null +++ b/test/macros/PooledClassWithExistingDispose.hx @@ -0,0 +1,17 @@ +package macros; + +@:build(transition9.macro.ClassMacros.addObjectPooling()) +class PooledClassWithExistingDispose +{ + public var isDisposeCalled :Bool; + + public function new() + { + isDisposeCalled = false; + } + + public function dispose() + { + isDisposeCalled = true; + } +} \ No newline at end of file diff --git a/test/macros/TestMacros.hx b/test/macros/TestMacros.hx new file mode 100644 index 0000000..555bac6 --- /dev/null +++ b/test/macros/TestMacros.hx @@ -0,0 +1,112 @@ +package macros; + +class TestMacros extends haxe.unit.TestCase +{ + public function testPooledMacro () :Void + { + var p1 = PooledClass.get(); + var p2 = PooledClass.get(); + assertTrue(p1 != null); + assertTrue(p2 != null); + assertTrue(p1 != p2); + assertTrue(PooledClass.POOL.length == 0); + + p2.dispose(); + assertTrue(PooledClass.POOL.length == 1); + + var p3 = PooledClass.get(); + assertTrue(PooledClass.POOL.length == 0); + + assertTrue(p2 == p3); + + var p2 = PooledClass.get(); + + assertTrue(p2 != p3); + assertTrue(p2 != p1); + + p1.dispose(); + #if debug + assertTrue(p1.isDisposed()); + #end + + p2.dispose(); + p3.dispose(); + assertTrue(PooledClass.POOL.length == 3); + } + + public function testPooledWithExistingDisposeMacro () :Void + { + var p1 = PooledClassWithExistingDispose.get(); + var p2 = PooledClassWithExistingDispose.get(); + assertTrue(p1 != null); + assertTrue(p2 != null); + assertTrue(p1 != p2); + assertTrue(PooledClassWithExistingDispose.POOL.length == 0); + + p2.dispose(); + assertTrue(PooledClassWithExistingDispose.POOL.length == 1); + assertTrue(p2.isDisposeCalled); + p2.isDisposeCalled = false; //Reset it + + var p3 = PooledClassWithExistingDispose.get(); + assertTrue(PooledClassWithExistingDispose.POOL.length == 0); + + assertTrue(p2 == p3); + + var p2 = PooledClassWithExistingDispose.get(); + + assertTrue(p2 != p3); + assertTrue(p2 != p1); + + p1.dispose(); + assertTrue(p1.isDisposeCalled); + p1.isDisposeCalled = false; //Reset it + #if debug + assertTrue(p1.isDisposed()); + #end + + p2.dispose(); + p3.dispose(); + assertTrue(PooledClassWithExistingDispose.POOL.length == 3); + + assertTrue(p2.isDisposeCalled); + assertTrue(p3.isDisposeCalled); + } + + public function testLinkedListMacro () :Void + { + var p1 = new LinkedListClass(); + var p2 = new LinkedListClass(); + var p3 = new LinkedListClass(); + + assertTrue(p1.before == null); + assertTrue(p1.after == null); + assertTrue(p2.before == null); + assertTrue(p2.after == null); + assertTrue(p3.before == null); + assertTrue(p3.after == null); + + p3.addAfter(p1); + + assertTrue(p1.before == null); + assertTrue(p1.after == p3); + assertTrue(p3.before == p1); + assertTrue(p3.after == null); + + p2.addBefore(p3); + + assertTrue(p1.before == null); + assertTrue(p1.after == p2); + assertTrue(p2.before == p1); + assertTrue(p2.after == p3); + assertTrue(p3.before == p2); + assertTrue(p3.after == null); + + p2.remove(); + + assertTrue(p1.before == null); + assertTrue(p1.after == p3); + assertTrue(p3.before == p1); + assertTrue(p3.after == null); + } +}