Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  erlymock+eunit problems with file, ets

jwatte
Posted: Sat Oct 09, 2010 6:36 am Reply with quote
User Joined: 10 Feb 2010 Posts: 34
I've been using eunit and erlymock (the Jason Wagner version) for testing for a while, and overall, I think they work pretty well!

However, because erlymock uses temporary code replacement for named modules, you can't mock any module that erlymock in turn uses. And, because it uses the compiler to do its dirty work, this means you can't mock things like ets or file, or the internals will try to call the replaced version and badness ensues. (At least, that's what I think is happening)

Here are two cases:
Code:
some_test() ->
  erlymock:start(),
  erlymock:strict(file, delete, ["somename"], [{return, ok}]),
  erlymock:replay(),
  ok = my_function_that_calls_delete("somename"),
  ok = erlymock:verify().

another_test() ->
  erlymock:start(),
  erlymock:strict(ets, new, [some_table, '_'], [{return, some_table}]),
  erlymock:replay(),
  ok = my_function_that_calls_ets_new(),
  ok = erlymock_verify().


These cases will cause internal errors in erlymock and the subsystems it uses, rather than actually provide mocking for the given modules while testing the functions in question.

Does anyone have any good ideas about what to do about this?

Worst case, I think I can let it call the 'real' ets, because it's fairly fast and non-destructive (except for named tables), but for the file system, that's a lot harder. I really don't want to wrap all file system access into my own module...
View user's profile Send private message
jwatte
Posted: Tue Nov 09, 2010 5:56 am Reply with quote
User Joined: 10 Feb 2010 Posts: 34
What I ended up doing, for the functions I really must have tests for, is pass in the module name to use for file I/O as an argument.

Code:
my_fun(Whatever) ->
  file:somecall(...).

turns into

Code:
my_fun(Whatever) ->
  my_fun(Whatever, file).
my_fun(Whatever, File) ->
  File:somecall(...).


This allows me to mock an arbitrary module name in erlymock, and pass that in as the "File" module to use:

Code:
my_fun_test() ->
  erlymock:start(),
  erlymoc:strict(test_file, somecall, ...),
  erlymock:replay(),
  my_fun(whatever, test_file),
  erlymock:verify().


Not particularly elegant, and probably less efficient for the compiler, too, but testing and correctness has to go before elegance and performance...
View user's profile Send private message
wuji
Posted: Fri Sep 14, 2012 6:19 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
Regional Jail in Los Angeles, Villanueva said. Young was being held at at cheap jordans for sale at the same location on $1 million bail.MTV Reality 'Gangsta' Charged With
in MiamiBaron 'Dirty' Colon, Star of 'From G's to Gents,' Accused of of jordan concord of Killing ArtistBy RUSSELL GOLDMANJan 15, 2011— A two-bit "gangster" who appeared
a third-rate reality show is now charged with first degree murder.Baron "Dirty" "Dirty" jordan 11 "Dirty" Colon, a 24-year-old barber and finalist in the 2009 MTV program
G's to Gents," was arrested on Jan. 7 in connection with the the cheap jordan shoes the fatal armed robbery of a Florida artist in 2006.Colon appeared on
second season of the show, produced by actor Jamie Foxx, in which which [h4]jordan 11[/h4] which young men with checkered pasts -- so-called "g's" or "gangstas" --
to turn their lives around and become "gentlemen.""I got two kids. I I cheap designer *beep* I want to be in the gentleman's club because I want to
for them," Colon said in the season's first episode. "If I don't don't jordan 11 don't change, there's only going to be two things: prison or death."Prison
View user's profile Send private message
mbtshoes88
Posted: Wed Sep 19, 2012 8:46 am Reply with quote
User Joined: 18 Sep 2012 Posts: 30
Go backstage at DSquared2 Fall 2012 with designers Dean & Dan Caten Dsquared2 Shoes and top models Cara Delevingne and Bette Franke, Frida Aasen, Daphne Groenveld, Dsquared2 Sale Online Arizona Muse.Get the gorgeous beauty look that Dsquared2 Online makeup Dsquared2 Belts artist Charlotte Tilbury and hairstylist Sam McKnight created for the Dsquared2 Clothing show that was inspired by the 60′s and the icon of today, Cheap Dsquared2 Online Lana del Rey. Makeup artist Charlotte Tilbury gave the girls a gorgeous supermodel brow, and used Dsquared2 Clothing Sale thick black liner to create Cheap Dsquared2 a wing. She poured on the Dsquared2 Denim mascara and added two layers of lashes. Charlotte finished off the look using MAC Spice Lip liner and Dsquared2 Jeans FleshPot lipstick to give the girls that sexy Lana del Rey pout. “It’s all Dsquared2 Shop Online about the feline eye, the pouty lip and the Dsquared2 Outlet Sale lash“.DSquared2 fashion shows Cheap Dsquared2 Outlet are always one of the best shows of Milan Fashion Week. Dean & Dan always Dsquared2 Sale stage a show that is entertaining and full of beautiful clothes that Dsquared2 Store Online you actually want to own and wear. The concept behind their Fall Dsquared2 Online Sale 2012 fashion show is a 60′s ‘Back to School’ high school prom. As the boys told us backstage, Dsquared2 Outlet Online “these are rich kids with a bad Dsquared2 Outlet attitude“.Hear what top model Cara Delevingne and Anna Dello Russo, Vogue Japan Editor-at-Large think about this collection.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum