1: %%
    2: %% %CopyrightBegin%
    3: %%
    4: %% Copyright Ericsson AB 2005-2013. All Rights Reserved.
    5: %%
    6: %% The contents of this file are subject to the Erlang Public License,
    7: %% Version 1.1, (the "License"); you may not use this file except in
    8: %% compliance with the License. You should have received a copy of the
    9: %% Erlang Public License along with this software. If not, it can be
   10: %% retrieved online at http://www.erlang.org/.
   11: %%
   12: %% Software distributed under the License is distributed on an "AS IS"
   13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
   14: %% the License for the specific language governing rights and limitations
   15: %% under the License.
   16: %%
   17: %% %CopyrightEnd%
   18: %%
   19: -module(emacs_SUITE).
   20: 
   21: %%-define(line_trace, 1).
   22: 
   23: -export([all/0, init_per_testcase/2, end_per_testcase/2]).
   24: 
   25: -export([bif_highlight/1]).
   26: 
   27: all() -> 
   28:     [bif_highlight].
   29: 
   30: init_per_testcase(_Case, Config) ->
   31:     ErlangEl = filename:join([code:lib_dir(tools),"emacs","erlang.el"]),
   32:     case file:read_file_info(ErlangEl) of
   33: 	{ok, _} ->
   34: 	    [{el, ErlangEl}|Config];
   35: 	_ ->
   36: 	    {skip, "Could not find erlang.el"}
   37:     end.
   38: 
   39: end_per_testcase(_Case, _Config) ->
   40:     ok.
   41: 
   42: bif_highlight(Config) ->
   43:     ErlangEl = proplists:get_value(el,Config),
   44:     {ok, Bin} = file:read_file(ErlangEl),
   45: 
   46:     %% All auto-imported bifs
   47:     IntBifs = lists:usort(
   48: 		[F  || {F,A} <- erlang:module_info(exports),
   49: 		       erl_internal:bif(F,A)]),
   50: 
   51:     %% all bif which need erlang: prefix and are not operands
   52:     ExtBifs = lists:usort(
   53: 		[F  || {F,A} <- erlang:module_info(exports),
   54: 		       not erl_internal:bif(F,A) andalso
   55: 			   not is_atom(catch erl_internal:op_type(F,A))]),
   56: 
   57:     check_bif_highlight(Bin, <<"erlang-int-bifs">>, IntBifs),
   58:     check_bif_highlight(Bin, <<"erlang-ext-bifs">>, ExtBifs).
   59:     
   60: 
   61: check_bif_highlight(Bin, Tag, Compare) ->
   62:     [_H,IntMatch,_T] = 
   63: 	re:split(Bin,<<"defvar ",Tag/binary,
   64: 		       "[^(]*\\(([^)]*)">>,[]),
   65:     EmacsIntBifs = [list_to_atom(S) || 
   66: 		  S <- string:tokens(binary_to_list(IntMatch)," '\"\n")],
   67:     
   68:     ct:log("Emacs ~p",[EmacsIntBifs]),
   69:     ct:log("Int ~p",[Compare]),
   70: 
   71:     ct:log("Diff1 ~p",[Compare -- EmacsIntBifs]),
   72:     ct:log("Diff2 ~p",[EmacsIntBifs -- Compare]),
   73:     [] = Compare -- EmacsIntBifs,
   74:     [] = EmacsIntBifs -- Compare.
   75:     
   76: