test.ml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (*
  2. * Extc : C common OCaml bindings
  3. * Copyright (c)2004 Nicolas Cannasse
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  18. *)
  19. if Array.length Sys.argv > 1 then begin
  20. print_string Sys.argv.(1);
  21. flush stdout;
  22. prerr_string "ERROR";
  23. flush stderr;
  24. let input = Std.input_all stdin in
  25. print_string input;
  26. exit 66;
  27. end;
  28. prerr_endline "Start";
  29. prerr_endline (Extc.executable_path());
  30. let contents = Std.input_file "test.ml" in
  31. let s = Extc.unzip (Extc.zip contents) in
  32. if s <> contents then failwith "zip + unzip failed";
  33. let p = Process.run "test" [|"Hello"|] in
  34. let tmp = String.create 100 in
  35. let out = String.sub tmp 0 (Process.read_stdout p tmp 0 100) in
  36. if out <> "Hello" then failwith ("OUT=" ^ out ^ "#");
  37. let err = String.sub tmp 0 (Process.read_stderr p tmp 0 100) in
  38. if err <> "ERROR" then failwith ("ERR= " ^ err ^ "#");
  39. ignore(Process.write_stdin p "INPUT" 0 5);
  40. Process.close_stdin p;
  41. let out = String.sub tmp 0 (Process.read_stdout p tmp 0 100) in
  42. if out <> "INPUT" then failwith ("IN-OUT=" ^ out ^ "#");
  43. let code = Process.exit p in
  44. if code <> 66 then failwith ("EXIT=" ^ string_of_int code);
  45. Process.close p;
  46. prerr_endline "End";