librelist archives

« back to archive

Tests for constants

Tests for constants

From:
Volker Mische
Date:
2011-11-25 @ 00:44
Hi,

as I patched the constants to allow all uppercase ones, I thought it's a
good idea to write some tests. But I hit some problems. The AST looks
different as it uses the line number of the original line where the
constant was defined, not where it was used.

Here's an example of what I tried:
    tu:test_mod_ast("$const = 3\n\nbar = fn () {\n io.format(\"~p\",
[$const])\n}\n",
        "-module(temp).\n-export([]).\nbar() ->\nio:format(\"~p\",
[3]).\n", "temp")

The important difference in the result is:
{cons,4,{integer,1,3},{nil,4}}
vs.
{cons,4,{integer,4,3},{nil,4}}

I'm not sure what the correct solution for the problem is :)

Cheers,
  Volker

Re: [efene] Tests for constants

From:
Mariano Guerra
Date:
2011-11-25 @ 10:15
On Fri, Nov 25, 2011 at 1:44 AM, Volker Mische <volker.mische@gmail.com> wrote:
> Hi,
>
> as I patched the constants to allow all uppercase ones, I thought it's a
> good idea to write some tests. But I hit some problems. The AST looks
> different as it uses the line number of the original line where the
> constant was defined, not where it was used.
>
> Here's an example of what I tried:
>    tu:test_mod_ast("$const = 3\n\nbar = fn () {\n io.format(\"~p\",
> [$const])\n}\n",
>        "-module(temp).\n-export([]).\nbar() ->\nio:format(\"~p\",
> [3]).\n", "temp")
>
> The important difference in the result is:
> {cons,4,{integer,1,3},{nil,4}}
> vs.
> {cons,4,{integer,4,3},{nil,4}}
>
> I'm not sure what the correct solution for the problem is :)

the correct solution wasn't implemented :D

I just commited a fix for that


https://github.com/marianoguerra/efene/commit/2539233a3e8f9d228908ea48eaa3545913d080ca

when it replaces a constant it replaces the line in the constant
expression for the line where it's being inserted

there are still complex expressions that aren't handled (functions,
list comprehensions, if/try/case etc) they are easy to add but I'm
abusing work time :P

regarding tests, we should move to a more automatized testing, until
now I run the tests and grep for "error:" I think we can do one of two
things:

 * create a simple tests lib for efene
 * move the tests to erlang and use eunit

eunit can't be used in efene because it uses macros
moving to eunit would be easy but I don't know what it says about the
language if we don't test it in itself :D

what do you think?

example code:

$number = 1
$string = "asd"
$tuple = (1, true, atom, "string", [], [1, 1.2])

@public
run = fn ()
    io.format("~p, ~p ~p~n", [
        $number,
        $string,
        $tuple])

mariano@ganesha:~$ fnc test.ifn
Compiling test.ifn

mariano@ganesha:~$ fnc -r test run
1, "asd" {1,true,atom,"string",[],[1,1.2]}

mariano@ganesha:~$ fnc -t mod test.ifn
[{attribute,1,module,test},
 {attribute,2,export,[{run,0}]},
 {function,7,run,0,
     [{clause,7,[],[],
          [{call,8,
               {remote,8,{atom,8,io},{atom,8,format}},
               [{string,8,"~p, ~p ~p~n"},
                {cons,8,
                    {integer,9,1},
                    {cons,10,
                        {string,10,"asd"},
                        {cons,11,
                            {tuple,11,
                                [{integer,11,1},
                                 {atom,11,true},
                                 {atom,11,atom},
                                 {string,11,"string"},
                                 {nil,11},
                                 {cons,11,
                                     {integer,11,1},
                                     {cons,11,{float,11,1.2},{nil,11}}}]},
                            {nil,11}}}}]}]}]}]

mariano@ganesha:~$ fnc -t erl test.ifn
-module(test).

-export([run/0]).

run() ->
    io:format("~p, ~p ~p~n",
              [1, "asd",
               {1, true, atom, "string", [],
                [1, 1.19999999999999995559]}]).

Re: [efene] Tests for constants

From:
Volker Mische
Date:
2011-11-25 @ 11:24
On 11/25/2011 11:15 AM, Mariano Guerra wrote:
> On Fri, Nov 25, 2011 at 1:44 AM, Volker Mische <volker.mische@gmail.com> wrote:
>> Hi,
>>
>> as I patched the constants to allow all uppercase ones, I thought it's a
>> good idea to write some tests. But I hit some problems. The AST looks
>> different as it uses the line number of the original line where the
>> constant was defined, not where it was used.
>>
>> Here's an example of what I tried:
>>    tu:test_mod_ast("$const = 3\n\nbar = fn () {\n io.format(\"~p\",
>> [$const])\n}\n",
>>        "-module(temp).\n-export([]).\nbar() ->\nio:format(\"~p\",
>> [3]).\n", "temp")
>>
>> The important difference in the result is:
>> {cons,4,{integer,1,3},{nil,4}}
>> vs.
>> {cons,4,{integer,4,3},{nil,4}}
>>
>> I'm not sure what the correct solution for the problem is :)
> 
> the correct solution wasn't implemented :D
> 
> I just commited a fix for that
> 
> 
https://github.com/marianoguerra/efene/commit/2539233a3e8f9d228908ea48eaa3545913d080ca
> 
> when it replaces a constant it replaces the line in the constant
> expression for the line where it's being inserted
> 
> there are still complex expressions that aren't handled (functions,
> list comprehensions, if/try/case etc) they are easy to add but I'm
> abusing work time :P

Thanks for fixing it.

> regarding tests, we should move to a more automatized testing, until
> now I run the tests and grep for "error:" I think we can do one of two
> things:
> 
>  * create a simple tests lib for efene
>  * move the tests to erlang and use eunit
> 
> eunit can't be used in efene because it uses macros
> moving to eunit would be easy but I don't know what it says about the
> language if we don't test it in itself :D
> 
> what do you think?

Wouldn't it make sense to have macro support in Efene? I think one goal
should be full interoperability with Erlang. Other than that, have you
heard of Etap before [1]? It's used by CouchDB and GeoCouch.

I'm not sure how much work a testing framework in Efene would be. I
don't want to waste time, but on the other hand it would be to find bugs
in the language itself.

[1] https://github.com/ngerakines/etap

Cheers,
  Volker