Browse Source

Move test for read-only data to new separate test source treadonlydata.pp

git-svn-id: trunk@42747 -
pierre 6 years ago
parent
commit
c406d0121e
3 changed files with 49 additions and 12 deletions
  1. 1 0
      .gitattributes
  2. 0 12
      tests/test/tarray15.pp
  3. 48 0
      tests/test/treadonlydata.pp

+ 1 - 0
.gitattributes

@@ -15065,6 +15065,7 @@ tests/test/trange3.pp svneol=native#text/plain
 tests/test/trange4.pp svneol=native#text/plain
 tests/test/trange5.pp svneol=native#text/plain
 tests/test/trangeob.pp svneol=native#text/plain
+tests/test/treadonlydata.pp svneol=native#text/pascal
 tests/test/trecreg.pp svneol=native#text/plain
 tests/test/trecreg2.pp svneol=native#text/plain
 tests/test/trecreg3.pp svneol=native#text/plain

+ 0 - 12
tests/test/tarray15.pp

@@ -1,10 +1,5 @@
 program tarray15;
 
-{$define target_supports_rodata}
-{$if defined(msdos) or defined(hasamiga) or defined(atari) or defined(palmos)}
-{$undef target_supports_rodata}
-{$endif}
-
 {$mode  objfpc}
 
 { needed for "except" to work }
@@ -84,13 +79,6 @@ begin
     Halt(17);
   if not specialize CheckArray<LongInt>(rc1, [1, 2, 3]) then
     Halt(18);
-{$ifdef target_supports_rodata}
-  try
-    rc1[1] := 42;
-    Halt(19);
-  except
-  end;
-{$endif}
   if not specialize CheckArray<LongInt>(wc1, [1, 2, 3]) then
     Halt(20);
   wc1[1] := 42;

+ 48 - 0
tests/test/treadonlydata.pp

@@ -0,0 +1,48 @@
+program treadonlydata;
+
+{$define target_supports_rodata}
+{$if defined(msdos) or defined(hasamiga) or defined(atari) or defined(palmos)}
+{$undef target_supports_rodata}
+{$endif}
+
+{$mode  objfpc}
+
+{ needed for "except" to work }
+uses
+  SysUtils;
+
+{$push}
+{$J-}
+const
+  rc1: array of LongInt = (1, 2, 3);
+{$J+}
+const
+  wc1: array of LongInt = (1, 2, 3);
+{$pop}
+
+
+begin
+{$ifdef target_supports_rodata}
+  try
+    rc1[1] := 42;
+    writeln('Error: Trying to write read-only data did not generate an exception');
+    Halt(1);
+  except
+    writeln('Trying to write read-only data generated exception');
+  end;
+{$else}
+  try
+    rc1[1] := 42;
+    writeln('Trying to write read-only data did not generate an exception, as expected');
+  except
+    writeln('Trying to write read-only data generated exception, while system is supposed not to support this');
+    halt(2);
+  end;
+{$endif}
+  try
+    wc1[1] := 42;
+  except
+    writeln('Error: Trying to write normal data generated exception');
+    halt(3);
+  end;
+end.