"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/test/libponyc/finalisers.cc" (1 Nov 2019, 2923 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <gtest/gtest.h>
    2 #include <platform.h>
    3 
    4 #include "util.h"
    5 
    6 
    7 #define TEST_COMPILE(src) DO(test_compile(src, "final"))
    8 
    9 #define TEST_ERRORS_1(src, err1) \
   10   { const char* errs[] = {err1, NULL}; \
   11     DO(test_expected_errors(src, "final", errs)); }
   12 
   13 
   14 class FinalisersTest : public PassTest
   15 {};
   16 
   17 
   18 TEST_F(FinalisersTest, FinalCanCreatePrimitive)
   19 {
   20   const char* src =
   21     "primitive Prim\n"
   22     "primitive Foo\n"
   23     "  fun _final() =>\n"
   24     "    Prim";
   25 
   26   TEST_COMPILE(src);
   27 }
   28 
   29 TEST_F(FinalisersTest, FinalCannotCreateActor)
   30 {
   31   const char* src =
   32     "actor Actor\n"
   33     "primitive Foo\n"
   34     "  fun _final() =>\n"
   35     "    Actor";
   36 
   37   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   38 }
   39 
   40 TEST_F(FinalisersTest, FinalCannotCreateActorInBranch)
   41 {
   42   const char* src =
   43     "actor Actor\n"
   44     "primitive Foo\n"
   45     "  fun _final() =>\n"
   46     "    if false then None else Actor end";
   47 
   48   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   49 }
   50 
   51 TEST_F(FinalisersTest, FinalCannotCreateActorInTryBlock)
   52 {
   53   const char* src =
   54     "actor Actor\n"
   55     "primitive Foo\n"
   56     "  fun _final() =>\n"
   57     "    try Actor; error end";
   58 
   59   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   60 }
   61 
   62 TEST_F(FinalisersTest, FinalCannotCallBehaviour)
   63 {
   64   const char* src =
   65     "actor Actor\n"
   66     "  be apply() => None\n"
   67     "class Foo\n"
   68     "  let a: Actor = Actor\n"
   69     "  fun _final() =>\n"
   70     "    a()";
   71 
   72   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   73 }
   74 
   75 TEST_F(FinalisersTest, FinalCannotCallBehaviourInBranch)
   76 {
   77   const char* src =
   78     "actor Actor\n"
   79     "  be apply() => None\n"
   80     "class Foo\n"
   81     "  let a: Actor = Actor\n"
   82     "  fun _final() =>\n"
   83     "    if true then a() end";
   84 
   85   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   86 }
   87 
   88 TEST_F(FinalisersTest, FinalCannotCallBehaviourInTryElseBlock)
   89 {
   90   const char* src =
   91     "actor Actor\n"
   92     "  be apply() => None\n"
   93     "class Foo\n"
   94     "  let a: Actor = Actor\n"
   95     "  fun _final() =>\n"
   96     "    try error else a() end";
   97 
   98   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
   99 }
  100 
  101 TEST_F(FinalisersTest, FinalCannotCallChainedBehaviour)
  102 {
  103   const char* src =
  104     "actor Actor\n"
  105     "  be apply() => None\n"
  106     "class Foo\n"
  107     "  let a: Actor = Actor\n"
  108     "  fun _final() =>\n"
  109     "    a.>apply()";
  110 
  111   TEST_ERRORS_1(src, "_final cannot create actors or send messages");
  112 }
  113 
  114 TEST_F(FinalisersTest, CannotLookupFinal)
  115 {
  116   const char* src =
  117     "class Actor\n"
  118     "  fun apply() =>\n"
  119     "    _final()\n"
  120     "  fun _final() =>\n"
  121     "    None";
  122 
  123   TEST_ERRORS_1(src, "can't lookup a _final function");
  124 }
  125 
  126 TEST_F(FinalisersTest, CannotLookupPrimitiveInit)
  127 {
  128   const char* src =
  129     "primitive Prim\n"
  130     "  fun apply() =>\n"
  131     "    _init()\n"
  132     "  fun _init() =>\n"
  133     "    None";
  134 
  135   TEST_ERRORS_1(src, "can't lookup an _init function on a primitive");
  136 }