caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hans Ole Rafaelsen <hrafaelsen@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Include question
Date: Tue, 8 Nov 2011 16:03:04 +0100	[thread overview]
Message-ID: <CALs4vDb_XVKve3A3Dj5bsy1Ntsk2TnMvC6EPP4+LGd+1vqrNZQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1986 bytes --]

Hi,

I'm trying to create a mockup module to replace a network module when doing
testing.

The application consists of basically 3 parts. Some user interaction. This
calls some logic of the application, and the logic module might need to
call some other functions over the network. For testing I want to make a
mockup of the network module, in addition to synthesize the user
interaction. I want to test the logic module. The application has the
following files:

net_lib.ml:
let util_fun a = a
let foo a b = a + b
let bar a b = a - b

logic.ml:
let state = ref 0
let get_state () = !state
let do_op a b =
  incr state;
  (Net_lib.foo a b) * (Net_lib.bar (Net_lib.util_fun a) b )

main_appl.ml:
let () =
  let a, b  = Scanf.scanf  "%d %d\n" (fun a b -> a,b) in
  Printf.printf "Foo %d %d\n%!" (Logic.get_state ()) (Logic.do_op a b)

let () =
  let a, b  = Scanf.scanf  "%d %d\n" (fun a b -> a,b) in
  Printf.printf "Foo %d %d\n%!" (Logic.get_state ()) (Logic.do_op a b)


For testing I have the following modules:
net_lib_mockup.ml
include Net_lib
let foo a b = 1
let bar a b = 1

logic_mockup.ml:
module Net_lib = Net_lib_mockup
include Logic

main_test.ml:
module Logic = Logic_mockup

let () =
  let a, b = (1, 1) in
  Printf.printf "Test %d %d\n%!" (Logic.get_state ()) (Logic.do_op a b)

let () =
  let a, b = (10, 1) in
  Printf.printf "Test %d %d\n%!" (Logic.get_state ()) (Logic.do_op a b)

The problem is that the "include Logic" has already 'bound' the functions
in Logic to the Net_lib module and will not use the Net_lib_mockup that I
try to use through a moudle alias. If i replace the 'include Logic' with
the actual content of the logic.ml file, then the functions get bound to
the Logic_mockup functions, and the test works as they should.

Are there some trick to get the 'include Logic', in logic_mockup.ml, to use
to the Net_lib_mockup module and not the Net_lib module, so that I don't
have to do copy and paste between the two files?


Regards,

Hans Ole Rafaelsen

[-- Attachment #1.2: Type: text/html, Size: 2708 bytes --]

[-- Attachment #2: mockup.tgz --]
[-- Type: application/x-gzip, Size: 2842 bytes --]

             reply	other threads:[~2011-11-08 15:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-08 15:03 Hans Ole Rafaelsen [this message]
2011-11-08 15:10 ` Gabriel Scherer
2011-11-08 15:45   ` Hans Ole Rafaelsen
2011-11-08 15:50     ` Thomas Gazagnaire
2011-11-08 15:49   ` Alexandre Pilkiewicz
2011-11-09  7:29     ` Cedric Cellier
2011-11-09 15:41       ` Vincent Aravantinos
2011-11-09 15:50         ` Vincent Aravantinos
2011-11-09 16:29           ` rossberg
2011-11-09 17:08             ` Vincent Aravantinos
2011-11-09 23:36             ` Jacques Garrigue
2011-11-10 12:08               ` rossberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALs4vDb_XVKve3A3Dj5bsy1Ntsk2TnMvC6EPP4+LGd+1vqrNZQ@mail.gmail.com \
    --to=hrafaelsen@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).