raz / test / host / Host.raz

46 lines · 1.1 KiB · raw · history · last change 7a137131

1(* A compiler host for test/compiler-host.sh: the library is where the
2 environment's RAZ_TEST_LIBRARY says, raz run is refused and a program
3 that uses C is not made. With RAZ_TEST_WRITE=refuse the executable
4 can't be written. Linux still supplies the runtime and the files. *)
5module Host;
6import Sys, Files;
7
8type
9 CLib* = (none, glibc, musl); (* as raz's Host.raz has it *)
10
11const
12 RunRefused: ERROR = "this test host cannot run programs";
13 CannotWrite = "refuse"; (* RAZ_TEST_WRITE's value that fails the write *)
14
15(* The library the test sets up *)
16proc libraryDir*: []const U8;
17begin
18 return Sys.env("RAZ_TEST_LIBRARY");
19end;
20
21(* No C *)
22proc cLibrary*: CLib;
23begin
24 return none;
25end;
26
27(* The file written as it is, or not at all when the test says so *)
28proc writeExecutable*(path, data: []const U8): BOOL;
29begin
30 if Sys.env("RAZ_TEST_WRITE") = CannotWrite then return false; end;
31 return Files.write(path, data) and (Sys.chmod(path, 1EDH) >= 0);
32end;
33
34(* Refused *)
35proc prepareRun*: ([]const U8, ERROR);
36begin
37 return "", RunRefused;
38end;
39
40(* Never reached, since prepareRun refuses *)
41proc execute*(_path: []const U8; _first: INT): INT;
42begin
43 return -38;
44end;
45
46end Host.