anchor.diff:  -include_lib("eunit/include/eunit.hrl").
   
   %% Server state
  --record(state, {port :: port(),
  +-record(state, {port :: port() | {inactive, tuple()},
                   name :: term(),
                   messages,
                   log_tref :: timer:tref(),
  
positive.code:     ?log_error("Got unexpected exit signal from port: ~p. Exiting.", [Exit]),
      {stop, Reason, State}.
  
  handle_call(unhandled, unhandled, unhandled) ->
      erlang:exit(unhandled).
  
  handle_cast(unhandled, unhandled) ->
      erlang:exit(unhandled).
  
negative.code: init(Fun) ->
      {Name, _Cmd, _Args, Opts} = Params = Fun(),
      process_flag(trap_exit, true), % Make sure terminate gets called
      Opts2 = proplists:delete(port_server_send_eol, proplists:delete(port_server_dont_start, Opts)),
      SendEOL = proplists:get_value(port_server_send_eol, Opts),
      DontStart = proplists:get_bool(port_server_dont_start, Opts),
      Params2 = erlang:setelement(4, Params, Opts2),
      Port = case DontStart of
                 false -> open_port(Params2);
                 true -> {inactive, Params2}
             end,
      {ok, #state{port = Port, name = Name, send_eol = SendEOL,
                  messages = ringbuffer:new(?NUM_MESSAGES)}}.
  
  handle_info({send_to_port, Msg}, #state{port = P} = State) when not is_port(P) ->
      ?log_debug("Got send_to_port when there's no port running yet. Will kill myself."),
      {stop, {unexpected_send_to_port, {send_to_port, Msg}}, State};
  handle_info({send_to_port, Msg}, State) ->
      ?log_debug("Sending the following to port: ~p", [Msg]),
      port_command(State#state.port, Msg),
  