Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Test Decompiling a (basically) empty sub

This is in t/02-decompile because I realized I probably want some
tests for the basic packfile data structures in 01-packfile/
  • Loading branch information...
commit c1f27b1532294ed21f0bf5db87522ff0418f7b84 1 parent 7d6e739
Brian Gernhardt authored July 24, 2012
3  setup.winxed
@@ -89,7 +89,8 @@ function main[main](var argv) {
89 89
             'pbc_pir'          : {},
90 90
             'header_pbc'       : {},
91 91
             'installable_pbc'  : {},
92  
-            'inst_lib'         : []
  92
+            'inst_lib'         : [],
  93
+            'prove_files'      : 't/*.t t/*/*.t'
93 94
         };
94 95
 
95 96
         library_winxed(pact, 'PACT/Packfile');
135  t/02-decompile/01-empty_sub.t
... ...
@@ -0,0 +1,135 @@
  1
+#!winxed
  2
+
  3
+$include 't/common.winxed';
  4
+
  5
+function main[main]() {
  6
+    Rosella.Test.test(class EmptySubTest);
  7
+}
  8
+
  9
+class EmptySubTest {
  10
+    // This has a variety of tests based on compiling an empty sub
  11
+    // Most of what is "expected" was simply tested experimentally
  12
+    // These may change based on changes in IMCC
  13
+    function test_empty_sub() {
  14
+        var assert = self.assert;
  15
+
  16
+        // Get a PACT.Packfile
  17
+        var pact = decompile(compile(<<:
  18
+.namespace [] # workaround for IMCC bug
  19
+.sub 'empty_sub'
  20
+.end
  21
+:>>
  22
+        ));
  23
+
  24
+        // Some simple tests
  25
+        assert.is_null(pact.main, 'no main');
  26
+        assert.equal(0,  pact.uuid_type, 'no UUID type');
  27
+        assert.equal('', pact.uuid,      'no UUID');
  28
+
  29
+        // No floats
  30
+        assert.equal(0, elements(pact.floats), 'no floats');
  31
+
  32
+        // Two PMCs: 1 sub (empty_sub), 1 empty FIA for PCC
  33
+        assert.equal(2, elements(pact.pmcs), '2 PMCs');
  34
+        var fia;
  35
+        var sub;
  36
+        for (var pmc in pact.pmcs) {
  37
+            switch(typeof(pmc)) {
  38
+            case 'FixedIntegerArray':
  39
+                fia = pmc;
  40
+                break;
  41
+
  42
+            // XXX: At some point, this might be a PACT.Packfile.Subroutine
  43
+            case 'Sub':
  44
+                sub = pmc;
  45
+                break;
  46
+
  47
+            default:
  48
+                assert.fail('Unexpected PMC Constant');
  49
+            }
  50
+        }
  51
+
  52
+        assert.not_null(fia, 'got FIA');
  53
+        assert.equal(0, elements(fia), 'FIA is empty (PCC)');
  54
+
  55
+        assert.not_null(sub, 'got Sub');
  56
+        assert.equal('empty_sub', string(sub));
  57
+
  58
+        // 4 strings: filename, subname, empty, 'parrot'
  59
+        assert.equal(4, elements(pact.strings), '4 strings');
  60
+        var strings = {};
  61
+        int nulls;
  62
+        for (string s in pact.strings) {
  63
+            if(s == null)
  64
+                ++nulls; // hashes complain about storing nulls
  65
+            else
  66
+                strings[s] = 1;
  67
+        }
  68
+        assert.equal(1, nulls, '1 null string'); // XXX: Why?
  69
+        assert.equal(1, strings['parrot'],         'HLL namespace name');
  70
+        assert.equal(1, strings['empty_sub'],      'sub name');
  71
+        assert.equal(1, strings['(file unknown)'], 'file name');
  72
+
  73
+        // 1 oplib: core_ops
  74
+        assert.equal(1, elements(pact.oplibs), '1 oplib');
  75
+        var core_ops = pact.oplibs['core_ops'];
  76
+        assert.not_null(core_ops, 'have core_ops');
  77
+        assert.instance_of(core_ops, 'OpLib', 'core_ops is OpLib');
  78
+
  79
+        // Check namespaces
  80
+        assert.instance_of(pact.root, class PACT.Packfile.Namespace);
  81
+        assert.equal(1, elements(pact.root.contents), '1 object in root');
  82
+
  83
+        var parrot = pact.root.contents['parrot'];
  84
+        assert.not_null(parrot, 'have a parrot');
  85
+        assert.instance_of(parrot, class PACT.Packfile.Namespace);
  86
+        assert.equal(1, elements(parrot.contents), '1 object in parrot');
  87
+
  88
+        // Check sub
  89
+        var empty_sub = parrot.contents['empty_sub'];
  90
+        assert.not_null(empty_sub, 'have an empty_sub');
  91
+        assert.instance_of(empty_sub, class PACT.Packfile.Subroutine);
  92
+        assert.equal('empty_sub', empty_sub.name);
  93
+
  94
+        // Check ops
  95
+        assert.equal(5, elements(empty_sub.ops));
  96
+        var op;
  97
+        var arg;
  98
+
  99
+        // Debug w/ filename
  100
+        op = empty_sub.ops[0];
  101
+        assert.instance_of(op, class PACT.Packfile.Debug, 'got debug');
  102
+        assert.equal('(file unknown)', op.filename, 'have filename');
  103
+
  104
+        // Label for PC 0
  105
+        op = empty_sub.ops[1];
  106
+        assert.instance_of(op, class PACT.Packfile.Label, 'got Label 1');
  107
+        assert.equal('_0', op.name, 'is PC 0 label');
  108
+
  109
+        // set_returns []
  110
+        op = empty_sub.ops[2];
  111
+        assert.instance_of(op, class PACT.Packfile.Op, 'got Op 1');
  112
+        assert.equal('set_returns', op.name, 'PCC set_returns');
  113
+        assert.equal(1, elements(op.args), 'set_returns has 1 arg');
  114
+        arg = op.args[0];
  115
+        assert.instance_of(arg, class PACT.Packfile.Constant.Reference,
  116
+                'set_returns uses a constant');
  117
+        assert.equal(PARROT_ARG_PMC, arg.type, 'set_returns uses PMC const');
  118
+        arg = pact.pmcs[arg.value];
  119
+        assert.instance_of(arg, 'FixedIntegerArray', 'set_returns uses FIA');
  120
+        assert.equal(0, elements(arg), 'set_returns FIA empty');
  121
+
  122
+        // Label for PC 2
  123
+        op = empty_sub.ops[3];
  124
+        assert.instance_of(op, class PACT.Packfile.Label, 'got Label 2');
  125
+        assert.equal('_2', op.name, 'is PC 2 label');
  126
+
  127
+        // returncc
  128
+        op = empty_sub.ops[4];
  129
+        assert.instance_of(op, class PACT.Packfile.Op, 'got Op 2');
  130
+        assert.equal('returncc', op.name, 'PCC returncc');
  131
+        assert.equal(0, elements(op.args), 'returncc has no args');
  132
+    }
  133
+}
  134
+
  135
+# vim: se ft=winxed :

0 notes on commit c1f27b1

Please sign in to comment.
Something went wrong with that request. Please try again.