lunes, 2 de enero de 2012

No more excuses for do not testing: picotest 0.0.1 released

Picotest is a gem which allows to write complete test suites in a few lines, targeted primarily to test separated methods, algorithms or little snippets of code

The first gem release (0.0.1) is only a proof on concept to explore the idea which is to avoid "It's not worth testing this" syndrome. This problem occurs when we develop really small features such as helper functions, calculation private methods, etc... and then we fall in "It's not worth testing this", "because test code will be much greater than code being tested".

The solution offered by picotest, is to provide a really small testing dsl to keep the "proportion" even in smaller cases, using hash syntax and other syntaxic sugar

Examples

For example, if you want to test Math.sqrt function, you could use the following:
require "picotest"

suite(1 => 1, 4 => 2, 9 => 3, 16 => 4).test(Math.method(:sqrt))

There is no need to write all cases one by one, if you known as to calculate the input from the output (the inverse of sqrt), in that cases you could use a reverse oracle
require "picotest"

suite( lambda{|x| x**2} => _set(1,2,3,4,5,6,7,8,9,10)).test(Math.method(:sqrt))
# the following is the same as the above example
suite( lambda{|x| x**2} => _set(*(1..10)).test(Math.method(:sqrt))

And mocking is as follows:
class X
attr_accessor :another_object
def foo(data)
data.split(";")[another_object.fieldno].to_f
end
end

# you can return mock objects using mock method again
s.test X.new.method(:foo).mock(:another_object => mock(:fieldno => 2) )
You can read more examples at https://github.com/tario/picotest/tree/master/samples and in the README

Install

gem install picotest

Links

sábado, 19 de noviembre de 2011

Fastruby 0.0.16 released with ruby 1.9 support

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.16 release simply adds support for ruby 1.9, also fastruby was fixed for ruby 1.8 running with rvm (ruby1.8 patch 334), the big disclaimer here is that ruby1.9 specific code such fibers and new hash syntax won't work and fastruby is slower than ruby1.9 (both issues will be solved in next releases)
All code working with fastruby on ruby1.8 now will work with fastruby on ruby1.9.

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.16
Or install it using gem install:
gem install fastruby 
Platforms Supported
  • Ruby 1.8 patch 352
  • Ruby 1.8 patch 334 (tested using rvm)
  • Ruby 1.9 patch 180 (tested using rvm)


jueves, 10 de noviembre de 2011

Migrating everthing to ruby1.9

Since the warning I get from a excellent talk of @yhara at @RubyConfAr, ruby 1.9 is the present while ruby 1.8 is the past. The next step regarding my projects is to ensure that all works on ruby 1.9 (but keeping the compatibility with ruby1.8 at the same time)
This is the status of the more important projects.

ImageRuby

All tests on ImageRuby spec works with 1.9,2-p180 thanks to the contribution fix of amadanmath. Of course I will be listen to bug reports regarding ruby1.9 compatibility

Shikashi (and dependencies)

All tests on Shikashi spec works with 1.9,2-p180. Specific ruby 1.9 syntaxis are not convered by the spec. I have created a new issue for this (the issue corresponds to partialruby gem)

To make shikashi fully compatible with ruby1.9, I must find a replacement for RubyParser which is not compatible with some of ruby 1.9 specific syntax, for example, RubyParser is unable to recognize the new syntax for hashes of ruby 1.9

Fastruby

This is the most complex case, these are the remaining issues:
  • Main headers of fastruby won't compile since these sources use syntax not supported by ruby1.9
  • Use of C-Api specific to ruby1.8
  • Remove support for syntax specific to ruby1.8 (only when run under ruby1.8)
  • Add support for syntax specific to ruby1.9 (only when run under ruby1.9)
  • RubyInline does not work with ruby1.9
  • RubyParser does not work with ruby1.9

I will fork or find a fork of rubyinline to fix issues related with ruby1.9 compatibility, for the case of RubyParser (affecting shikashi too) I will replace parsing using Ripper which is the native out-of-the-box implementation of parsing on ruby1.9

martes, 1 de noviembre de 2011

Fastruby 0.0.15 released. Callcc and continuation objects!

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.15 release adds the support for continuation objects created using callcc function. To acchieve this, the implementation uses the non-lineal stack created on previous releases.
Also this release adds a few extra language support improvements such as method default arguments

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.15
Or install it using gem install:
gem install fastruby

New Features

Fixes

Examples of code being supported

Example of continuation calls, tail recursion


require "fastruby"

fastruby '
class X
def fact( n )
a = callcc { |k| [ n, 1, k ] }
n = a[0]
f = a[1]
k = a[2]
if ( n == 0 ) then return f
else
k.call n-1, n*f, k
end
end
end
'

p X.new.fact(6) # 720

Default Arguments
require "fastruby"

fastruby '
class X
def foo(a,b = a.reverse)
a + b
end
end
'

p X.new.foo("13") # 1331
p X.new.foo("xx", "yy") # xxyy

Passing proc objects as blocks
require "fastruby"

fastruby '
class X
def bar
yield(1)
yield(2)
yield(3)
end

def foo
pr = proc do |x|
p x
end

bar(&pr) # passing proc as a block
end
end
'

X.new.foo

Receiving blocks as proc objects
require "fastruby"

fastruby '
class X
def bar(&pr)
pr.call(1)
pr.call(2)
pr.call(3)
end

def foo
bar do |x|
p x
end
end
end
'

X.new.foo


domingo, 23 de octubre de 2011

Fastruby 0.0.14 released with support for method replacement

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.14 release make a internal redesign of the method hash structure to allow the store of function pointer pointers, this is what allows to reference a fixed function pointer which may change enabling method replacement while retaining most of the performance (fastruby calls now consume a extra indirection and a few extra checks)

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.14
Or install it using gem install:
gem install fastruby

New Features


Examples of code being supported

Replacement of methods

require "fastruby"

fastruby '
class X
def foo(a)
a+1
end
end
'

x = X.new
p x.foo(4) # 5

fastruby '
class X
def foo(a)
a*2
end
end
'

p x.foo(4) # 8


Remaining uncovered items on v0.0.14 release
  • Memory handling of function pointers on method hash (will be fixed for v0.0.15)
  • Fix limitation of 15 arguments when calling method defined on fastruby from normal ruby
  • Fix duplication of objects on cache when methods are replaced
  • Optimization of splat callls, currently this calls are executing using normal rb_funcall2 (will be improved for v0.2.0)
  • Optimization of calls to methods with variable number of arguments, currently are wrapped using rb_funcall (will be improved for v0.2.0)

domingo, 9 de octubre de 2011

Fastruby 0.0.13 released with support for splat arguments and method with array arguments

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.13 release of fastruby make a little internal design improvement regarding translator class and the implementation of splat arguments and methods with optional arguments (see examples below)

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.13
Or install it using gem install:
gem install fastruby

New Features



Examples of code being supported

Multiple arguments and call with splat

require "fastruby"

fastruby '
class X
def foo(*array)
array.each do |x|
p x
end
end

def bar(*args)
foo(*args)
end
end
'

x = X.new
x.foo(1,2,3) # prints 1,2 and 3
x.bar(4,5,6) # prints 4,5 and 6

Remaining uncovered items on v0.0.13 release

domingo, 2 de octubre de 2011

Fastruby 0.0.11 released with support for retry, redo and foreach

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.11 release of fastruby make internal improvements regarding non-local jumps and implements foreach support, including retry and redo statements (both applicable to any kind of block, and retry applicable on rescue clause)

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.11
Or install it using gem install:
gem install fastruby

New Features


Examples of code being supported

For each with redo and retry

require "fastruby"

fastruby '
class X
def foo
sum = 0

for i in (4..8)
p i # 4 4 4 4 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 8
sum = sum + i
redo if sum < 20
retry if sum < 100 and i == 7
end

sum
end
end
'

x = X.new
x.foo # 46