develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34360 - in trunk/languages/ecmascript: config/makefiles lib lib/Parrot lib/Parrot/Test lib/Parrot/Test/JS src/builtin src/classes src/parser t t/js_pt t/sanity_js t/sanity_pt

From:
tewk
Date:
December 25, 2008 14:17
Subject:
[svn:parrot] r34360 - in trunk/languages/ecmascript: config/makefiles lib lib/Parrot lib/Parrot/Test lib/Parrot/Test/JS src/builtin src/classes src/parser t t/js_pt t/sanity_js t/sanity_pt
Message ID:
20081225221652.66A62CBA12@x12.develooper.com
Author: tewk
Date: Thu Dec 25 14:16:50 2008
New Revision: 34360

Added:
   trunk/languages/ecmascript/lib/
   trunk/languages/ecmascript/lib/Parrot/
   trunk/languages/ecmascript/lib/Parrot/Test/
   trunk/languages/ecmascript/lib/Parrot/Test/JS/
   trunk/languages/ecmascript/lib/Parrot/Test/JS.pm
   trunk/languages/ecmascript/lib/Parrot/Test/JS/PJS.pm
   trunk/languages/ecmascript/lib/Parrot/Test/JS/SpiderMonkey.pm
   trunk/languages/ecmascript/t/js_pt/   (props changed)
   trunk/languages/ecmascript/t/js_pt/10-version.t
   trunk/languages/ecmascript/t/sanity_js/
   trunk/languages/ecmascript/t/sanity_pt/   (props changed)
   trunk/languages/ecmascript/t/sanity_pt/00-literals.t
   trunk/languages/ecmascript/t/sanity_pt/01-vars.t
   trunk/languages/ecmascript/t/sanity_pt/03-boolean.t   (contents, props changed)
      - copied, changed from r34337, /trunk/languages/ecmascript/t/03-boolean.t
   trunk/languages/ecmascript/t/sanity_pt/05-objects.t
Removed:
   trunk/languages/ecmascript/t/03-boolean.t
Modified:
   trunk/languages/ecmascript/config/makefiles/root.in
   trunk/languages/ecmascript/src/builtin/builtins.pir
   trunk/languages/ecmascript/src/classes/Boolean.pir
   trunk/languages/ecmascript/src/parser/actions.pm
   trunk/languages/ecmascript/t/harness

Log:
[js] start of a test suite


Modified: trunk/languages/ecmascript/config/makefiles/root.in
==============================================================================
--- trunk/languages/ecmascript/config/makefiles/root.in	(original)
+++ trunk/languages/ecmascript/config/makefiles/root.in	Thu Dec 25 14:16:50 2008
@@ -133,7 +133,7 @@
 	@echo ""
 
 test: all
-	$(PERL) t/harness t
+	$(PERL) t/harness
 
 testclean:
 	$(RM_F) "t/*.js" "t/*.out"

Added: trunk/languages/ecmascript/lib/Parrot/Test/JS.pm
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/lib/Parrot/Test/JS.pm	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,64 @@
+# $Id: JS.pm 34193 2008-12-21 11:50:25Z bernhard $
+
+# Copyright (C) 2008, The Perl Foundation.
+
+package Parrot::Test::JS;
+
+# pragmata
+use strict;
+use warnings;
+
+use Data::Dumper;
+use File::Basename;
+use File::Spec;
+
+use Parrot::Test;
+use Parrot::Test::JS::SpiderMonkey;
+use Parrot::Test::JS::PJS;
+
+=head1 NAME
+
+Test/JS.pm - Testing routines specific to 'js'.
+
+=head1 DESCRIPTION
+
+Call 'js.pbc' and 'js'.
+
+=head1 METHODS
+
+=head2 new
+
+A kind of factory, that finds the proper subclass of Parrot::Test::JS.
+
+Use the executable B<js> in smoke testing.
+
+=cut
+
+sub new {
+    my $test_module =  $ENV{PARROT_PIPP_TEST_MODULE} || 'Parrot::Test::JS::PJS';
+
+    return bless {}, $test_module;
+}
+
+sub get_cd {
+    my $self = shift;
+    my ( $options ) = @_;
+
+    return File::Spec->catdir( $self->{relpath}, 'languages', 'ecmascript' );
+}
+
+sub get_lang_fn {
+    my $self = shift;
+    my ( $count, $options ) = @_;
+
+    return Parrot::Test::per_test( '.js', $count );
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/lib/Parrot/Test/JS/PJS.pm
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/lib/Parrot/Test/JS/PJS.pm	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,49 @@
+# $Id: PJS.pm 34192 2008-12-21 11:41:29Z bernhard $
+
+# Copyright (C) 2008, The Perl Foundation.
+
+package Parrot::Test::JS::PJS;
+
+# pragmata
+use strict;
+use warnings;
+
+use base 'Parrot::Test::JS';
+
+# Generate output_is(), output_isnt() and output_like() in current package.
+Parrot::Test::generate_languages_functions();
+
+sub get_out_fn {
+    my $self = shift;
+    my ( $count, $options ) = @_;
+
+    return Parrot::Test::per_test( '_pjs.out', $count );
+}
+
+# Use JS on the command line
+sub get_test_prog {
+    my $self = shift;
+    my ( $count, $options ) = @_;
+
+    my $lang_fn = Parrot::Test::per_test( '.js', $count );
+    $lang_fn =~ s!^js/!!; # fix for unified languages testing
+
+    return "$self->{relpath}/parrot $self->{relpath}/languages/ecmascript/js.pbc ${lang_fn}";
+}
+
+# never skip the reference implementation
+sub skip_why {
+    my $self = shift;
+    my ($options) = @_;
+
+    return;
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/lib/Parrot/Test/JS/SpiderMonkey.pm
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/lib/Parrot/Test/JS/SpiderMonkey.pm	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,48 @@
+# $Id: SpiderMonkey.pm 29200 2008-07-09 14:40:19Z bernhard $
+
+# Copyright (C) 2008, The Perl Foundation.
+
+package Parrot::Test::JS::SpiderMonkey;
+
+# pragmata
+use strict;
+use warnings;
+
+use base 'Parrot::Test::JS';
+
+# Generate output_is(), output_isnt() and output_like() in current package.
+Parrot::Test::generate_languages_functions();
+
+sub get_out_fn {
+    my $self = shift;
+    my ( $count, $options ) = @_;
+
+    return Parrot::Test::per_test( '_js.out', $count );
+}
+
+# Use SpiderMonkey on the command line
+sub get_test_prog {
+    my $self = shift;
+    my ( $count, $options ) = @_;
+
+    my $lang_fn = Parrot::Test::per_test( '.js', $count );
+
+    return "js $lang_fn";
+}
+
+# never skip the reference implementation
+sub skip_why {
+    my $self = shift;
+    my ($options) = @_;
+
+    return;
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Modified: trunk/languages/ecmascript/src/builtin/builtins.pir
==============================================================================
--- trunk/languages/ecmascript/src/builtin/builtins.pir	(original)
+++ trunk/languages/ecmascript/src/builtin/builtins.pir	Thu Dec 25 14:16:50 2008
@@ -120,6 +120,16 @@
 ## built-in operators
 ##
 
+.sub 'prefix:?' :multi(_)
+    .param pmc a
+    if a goto a_true
+    $P0 = get_hll_global ['JSBoolean'], 'false'
+    .return ($P0)
+  a_true:
+    $P0 = get_hll_global ['JSBoolean'], 'true'
+    .return ($P0)
+.end
+
 .sub 'infix:='
     .param pmc lhs
     .param pmc rhs
@@ -235,7 +245,7 @@
     .param pmc left
     .param pmc right
     iseq $I0, left, right
-    .return ($I0)
+    .tailcall 'prefix:?'($I0)
 .end
 
 

Modified: trunk/languages/ecmascript/src/classes/Boolean.pir
==============================================================================
--- trunk/languages/ecmascript/src/classes/Boolean.pir	(original)
+++ trunk/languages/ecmascript/src/classes/Boolean.pir	Thu Dec 25 14:16:50 2008
@@ -43,6 +43,13 @@
   .return ("false")
 .end
 
+.sub 'get_integer1' #:vtable
+  .param pmc self
+   $I0 = self
+  .return ($I0)
+.end
+
+
 .sub 'ACCEPTS' :method
     .param pmc topic
     .return (self)

Modified: trunk/languages/ecmascript/src/parser/actions.pm
==============================================================================
--- trunk/languages/ecmascript/src/parser/actions.pm	(original)
+++ trunk/languages/ecmascript/src/parser/actions.pm	Thu Dec 25 14:16:50 2008
@@ -650,21 +650,18 @@
 
 method true($/) {
     # XXX change this into type a ECMAScript type, 'Boolean' or whatever
-#    make PAST::Val.new( :returns('Integer'), :value('1'), :node($/) );
     make PAST::Var.new( :name(~$/), :namespace('JSBoolean'), :scope('package'), :node($/) );
-
 }
 
 method false($/) {
     # XXX change this into type 'Boolean' or whatever
-#    make PAST::Val.new( :returns('Integer'), :value('0'), :node($/) );
     make PAST::Var.new( :name(~$/), :namespace('JSBoolean'), :scope('package'), :node($/) );
 }
 
 method null($/) {
     # XXX would this work?
-    make PAST::Var.new( :name('null'), :scope('package'), :node($/) );
-#    make PAST::Var.new( :name(~$/), :namespace('Null'), :node($/) );
+    #make PAST::Var.new( :name('null'), :scope('package'), :node($/) );
+    make PAST::Var.new( :name('null'), :namespace('JSNull'), :scope('package'), :node($/) );
 }
 
 method object_literal($/) {

Modified: trunk/languages/ecmascript/t/harness
==============================================================================
--- trunk/languages/ecmascript/t/harness	(original)
+++ trunk/languages/ecmascript/t/harness	Thu Dec 25 14:16:50 2008
@@ -1,10 +1,168 @@
 #! perl
-
 # $Id$
 
-use FindBin;
-use lib qw( . lib ../lib ../../lib ../../lib );
-use Parrot::Test::Harness language => 'JS', compiler => 'js.pbc';
+=head1 NAME
+
+languages/ecmascript/t/harness - A harness for JS
+
+=head1 SYNOPSIS
+
+  cd languages && perl ecmascript/t/harness --files --master
+
+  cd languages/ecmascript && perl t/harness 
+
+  cd languages/ecmascript && perl t/harness --verbose t/hello.t 
+
+=head1 DESCRIPTION
+
+If I'm called with a single
+argument of "--files", I just return a list of files to process.
+This list is one per line, and is relative to the languages dir.
+
+If I'm called with no args, I run the complete suite.
+
+Otherwise I run the tests that were passed on the command line.
+
+=cut
+
+# pragmata
+use strict;
+use warnings;
+use FindBin ();
+use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin/../lib";
+
+use Cwd                     ();
+use File::Spec              ();
+use TAP::Harness            3.12;     # support closures for the 'exec' option
+use TAP::Harness::Archive   0.12; 
+use Parrot::Config          qw( %PConfig );
+use Getopt::Long;
+use Parrot::Harness::Smoke;
+use Parrot::Test;
+
+my ( $files_flag, $master_flag, $send_to_smolder_flag, $archive_flag, $verbose_flag );
+my ( $js_flag, $pjs_flag);
+GetOptions(
+    'files'           => \$files_flag,
+    'master'          => \$master_flag,          # unused, but passed by languages/t/harness
+    'send-to-smolder' => \$send_to_smolder_flag,
+    'archive'         => \$archive_flag,
+    'verbose'         => \$verbose_flag,
+    'with-pjs'        => \$pjs_flag,
+    'with-js'         => \$js_flag,
+);
+
+my $hll = 'ecmascript';
+my $verbosity = $verbose_flag ? 1 : $ENV{HARNESS_VERBOSE};
+$verbosity ||= 0;
+
+if ( $files_flag ) {
+    # Only the Makefile in 'parrot/languages' uses --files for unified testing
+    my $dir = File::Spec->catfile( $hll, 't' );
+    # unified testing can't handle test scripts written in JS
+    my @files = grep { ! m!in_php|pmc|embed! } glob( File::Spec->catfile( $dir, '*/*.t' ) );
+    print join( "\n", @files );
+    print "\n" if scalar(@files);
+}
+else { 
+    my $path_to_parrot = Parrot::Test::path_to_parrot();
+    my @cmd = ( "$path_to_parrot/parrot$PConfig{exe}", "$path_to_parrot/languages/ecmascript/js.pbc" );
+    $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::JS::PJS';
+
+    if ( $js_flag ) { 
+         $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::JS::SpiderMonkey';
+         @cmd = qw{ js } ;
+    }
+    elsif ( $pjs_flag ) {
+        $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::JS::PJS';
+    }
+
+    my @files;
+    if ( scalar(@ARGV) ) {
+        # Someone specified tests for me to run.
+        @files = grep { -f $_ } @ARGV
+    }
+    else {
+        ( undef, undef, my $current_dir ) = File::Spec->splitpath( Cwd::getcwd() );
+        if ( $current_dir eq 'languages' ) {
+            @files = glob( File::Spec->catfile( $hll, 't', '*/*.t' ) );
+        }
+        elsif ( $current_dir eq $hll ) {
+            @files = glob( File::Spec->catfile( 't', '*/*.t' ) );
+            print glob( File::Spec->catfile( 't', '*.t' ) );
+            push @files, glob( File::Spec->catfile( 't', '*.t' ) );
+        }
+        else {
+            die "Where am I?";
+        }
+    }
+
+    my $exec_sub
+        = sub {
+              my ( $harness, $test_file ) = @_;
+
+              # the directory t/embed contains only PIR test files
+              return [ "$path_to_parrot/parrot$PConfig{exe}", $test_file ] if $test_file =~ m{t/embed/.*[.]t$};
+
+              # the directory t/pmc contains only PIR test files
+              return [ "$path_to_parrot/parrot$PConfig{exe}", $test_file ] if $test_file =~ m{t/pmc/.*[.]t$};
+
+              # the directory t/in_php contains only test scripts written in JS
+              return [ @cmd, $test_file ] if $test_file =~ m{t/sanity_js/.*[.]t$};
+              if ($test_file =~ m{^t/(?:[^/])*\.t$!}) {
+                print "$test_file\n";
+                return [ @cmd, $test_file ];
+              }
+
+
+              # all other directories contain test scripts written in Perl
+              return [ $PConfig{perl}, $test_file ];
+          };  
+    if ( $archive_flag ) { 
+        my %env_data = Parrot::Harness::Smoke::collect_test_environment_data();
+       
+        my $report_file = ['js_test_run.tar.gz'];
+        my $harness = TAP::Harness::Archive->new(
+            {
+                exec             => $exec_sub,
+                verbosity        => $verbosity,
+                archive          => $report_file->[0],
+                merge            => 1,
+                extra_properties => \%env_data,
+            }
+        );
+        $harness->runtests(@files);
+
+        if ( $send_to_smolder_flag ) {
+            $env_data{report_file} = $report_file;
+            $env_data{project_id}  = 10;
+            Parrot::Harness::Smoke::send_archive_to_smolder(%env_data);
+        }
+    } else {
+       my $harness = TAP::Harness->new(
+           {
+               exec       => $exec_sub,
+               verbosity  => $verbosity,
+           }
+       );
+        $harness->runtests(@files);
+    }
+}
+
+=head1 SEE ALSO
+
+  F<languages/perl6/t/harness>
+
+=head1 AUTHOR
+
+Bernhard Schmalhofer - <Bernhard.Schmalhofer@gmx.de>
+Kevin Tew - <tewk at tewk dot com>
+
+=cut
 
-# Set up PERL6LIB environment path so the "use" tests can find libraries
-# $ENV{PERL6LIB} = "$Bin/01-sanity";
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/js_pt/10-version.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/10-version.t	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: null.t 33314 2008-11-28 16:28:50Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 2;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'version builtin' );
+function a() {
+}
+print(typeof version);
+print(version(150));
+print(version);
+print((typeof version) == (typeof a));
+CODE
+function
+0
+version
+true
+OUT
+
+todo: {
+language_output_is( 'JS', <<'CODE', <<'OUT', 'version global', todo => 'need to wrap parrot subs');
+print(version);
+CODE
+function version() {
+    [native code]
+}
+OUT
+}
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/sanity_pt/00-literals.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/sanity_pt/00-literals.t	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 03-boolean.t 33314 2008-11-28 16:28:50Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 3;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'number literals' );
+print(1);
+print(-1);
+print(100);
+print(-100);
+print(0);
+CODE
+1
+-1
+100
+-100
+0
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'string literals' );
+print("Hello");
+print("Bye");
+CODE
+Hello
+Bye
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'float literals' );
+print(1.0);
+print(1.1);
+CODE
+1
+1.1
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
+

Added: trunk/languages/ecmascript/t/sanity_pt/01-vars.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/sanity_pt/01-vars.t	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 03-boolean.t 33314 2008-11-28 16:28:50Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 3;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'number var' );
+var a = 1;
+print(a);
+CODE
+1
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'string var' );
+var b = "Hello";
+print(b);
+CODE
+Hello
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'printing booleans' );
+var c = 1.1;
+print(c);
+CODE
+1.1
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
+

Copied: trunk/languages/ecmascript/t/sanity_pt/03-boolean.t (from r34337, /trunk/languages/ecmascript/t/03-boolean.t)
==============================================================================
--- /trunk/languages/ecmascript/t/03-boolean.t	(original)
+++ trunk/languages/ecmascript/t/sanity_pt/03-boolean.t	Thu Dec 25 14:16:50 2008
@@ -1,3 +1,46 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 3;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'basic booleans' );
+print(true == true);
+print(false == false);
+print(true == false);
+print(false == true);
+CODE
+true
+true
+false
+false
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'basic booleans', todo => 'get_integer on JSBoolean leads to eternal recursion' );
+print(true + 1);
+print(false + 1);
+CODE
+2
+1
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'printing booleans' );
 print(true);
 print(false);
+CODE
+true
+false
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
 

Added: trunk/languages/ecmascript/t/sanity_pt/05-objects.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/sanity_pt/05-objects.t	Thu Dec 25 14:16:50 2008
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 03-boolean.t 33314 2008-11-28 16:28:50Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 3;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'empty object', todo => 'toString broken' );
+var a = {};
+print(a);
+CODE
+[object Object]
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'object with primitive fields', todo => 'fields broken' );
+var a = { 0: 1, 1: 2, };
+print(a);
+CODE
+[object Object]
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'nested objects', todo => 'fields broken' );
+var a = { a: { aa: "duh" },
+          b: { bb: "huh" },
+          c: { cc: "wuh" },
+          };
+print(a);
+CODE
+[object Object]
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
+



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About