Skip to content

Commit

Permalink
Tests for macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dionjwa committed Oct 28, 2013
1 parent 67386c9 commit e2867c6
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 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)
69 changes: 69 additions & 0 deletions 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
27 changes: 27 additions & 0 deletions 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

10 changes: 10 additions & 0 deletions test/macros/LinkedListClass.hx
@@ -0,0 +1,10 @@
package macros;

@:build(transition9.macro.ClassMacros.addLinkedListBehaviour())
class LinkedListClass
{
public function new()
{

}
}
10 changes: 10 additions & 0 deletions test/macros/PooledClass.hx
@@ -0,0 +1,10 @@
package macros;

@:build(transition9.macro.ClassMacros.addObjectPooling())
class PooledClass
{
public function new()
{

}
}
17 changes: 17 additions & 0 deletions 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;
}
}
112 changes: 112 additions & 0 deletions 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);
}
}

0 comments on commit e2867c6

Please sign in to comment.