aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/stdlib/doc/src/filename.xml156
-rw-r--r--lib/stdlib/src/filename.erl160
-rw-r--r--lib/stdlib/test/filename_SUITE.erl1110
3 files changed, 953 insertions, 473 deletions
diff --git a/lib/stdlib/doc/src/filename.xml b/lib/stdlib/doc/src/filename.xml
index 77e262dbe6..65009753f3 100644
--- a/lib/stdlib/doc/src/filename.xml
+++ b/lib/stdlib/doc/src/filename.xml
@@ -47,7 +47,12 @@
<p>The module supports raw file names in the way that if a binary is present, or the file name cannot be interpreted according to the return value of
<seealso marker="kernel:file#native_name_encoding/0">file:native_name_encoding/0</seealso>, a raw file name will also be returned. For example filename:join/1 provided with a path component being a binary (and also not being possible to interpret under the current native file name encoding) will result in a raw file name being returned (the join operation will have been performed of course). For more information about raw file names, see the <seealso marker="kernel:file">file</seealso> module.</p>
</description>
-
+ <datatypes>
+ <datatype>
+ <name name="basedir_type"/>
+ </datatype>
+ </datatypes>
+
<funcs>
<func>
<name name="absname" arity="1"/>
@@ -102,6 +107,155 @@
</desc>
</func>
<func>
+ <name name="basedir" arity="2"/>
+ <fsummary>Equivalent to <c>basedir(<anno>Type</anno>,<anno>Application</anno>,#{})</c>.</fsummary>
+ <desc>
+ <p>
+ Equivalent to <seealso marker="#basedir-3">
+ basedir(<anno>Type</anno>, <anno>Application</anno>, #{})</seealso>.
+ </p>
+ </desc>
+ </func>
+ <func>
+ <name name="basedir" arity="3"/>
+ <fsummary></fsummary>
+ <desc><marker id="basedir-3"/>
+ <p>
+ Returns a suitable path, or paths, for a given type.
+ If <c>os</c> is not set in <c><anno>Opts</anno></c> the function will default to
+ the native option, i.e. <c>'linux'</c>, <c>'darwin'</c> or <c>'windows'</c>, as understood
+ by <c>os:type/0</c>. Anything not recognized as <c>'darwin'</c> or <c>'windows'</c> is
+ interpreted as <c>'linux'</c>.</p>
+ <p>
+ The options <c>'author'</c> and <c>'version'</c> are only used with <c>'windows'</c> option mode.
+ </p>
+ <list type="bulleted">
+ <item><c>user_cache</c>
+ <p>The path location is intended for transient data files on a local machine.</p>
+ <p>
+ On Linux:
+ Respects the os environment variable <c>XDG_CACHE_HOME</c>.
+ </p>
+ <pre>
+1> <input>filename:basedir(user_cache, "my_application", #{os=>linux}).</input>
+"/home/otptest/.cache/my_application"</pre>
+ On Darwin: <pre>
+1> <input>filename:basedir(user_cache, "my_application", #{os=>darwin}).</input>
+"/home/otptest/Library/Caches/my_application"</pre>
+ On Windows: <pre>
+1> <input>filename:basedir(user_cache, "My App").</input>
+"c:/Users/otptest/AppData/Local/My App/Cache"
+2> <input>filename:basedir(user_cache, "My App").</input>
+"c:/Users/otptest/AppData/Local/My App/Cache"
+3> <input>filename:basedir(user_cache, "My App", #{author=>"Erlang"}).</input>
+"c:/Users/otptest/AppData/Local/Erlang/My App/Cache"
+4> <input>filename:basedir(user_cache, "My App", #{version=>"1.2"}).</input>
+"c:/Users/otptest/AppData/Local/My App/1.2/Cache"
+5> <input>filename:basedir(user_cache, "My App", #{author=>"Erlang",version=>"1.2"}).</input>
+"c:/Users/otptest/AppData/Local/Erlang/My App/1.2/Cache"</pre>
+ </item>
+ <item><c>user_config</c>
+ <p>
+ The path location is intended for persistent configuration files.
+ </p>
+ <p>
+ On Linux:
+ Respects the os environment variable <c>XDG_CONFIG_HOME</c>.
+ </p>
+ <pre>
+2> <input>filename:basedir(user_config, "my_application", #{os=>linux}).</input>
+"/home/otptest/.config/my_application"</pre>
+ On Darwin:<pre>
+2> <input>filename:basedir(user_config, "my_application", #{os=>darwin}).</input>
+"/home/otptest/Library/Application Support/my_application"</pre>
+ On Windows:<pre>
+1> <input>filename:basedir(user_config, "My App").</input>
+"c:/Users/otptest/AppData/Roaming/My App"
+2> <input>filename:basedir(user_config, "My App", #{author=>"Erlang", version=>"1.2"}).</input>
+"c:/Users/otptest/AppData/Roaming/Erlang/My App/1.2"</pre>
+ </item>
+ <item><c>user_data</c>
+ <p>
+ The path location is intended for persistent data files.
+ </p>
+ <p>
+ On Linux:
+ Respects the os environment variable <c>XDG_DATA_HOME</c>.
+ </p>
+ <pre>
+3> <input>filename:basedir(user_data, "my_application", #{os=>linux}).</input>
+"/home/otptest/.local/my_application"</pre>
+ On Darwin:<pre>
+3> <input>filename:basedir(user_data, "my_application", #{os=>darwin}).</input>
+"/home/otptest/Library/Application Support/my_application"</pre>
+ On Windows:<pre>
+8> <input>filename:basedir(user_data, "My App").</input>
+"c:/Users/otptest/AppData/Local/My App"
+9> <input>filename:basedir(user_data, "My App",#{author=>"Erlang",version=>"1.2"}).</input>
+"c:/Users/otptest/AppData/Local/Erlang/My App/1.2"</pre>
+ </item>
+ <item><c>user_log</c>
+ <p>The path location is intended for transient log files on a local machine.</p>
+ <p>
+ On Linux:
+ Respects the os environment variable <c>XDG_CACHE_HOME</c>.</p>
+ <pre>
+4> <input>filename:basedir(user_log, "my_application", #{os=>linux}).</input>
+"/home/otptest/.cache/my_application/log"</pre>
+ On Darwin:<pre>
+4> <input>filename:basedir(user_log, "my_application", #{os=>darwin}).</input>
+"/home/otptest/Library/Caches/my_application"</pre>
+ On Windows:<pre>
+12> <input>filename:basedir(user_log, "My App").</input>
+"c:/Users/otptest/AppData/Local/My App/Logs"
+13> <input>filename:basedir(user_log, "My App",#{author=>"Erlang",version=>"1.2"}).</input>
+"c:/Users/otptest/AppData/Local/Erlang/My App/1.2/Logs"</pre>
+ </item>
+ <item><c>site_config</c><p>
+ On Linux:
+ Respects the os environment variable <c>XDG_CONFIG_DIRS</c>.</p>
+<pre>
+5> <input>filename:basedir(site_data, "my_application", #{os=>linux}).</input>
+["/usr/local/share/my_application",
+ "/usr/share/my_application"]
+6> <input>os:getenv("XDG_CONFIG_DIRS").</input>
+"/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg"
+7> <input>filename:basedir(site_config, "my_application", #{os=>linux}).</input>
+["/etc/xdg/xdg-ubuntu/my_application",
+ "/usr/share/upstart/xdg/my_application",
+ "/etc/xdg/my_application"]
+8> <input>os:unsetenv("XDG_CONFIG_DIRS").</input>
+true
+9> <input>filename:basedir(site_config, "my_application", #{os=>linux}).</input>
+["/etc/xdg/my_application"]</pre>
+ On Darwin:<pre>
+5> <input>filename:basedir(site_config, "my_application", #{os=>darwin}).</input>
+["/Library/Application Support/my_application"]</pre>
+ </item>
+ <item><c>site_data</c><p>
+ On Linux:
+ Respects the os environment variable <c>XDG_DATA_DIRS</c>.</p>
+ <pre>
+10> <input>os:getenv("XDG_DATA_DIRS").</input>
+"/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/"
+11> <input>filename:basedir(site_data, "my_application", #{os=>linux}).</input>
+["/usr/share/ubuntu/my_application",
+ "/usr/share/gnome/my_application",
+ "/usr/local/share/my_application",
+ "/usr/share/my_application"]
+12> <input>os:unsetenv("XDG_DATA_DIRS").</input>
+true
+13> <input>filename:basedir(site_data, "my_application", #{os=>linux}).</input>
+["/usr/local/share/my_application",
+ "/usr/share/my_application"]</pre>
+ On Darwin:<pre>
+5> <input>filename:basedir(site_data, "my_application", #{os=>darwin}).</input>
+["/Library/Application Support/my_application"]</pre>
+ </item>
+ </list>
+ </desc>
+ </func>
+ <func>
<name name="basename" arity="1"/>
<fsummary>Return the last component of a filename</fsummary>
<desc>
diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl
index 008beb8b67..d921a69108 100644
--- a/lib/stdlib/src/filename.erl
+++ b/lib/stdlib/src/filename.erl
@@ -36,6 +36,7 @@
extension/1, join/1, join/2, pathtype/1,
rootname/1, rootname/2, split/1, nativename/1]).
-export([find_src/1, find_src/2, flatten/1]).
+-export([basedir/2, basedir/3]).
%% Undocumented and unsupported exports.
-export([append/2]).
@@ -139,6 +140,7 @@ absname_join(AbsBase, Name) ->
-spec basename(Filename) -> file:filename_all() when
Filename :: file:name_all().
+
basename(Name) when is_binary(Name) ->
case os:type() of
{win32,_} ->
@@ -954,3 +956,161 @@ filename_string_to_binary(List) ->
Bin
end.
+%% Application Base Directories
+%% basedir
+%% http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+
+-type basedir_type() :: 'user_cache' | 'user_config' | 'user_data'
+ | 'user_log'
+ | 'site_config' | 'site_data'.
+
+-spec basedir(Type,Application) -> file:filename_all() when
+ Type :: basedir_type(),
+ Application :: string() | binary().
+
+basedir(Type,Application) when is_atom(Type), is_list(Application) orelse
+ is_binary(Application) ->
+ basedir(Type, Application, #{}).
+
+-spec basedir(Type,Application,Opts) -> file:filename_all() when
+ Type :: basedir_type(),
+ Application :: string() | binary(),
+ Opts :: #{author => string() | binary(),
+ os => 'windows' | 'darwin' | 'linux',
+ version => string() | binary()}.
+
+basedir(Type,Application,Opts) when is_atom(Type), is_map(Opts),
+ is_list(Application) orelse
+ is_binary(Application) ->
+ Os = basedir_os_from_opts(Opts),
+ Name = basedir_name_from_opts(Os,Application,Opts),
+ Base = basedir_from_os(Type,Os),
+ case {Type,Os} of
+ {user_log,linux} ->
+ filename:join([Base,Name,"log"]);
+ {user_log,windows} ->
+ filename:join([Base,Name,"Logs"]);
+ {user_cache,windows} ->
+ filename:join([Base,Name,"Cache"]);
+ {Type,_} when Type =:= site_config orelse Type =:= site_data ->
+ [filename:join([B,Name]) || B <- Base];
+ _ ->
+ filename:join([Base,Name])
+ end.
+
+basedir_os_from_opts(#{os := linux}) -> linux;
+basedir_os_from_opts(#{os := windows}) -> windows;
+basedir_os_from_opts(#{os := darwin}) -> darwin;
+basedir_os_from_opts(#{}) -> basedir_os_type().
+
+basedir_name_from_opts(windows,App,#{author:=Author,version:=Vsn}) ->
+ filename:join([Author,App,Vsn]);
+basedir_name_from_opts(windows,App,#{author:=Author}) ->
+ filename:join([Author,App]);
+basedir_name_from_opts(_,App,#{version:=Vsn}) ->
+ filename:join([App,Vsn]);
+basedir_name_from_opts(_,App,_) ->
+ App.
+
+basedir_from_os(Type,Os) ->
+ case Os of
+ linux -> basedir_linux(Type);
+ darwin -> basedir_darwin(Type);
+ windows -> basedir_windows(Type)
+ end.
+
+-define(basedir_linux_user_data, ".local/share").
+-define(basedir_linux_user_config, ".config").
+-define(basedir_linux_user_cache, ".cache").
+-define(basedir_linux_user_log, ".cache"). %% .cache/App/log
+-define(basedir_linux_site_data, "/usr/local/share/:/usr/share/").
+-define(basedir_linux_site_config, "/etc/xdg").
+
+basedir_linux(Type) ->
+ case Type of
+ user_data -> getenv("XDG_DATA_HOME", ?basedir_linux_user_data, true);
+ user_config -> getenv("XDG_CONFIG_HOME",?basedir_linux_user_config,true);
+ user_cache -> getenv("XDG_CACHE_HOME", ?basedir_linux_user_cache, true);
+ user_log -> getenv("XDG_CACHE_HOME", ?basedir_linux_user_log, true);
+ site_data ->
+ Base = getenv("XDG_DATA_DIRS",?basedir_linux_site_data,false),
+ string:tokens(Base,":");
+ site_config ->
+ Base = getenv("XDG_CONFIG_DIRS",?basedir_linux_site_config,false),
+ string:tokens(Base,":")
+ end.
+
+-define(basedir_darwin_user_data, "Library/Application Support").
+-define(basedir_darwin_user_config, "Library/Application Support").
+-define(basedir_darwin_user_cache, "Library/Caches").
+-define(basedir_darwin_user_log, "Library/Logs").
+-define(basedir_darwin_site_data, "/Library/Application Support").
+-define(basedir_darwin_site_config, "/Library/Application Support").
+
+basedir_darwin(Type) ->
+ case Type of
+ user_data -> basedir_join_home(?basedir_darwin_user_data);
+ user_config -> basedir_join_home(?basedir_darwin_user_config);
+ user_cache -> basedir_join_home(?basedir_darwin_user_cache);
+ user_log -> basedir_join_home(?basedir_darwin_user_log);
+ site_data -> [?basedir_darwin_site_data];
+ site_config -> [?basedir_darwin_site_config]
+ end.
+
+%% On Windows:
+%% ex. C:\Users\egil\AppData\Local\Ericsson\Erlang
+%% %LOCALAPPDATA% is defined on Windows 7 and onwards
+%% %APPDATA% is used instead of %LOCALAPPDATA% if it's not defined.
+%% %APPDATA% is used for roaming, i.e. for user_config on Windows 7 and beyond.
+%%
+%% user_data %LOCALAPPDATA%[/$author]/$appname[/$version]
+%% user_config %APPDATA%[/$author]/$appname[/$version]
+%% user_cache %LOCALAPPDATA%[/$author]/$appname[/$version]/Cache
+%% user_log %LOCALAPPDATA%[/$author]/$appname[/$version]/Logs
+
+basedir_windows(Type) ->
+ %% If LOCALAPPDATA is not defined we are likely on an
+ %% XP machine. Use APPDATA instead.
+ AppData = basedir_windows_appdata(),
+ case Type of
+ user_data -> getenv("LOCALAPPDATA", AppData);
+ user_config -> AppData;
+ user_cache -> getenv("LOCALAPPDATA", AppData);
+ user_log -> getenv("LOCALAPPDATA", AppData);
+ site_data -> [];
+ site_config -> []
+ end.
+
+basedir_windows_appdata() ->
+ case os:getenv("APPDATA") of
+ Invalid when Invalid =:= false orelse Invalid =:= [] ->
+ erlang:error(noappdata);
+ Val -> Val
+ end.
+
+%% basedir aux
+
+getenv(K,Def,false) -> getenv(K,Def);
+getenv(K,Def,true) -> getenv(K,basedir_join_home(Def)).
+
+getenv(K,Def) ->
+ case os:getenv(K) of
+ [] -> Def;
+ false -> Def;
+ Val -> Val
+ end.
+
+basedir_join_home(Dir) ->
+ case os:getenv("HOME") of
+ false ->
+ {ok,[[Home]]} = init:get_argument(home),
+ filename:join(Home,Dir);
+ Home -> filename:join(Home,Dir)
+ end.
+
+basedir_os_type() ->
+ case os:type() of
+ {unix,darwin} -> darwin;
+ {win32,_} -> windows;
+ _ -> linux
+ end.
diff --git a/lib/stdlib/test/filename_SUITE.erl b/lib/stdlib/test/filename_SUITE.erl
index 8ecbc7eadf..7f2e4771f3 100644
--- a/lib/stdlib/test/filename_SUITE.erl
+++ b/lib/stdlib/test/filename_SUITE.erl
@@ -28,21 +28,29 @@
basename_bin_1/1, basename_bin_2/1,
dirname_bin/1, extension_bin/1, join_bin/1, t_nativename_bin/1]).
-export([pathtype_bin/1,rootname_bin/1,split_bin/1]).
+-export([t_basedir_api/1, t_basedir_xdg/1, t_basedir_windows/1]).
-include_lib("common_test/include/ct.hrl").
suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
- [absname, absname_2, basename_1, basename_2, dirname,
- extension,
- join, pathtype, rootname, split, t_nativename, find_src,
- absname_bin, absname_bin_2, basename_bin_1, basename_bin_2, dirname_bin,
- extension_bin,
- join_bin, pathtype_bin, rootname_bin, split_bin, t_nativename_bin].
+ [absname, absname_2,
+ find_src,
+ absname_bin, absname_bin_2,
+ {group,p},
+ t_basedir_xdg, t_basedir_windows].
groups() ->
- [].
+ [{p, [parallel],
+ [dirname,
+ extension, extension_bin,
+ join, pathtype, rootname, split, t_nativename,
+ basename_1, basename_2,
+ basename_bin_1, basename_bin_2, dirname_bin,
+ join_bin, pathtype_bin, rootname_bin, split_bin,
+ t_nativename_bin,
+ t_basedir_api]}].
init_per_suite(Config) ->
Config.
@@ -61,58 +69,59 @@ end_per_group(_GroupName, Config) ->
absname(Config) when is_list(Config) ->
case os:type() of
- {win32, _} ->
- ?line [Drive|_] = ?config(priv_dir, Config),
- ?line Temp = filename:join([Drive|":/"], "temp"),
- ?line case file:make_dir(Temp) of
- ok -> ok;
- {error,eexist} -> ok
- end,
- ?line {ok,Cwd} = file:get_cwd(),
- ?line ok = file:set_cwd(Temp),
- ?line [Drive|":/temp/foo"] = filename:absname(foo),
- ?line [Drive|":/temp/foo"] = filename:absname("foo"),
- ?line [Drive|":/temp/../ebin"] = filename:absname("../ebin"),
- ?line [Drive|":/erlang"] = filename:absname("/erlang"),
- ?line [Drive|":/erlang/src"] = filename:absname("/erlang/src"),
- ?line [Drive|":/erlang/src"] = filename:absname("\\erlang\\src"),
- ?line [Drive|":/temp/erlang"] = filename:absname([Drive|":erlang"]),
- ?line [Drive|":/temp/erlang/src"] =
- filename:absname([Drive|":erlang/src"]),
- ?line [Drive|":/temp/erlang/src"] =
- filename:absname([Drive|":erlang\\src\\"]),
- ?line "a:/erlang" = filename:absname("a:erlang"),
-
- ?line file:set_cwd([Drive|":/"]),
- ?line [Drive|":/foo"] = filename:absname(foo),
- ?line [Drive|":/foo"] = filename:absname("foo"),
- ?line [Drive|":/../ebin"] = filename:absname("../ebin"),
- ?line [Drive|":/erlang"] = filename:absname("/erlang"),
- ?line [Drive|":/erlang/src"] = filename:absname("/erlang/src"),
- ?line [Drive|":/erlang/src"] = filename:absname(["/erlang",'/src']),
- ?line [Drive|":/erlang/src"] = filename:absname("\\erlang\\\\src"),
- ?line [Drive|":/erlang"] = filename:absname([Drive|":erlang"]),
- ?line [Drive|":/erlang/src"] = filename:absname([Drive|":erlang/src"]),
- ?line "a:/erlang" = filename:absname("a:erlang"),
-
- ?line file:set_cwd(Cwd),
- ok;
- {unix, _} ->
- ?line ok = file:set_cwd("/usr"),
- ?line "/usr/foo" = filename:absname(foo),
- ?line "/usr/foo" = filename:absname("foo"),
- ?line "/usr/../ebin" = filename:absname("../ebin"),
- ?line file:set_cwd("/"),
- ?line "/foo" = filename:absname(foo),
- ?line "/foo" = filename:absname("foo"),
- ?line "/../ebin" = filename:absname("../ebin"),
- ?line "/erlang" = filename:absname("/erlang"),
- ?line "/erlang/src" = filename:absname("/erlang/src"),
- ?line "/erlang/src" = filename:absname(["/erl",'ang/s',"rc"]),
- ?line "/erlang/src" = filename:absname(["/erl",'a','ng',"/",'s',"rc"]),
- ?line "/erlang/src" = filename:absname("/erlang///src"),
- ?line "/file_sorter.erl" = filename:absname([file_sorter|'.erl']),
- ok
+ {win32, _} ->
+ [Drive|_] = ?config(priv_dir, Config),
+ Temp = filename:join([Drive|":/"], "temp"),
+ case file:make_dir(Temp) of
+ ok -> ok;
+ {error,eexist} -> ok
+ end,
+ {ok,Cwd} = file:get_cwd(),
+ ok = file:set_cwd(Temp),
+ [Drive|":/temp/foo"] = filename:absname(foo),
+ [Drive|":/temp/foo"] = filename:absname("foo"),
+ [Drive|":/temp/../ebin"] = filename:absname("../ebin"),
+ [Drive|":/erlang"] = filename:absname("/erlang"),
+ [Drive|":/erlang/src"] = filename:absname("/erlang/src"),
+ [Drive|":/erlang/src"] = filename:absname("\\erlang\\src"),
+ [Drive|":/temp/erlang"] = filename:absname([Drive|":erlang"]),
+ [Drive|":/temp/erlang/src"] =
+ filename:absname([Drive|":erlang/src"]),
+ [Drive|":/temp/erlang/src"] =
+ filename:absname([Drive|":erlang\\src\\"]),
+ "a:/erlang" = filename:absname("a:erlang"),
+
+ file:set_cwd([Drive|":/"]),
+ [Drive|":/foo"] = filename:absname(foo),
+ [Drive|":/foo"] = filename:absname("foo"),
+ [Drive|":/../ebin"] = filename:absname("../ebin"),
+ [Drive|":/erlang"] = filename:absname("/erlang"),
+ [Drive|":/erlang/src"] = filename:absname("/erlang/src"),
+ [Drive|":/erlang/src"] = filename:absname(["/erlang",'/src']),
+ [Drive|":/erlang/src"] = filename:absname("\\erlang\\\\src"),
+ [Drive|":/erlang"] = filename:absname([Drive|":erlang"]),
+ [Drive|":/erlang/src"] = filename:absname([Drive|":erlang/src"]),
+ "a:/erlang" = filename:absname("a:erlang"),
+
+ file:set_cwd(Cwd),
+ ok;
+ {unix, _} ->
+ ok = file:set_cwd("/usr"),
+ "/usr/foo" = filename:absname(foo),
+ "/usr/foo" = filename:absname("foo"),
+ "/usr/../ebin" = filename:absname("../ebin"),
+
+ file:set_cwd("/"),
+ "/foo" = filename:absname(foo),
+ "/foo" = filename:absname("foo"),
+ "/../ebin" = filename:absname("../ebin"),
+ "/erlang" = filename:absname("/erlang"),
+ "/erlang/src" = filename:absname("/erlang/src"),
+ "/erlang/src" = filename:absname(["/erl",'ang/s',"rc"]),
+ "/erlang/src" = filename:absname(["/erl",'a','ng',"/",'s',"rc"]),
+ "/erlang/src" = filename:absname("/erlang///src"),
+ "/file_sorter.erl" = filename:absname([file_sorter|'.erl']),
+ ok
end.
@@ -120,125 +129,123 @@ absname(Config) when is_list(Config) ->
absname_2(Config) when is_list(Config) ->
case os:type() of
- {win32, _} ->
- ?line [Drive|_] = ?config(priv_dir, Config),
- ?line [Drive|":/temp/foo"] = filename:absname(foo, [Drive|":/temp"]),
- ?line [Drive|":/temp/foo"] = filename:absname("foo", [Drive|":/temp"]),
- ?line [Drive|":/temp/../ebin"] = filename:absname("../ebin",
- [Drive|":/temp"]),
- ?line [Drive|":/erlang"] = filename:absname("/erlang", [Drive|":/temp"]),
- ?line [Drive|":/erlang/src"] = filename:absname("/erlang/src",
- [Drive|":/temp"]),
- ?line [Drive|":/erlang/src"] = filename:absname("\\erlang\\src",
- [Drive|":/temp"]),
- ?line [Drive|":/temp/erlang"] = filename:absname([Drive|":erlang"],
- [Drive|":/temp"]),
- ?line [Drive|":/temp/erlang/src"] = filename:absname([Drive|":erlang/src"],
- [Drive|":/temp"]),
- ?line [Drive|":/temp/erlang/src"] =
- filename:absname([Drive|":erlang\\src\\"], [Drive|":/temp"]),
- ?line "a:/erlang" = filename:absname("a:erlang", [Drive|":/temp"]),
-
- ?line file:set_cwd([Drive|":/"]),
- ?line [Drive|":/foo"] = filename:absname(foo, [Drive|":/"]),
- ?line [Drive|":/foo"] = filename:absname("foo", [Drive|":/"]),
- ?line [Drive|":/../ebin"] = filename:absname("../ebin", [Drive|":/"]),
- ?line [Drive|":/erlang"] = filename:absname("/erlang", [Drive|":/"]),
- ?line [Drive|":/erlang/src"] = filename:absname("/erlang/src",
- [Drive|":/"]),
- ?line [Drive|":/erlang/src"] = filename:absname("\\erlang\\\\src",
- [Drive|":/"]),
- ?line [Drive|":/erlang"] = filename:absname([Drive|":erlang"],
- [Drive|":/"]),
- ?line [Drive|":/erlang/src"] = filename:absname([Drive|":erlang/src"],
- [Drive|":/"]),
- ?line "a:/erlang" = filename:absname("a:erlang", [Drive|":/"]),
-
- ok;
- _ ->
- ?line "/usr/foo" = filename:absname(foo, "/usr"),
- ?line "/usr/foo" = filename:absname("foo", "/usr"),
- ?line "/usr/../ebin" = filename:absname("../ebin", "/usr"),
-
- ?line "/foo" = filename:absname(foo, "/"),
- ?line "/foo" = filename:absname("foo", "/"),
- ?line "/../ebin" = filename:absname("../ebin", "/"),
- ?line "/erlang" = filename:absname("/erlang", "/"),
- ?line "/erlang/src" = filename:absname("/erlang/src", "/"),
- ?line "/erlang/src" = filename:absname("/erlang///src", "/"),
- ok
+ {win32, _} ->
+ [Drive|_] = ?config(priv_dir, Config),
+ [Drive|":/temp/foo"] = filename:absname(foo, [Drive|":/temp"]),
+ [Drive|":/temp/foo"] = filename:absname("foo", [Drive|":/temp"]),
+ [Drive|":/temp/../ebin"] = filename:absname("../ebin",
+ [Drive|":/temp"]),
+ [Drive|":/erlang"] = filename:absname("/erlang", [Drive|":/temp"]),
+ [Drive|":/erlang/src"] = filename:absname("/erlang/src",
+ [Drive|":/temp"]),
+ [Drive|":/erlang/src"] = filename:absname("\\erlang\\src",
+ [Drive|":/temp"]),
+ [Drive|":/temp/erlang"] = filename:absname([Drive|":erlang"],
+ [Drive|":/temp"]),
+ [Drive|":/temp/erlang/src"] = filename:absname([Drive|":erlang/src"],
+ [Drive|":/temp"]),
+ [Drive|":/temp/erlang/src"] =
+ filename:absname([Drive|":erlang\\src\\"], [Drive|":/temp"]),
+ "a:/erlang" = filename:absname("a:erlang", [Drive|":/temp"]),
+
+ file:set_cwd([Drive|":/"]),
+ [Drive|":/foo"] = filename:absname(foo, [Drive|":/"]),
+ [Drive|":/foo"] = filename:absname("foo", [Drive|":/"]),
+ [Drive|":/../ebin"] = filename:absname("../ebin", [Drive|":/"]),
+ [Drive|":/erlang"] = filename:absname("/erlang", [Drive|":/"]),
+ [Drive|":/erlang/src"] = filename:absname("/erlang/src",
+ [Drive|":/"]),
+ [Drive|":/erlang/src"] = filename:absname("\\erlang\\\\src",
+ [Drive|":/"]),
+ [Drive|":/erlang"] = filename:absname([Drive|":erlang"],
+ [Drive|":/"]),
+ [Drive|":/erlang/src"] = filename:absname([Drive|":erlang/src"],
+ [Drive|":/"]),
+ "a:/erlang" = filename:absname("a:erlang", [Drive|":/"]),
+
+ ok;
+ _ ->
+ "/usr/foo" = filename:absname(foo, "/usr"),
+ "/usr/foo" = filename:absname("foo", "/usr"),
+ "/usr/../ebin" = filename:absname("../ebin", "/usr"),
+
+ "/foo" = filename:absname(foo, "/"),
+ "/foo" = filename:absname("foo", "/"),
+ "/../ebin" = filename:absname("../ebin", "/"),
+ "/erlang" = filename:absname("/erlang", "/"),
+ "/erlang/src" = filename:absname("/erlang/src", "/"),
+ "/erlang/src" = filename:absname("/erlang///src", "/"),
+ ok
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
basename_1(Config) when is_list(Config) ->
- ?line Dog = test_server:timetrap(test_server:seconds(10)),
- ?line "." = filename:basename("."),
- ?line "foo" = filename:basename("foo"),
- ?line "foo" = filename:basename("/usr/foo"),
- ?line "foo.erl" = filename:basename("A:usr/foo.erl"),
- ?line "foo" = filename:basename('/usr/foo'),
- ?line "foo" = filename:basename(["/usr","/","f","o","o"]),
- ?line "foo" = filename:basename(["/usr/",foo]),
- ?line "foo" = filename:basename(["/usr/f",oo]),
- ?line "foo" = filename:basename(["usr/", "foo"]),
- ?line "foo" = filename:basename(["usr/"|foo]),
- ?line "foo" = filename:basename(["usr/foo/"]),
- ?line case os:type() of
- {win32, _} ->
- ?line "foo" = filename:basename(["usr\\foo\\"]),
- ?line "foo" = filename:basename("A:\\usr\\foo"),
- ?line "foo" = filename:basename("A:foo");
- _ ->
- ?line "strange\\but\\true" =
- filename:basename("strange\\but\\true")
- end,
- ?line test_server:timetrap_cancel(Dog),
+ Dog = test_server:timetrap(test_server:seconds(10)),
+ "." = filename:basename("."),
+ "foo" = filename:basename("foo"),
+ "foo" = filename:basename("/usr/foo"),
+ "foo.erl" = filename:basename("A:usr/foo.erl"),
+ "foo" = filename:basename('/usr/foo'),
+ "foo" = filename:basename(["/usr","/","f","o","o"]),
+ "foo" = filename:basename(["/usr/",foo]),
+ "foo" = filename:basename(["/usr/f",oo]),
+ "foo" = filename:basename(["usr/", "foo"]),
+ "foo" = filename:basename(["usr/"|foo]),
+ "foo" = filename:basename(["usr/foo/"]),
+ case os:type() of
+ {win32, _} ->
+ "foo" = filename:basename(["usr\\foo\\"]),
+ "foo" = filename:basename("A:\\usr\\foo"),
+ "foo" = filename:basename("A:foo");
+ _ ->
+ "strange\\but\\true" =
+ filename:basename("strange\\but\\true")
+ end,
+ test_server:timetrap_cancel(Dog),
ok.
basename_2(Config) when is_list(Config) ->
- ?line Dog = test_server:timetrap(test_server:seconds(10)),
- ?line "." = filename:basename(".", ".erl"),
- ?line "foo" = filename:basename("foo.erl", ".erl"),
- ?line "foo" = filename:basename('foo.erl', ".erl"),
- ?line "foo" = filename:basename("foo.erl", '.erl'),
- ?line "foo" = filename:basename(["/usr","/","f","oo"], ".erl"),
- ?line "foo.erl" = filename:basename("/usr/foo.erl", ".hrl"),
- ?line "foo.erl" = filename:basename("/usr.hrl/foo.erl", ".hrl"),
- ?line "foo" = filename:basename("/usr.hrl/foo", ".hrl"),
- ?line "foo" = filename:basename("usr/foo/", ".erl"),
- ?line "foo.erl" = filename:basename("usr/foo.erl/", ".erl"),
- ?line "foo.erl" = filename:basename("usr/foo.erl/", '.erl'),
- ?line "foo" = filename:basename(["/usr",'/','f','oo'], ".erl"),
- ?line "foo.erl" = filename:basename(["usr/foo.e",'rl/'], ".erl"),
- ?line case os:type() of
- {win32, _} ->
- ?line "foo" = filename:basename("A:foo", ".erl"),
- ?line "foo.erl" = filename:basename("a:\\usr\\foo.erl",
- ".hrl"),
- ?line "foo.erl" = filename:basename("c:\\usr.hrl\\foo.erl",
- ".hrl"),
- ?line "foo" = filename:basename("A:\\usr\\foo", ".hrl");
- _ ->
- ?line "strange\\but\\true" =
- filename:basename("strange\\but\\true.erl", ".erl"),
- ?line "strange\\but\\true" =
- filename:basename("strange\\but\\true", ".erl")
- end,
- ?line test_server:timetrap_cancel(Dog),
+ Dog = test_server:timetrap(test_server:seconds(10)),
+ "." = filename:basename(".", ".erl"),
+ "foo" = filename:basename("foo.erl", ".erl"),
+ "foo" = filename:basename('foo.erl', ".erl"),
+ "foo" = filename:basename("foo.erl", '.erl'),
+ "foo" = filename:basename(["/usr","/","f","oo"], ".erl"),
+ "foo.erl" = filename:basename("/usr/foo.erl", ".hrl"),
+ "foo.erl" = filename:basename("/usr.hrl/foo.erl", ".hrl"),
+ "foo" = filename:basename("/usr.hrl/foo", ".hrl"),
+ "foo" = filename:basename("usr/foo/", ".erl"),
+ "foo.erl" = filename:basename("usr/foo.erl/", ".erl"),
+ "foo.erl" = filename:basename("usr/foo.erl/", '.erl'),
+ "foo" = filename:basename(["/usr",'/','f','oo'], ".erl"),
+ "foo.erl" = filename:basename(["usr/foo.e",'rl/'], ".erl"),
+ case os:type() of
+ {win32, _} ->
+ "foo" = filename:basename("A:foo", ".erl"),
+ "foo.erl" = filename:basename("a:\\usr\\foo.erl", ".hrl"),
+ "foo.erl" = filename:basename("c:\\usr.hrl\\foo.erl", ".hrl"),
+ "foo" = filename:basename("A:\\usr\\foo", ".hrl");
+ _ ->
+ "strange\\but\\true" =
+ filename:basename("strange\\but\\true.erl", ".erl"),
+ "strange\\but\\true" =
+ filename:basename("strange\\but\\true", ".erl")
+ end,
+ test_server:timetrap_cancel(Dog),
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dirname(Config) when is_list(Config) ->
case os:type() of
- {win32,_} ->
- "A:/usr" = filename:dirname("A:/usr/foo.erl"),
- "A:usr" = filename:dirname("A:usr/foo.erl"),
- "/usr" = filename:dirname("\\usr\\foo.erl"),
- "/" = filename:dirname("\\usr"),
- "A:" = filename:dirname("A:");
- _ -> true
+ {win32,_} ->
+ "A:/usr" = filename:dirname("A:/usr/foo.erl"),
+ "A:usr" = filename:dirname("A:usr/foo.erl"),
+ "/usr" = filename:dirname("\\usr\\foo.erl"),
+ "/" = filename:dirname("\\usr"),
+ "A:" = filename:dirname("A:");
+ _ -> true
end,
"usr" = filename:dirname("usr///foo.erl"),
"." = filename:dirname("foo.erl"),
@@ -258,23 +265,22 @@ dirname(Config) when is_list(Config) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
extension(Config) when is_list(Config) ->
- ?line ".erl" = filename:extension("A:/usr/foo.erl"),
- ?line ".erl" = filename:extension("A:/usr/foo.nisse.erl"),
- ?line ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.erl"]),
- ?line ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.e", 'rl']),
- ?line ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.e"|'rl']),
- ?line ".erl" = filename:extension("A:/usr.bar/foo.nisse.erl"),
- ?line "" = filename:extension("A:/usr.bar/foo"),
- ?line "" = filename:extension("A:/usr/foo"),
- ?line case os:type() of
- {win32, _} ->
- ?line "" = filename:extension("A:\\usr\\foo"),
- ?line ".erl" =
- filename:extension("A:/usr.bar/foo.nisse.erl"),
- ?line "" = filename:extension("A:/usr.bar/foo"),
- ok;
- _ -> ok
- end.
+ ".erl" = filename:extension("A:/usr/foo.erl"),
+ ".erl" = filename:extension("A:/usr/foo.nisse.erl"),
+ ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.erl"]),
+ ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.e", 'rl']),
+ ".erl" = filename:extension(["A:/usr/", 'foo.ni', "sse.e"|'rl']),
+ ".erl" = filename:extension("A:/usr.bar/foo.nisse.erl"),
+ "" = filename:extension("A:/usr.bar/foo"),
+ "" = filename:extension("A:/usr/foo"),
+ case os:type() of
+ {win32, _} ->
+ "" = filename:extension("A:\\usr\\foo"),
+ ".erl" = filename:extension("A:/usr.bar/foo.nisse.erl"),
+ "" = filename:extension("A:/usr.bar/foo"),
+ ok;
+ _ -> ok
+ end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -282,8 +288,8 @@ join(Config) when is_list(Config) ->
%% Whenever joining two elements, test the equivalence between
%% join/1 and join/2 (OTP-12158) by using help function
%% filename_join/2.
- ?line "/" = filename:join(["/"]),
- ?line "/" = filename:join(["//"]),
+ "/" = filename:join(["/"]),
+ "/" = filename:join(["//"]),
"usr/foo.erl" = filename_join("usr","foo.erl"),
"/src/foo.erl" = filename_join(usr, "/src/foo.erl"),
"/src/foo.erl" = filename_join("/src/",'foo.erl'),
@@ -291,7 +297,7 @@ join(Config) when is_list(Config) ->
"/src/foo.erl" = filename_join("usr", "/src/foo.erl"),
%% Make sure that redundant slashes work too.
- ?line "a/b/c/d/e/f/g" = filename:join(["a//b/c/////d//e/f/g"]),
+ "a/b/c/d/e/f/g" = filename:join(["a//b/c/////d//e/f/g"]),
"a/b/c/d/e/f/g" = filename_join("a//b/c/", "d//e/f/g"),
"a/b/c/d/e/f/g" = filename_join("a//b/c", "d//e/f/g"),
"/d/e/f/g" = filename_join("a//b/c", "/d//e/f/g"),
@@ -324,30 +330,25 @@ join(Config) when is_list(Config) ->
"/b" = filename_join("/a/","/b/"),
"/a/b" = filename_join("/a/","b/"),
- ?line case os:type() of
- {win32, _} ->
- ?line "d:/" = filename:join(["D:/"]),
- ?line "d:/" = filename:join(["D:\\"]),
- "d:/abc" = filename_join("D:/", "abc"),
- "d:abc" = filename_join("D:", "abc"),
- ?line "a/b/c/d/e/f/g" =
- filename:join(["a//b\\c//\\/\\d/\\e/f\\g"]),
- ?line "a:usr/foo.erl" =
- filename:join(["A:","usr","foo.erl"]),
- ?line "/usr/foo.erl" =
- filename:join(["A:","/usr","foo.erl"]),
- "c:usr" = filename_join("A:","C:usr"),
- "a:usr" = filename_join("A:","usr"),
- "c:/usr" = filename_join("A:", "C:/usr"),
- ?line "c:/usr/foo.erl" =
- filename:join(["A:","C:/usr","foo.erl"]),
- ?line "c:usr/foo.erl" =
- filename:join(["A:","C:usr","foo.erl"]),
- ?line "d:/foo" = filename:join([$D, $:, $/, []], "foo"),
- ok;
- _ ->
- ok
- end.
+ case os:type() of
+ {win32, _} ->
+ "d:/" = filename:join(["D:/"]),
+ "d:/" = filename:join(["D:\\"]),
+ "d:/abc" = filename_join("D:/", "abc"),
+ "d:abc" = filename_join("D:", "abc"),
+ "a/b/c/d/e/f/g" = filename:join(["a//b\\c//\\/\\d/\\e/f\\g"]),
+ "a:usr/foo.erl" = filename:join(["A:","usr","foo.erl"]),
+ "/usr/foo.erl" = filename:join(["A:","/usr","foo.erl"]),
+ "c:usr" = filename_join("A:","C:usr"),
+ "a:usr" = filename_join("A:","usr"),
+ "c:/usr" = filename_join("A:", "C:/usr"),
+ "c:/usr/foo.erl" = filename:join(["A:","C:/usr","foo.erl"]),
+ "c:usr/foo.erl" = filename:join(["A:","C:usr","foo.erl"]),
+ "d:/foo" = filename:join([$D, $:, $/, []], "foo"),
+ ok;
+ _ ->
+ ok
+ end.
%% Make sure join([A,B]) is equivalent to join(A,B) (OTP-12158)
filename_join(A,B) ->
@@ -355,92 +356,92 @@ filename_join(A,B) ->
Res = filename:join([A,B]).
pathtype(Config) when is_list(Config) ->
- ?line relative = filename:pathtype(".."),
- ?line relative = filename:pathtype("foo"),
- ?line relative = filename:pathtype("foo/bar"),
- ?line relative = filename:pathtype('foo/bar'),
- ?line relative = filename:pathtype(['f','oo',"/bar"]),
+ relative = filename:pathtype(".."),
+ relative = filename:pathtype("foo"),
+ relative = filename:pathtype("foo/bar"),
+ relative = filename:pathtype('foo/bar'),
+ relative = filename:pathtype(['f','oo',"/bar"]),
case os:type() of
- {win32, _} ->
- ?line volumerelative = filename:pathtype("/usr/local/bin"),
- ?line volumerelative = filename:pathtype("A:usr/local/bin"),
- ok;
- _ ->
- ?line absolute = filename:pathtype("/"),
- ?line absolute = filename:pathtype("/usr/local/bin"),
- ok
+ {win32, _} ->
+ volumerelative = filename:pathtype("/usr/local/bin"),
+ volumerelative = filename:pathtype("A:usr/local/bin"),
+ ok;
+ _ ->
+ absolute = filename:pathtype("/"),
+ absolute = filename:pathtype("/usr/local/bin"),
+ ok
end.
rootname(Config) when is_list(Config) ->
- ?line "/jam.src/kalle" = filename:rootname("/jam.src/kalle"),
- ?line "/jam.src/foo" = filename:rootname("/jam.src/foo.erl"),
- ?line "/jam.src/foo" = filename:rootname(["/ja",'m.sr',"c/foo.erl"]),
- ?line "/jam.src/foo" = filename:rootname("/jam.src/foo.erl", ".erl"),
- ?line "/jam.src/foo.jam" = filename:rootname("/jam.src/foo.jam", ".erl"),
- ?line "/jam.src/foo.jam" = filename:rootname(["/jam.sr",'c/foo.j',"am"],".erl"),
- ?line "/jam.src/foo.jam" = filename:rootname(["/jam.sr",'c/foo.j'|am],".erl"),
+ "/jam.src/kalle" = filename:rootname("/jam.src/kalle"),
+ "/jam.src/foo" = filename:rootname("/jam.src/foo.erl"),
+ "/jam.src/foo" = filename:rootname(["/ja",'m.sr',"c/foo.erl"]),
+ "/jam.src/foo" = filename:rootname("/jam.src/foo.erl", ".erl"),
+ "/jam.src/foo.jam" = filename:rootname("/jam.src/foo.jam", ".erl"),
+ "/jam.src/foo.jam" = filename:rootname(["/jam.sr",'c/foo.j',"am"],".erl"),
+ "/jam.src/foo.jam" = filename:rootname(["/jam.sr",'c/foo.j'|am],".erl"),
ok.
split(Config) when is_list(Config) ->
- ?line ["/","usr","local","bin"] = filename:split("/usr/local/bin"),
- ?line ["foo","bar"]= filename:split("foo/bar"),
- ?line ["foo", "bar", "hello"]= filename:split("foo////bar//hello"),
- ?line ["foo", "bar", "hello"]= filename:split(["foo//",'//bar//h',"ello"]),
- ?line ["foo", "bar", "hello"]= filename:split(["foo//",'//bar//h'|ello]),
+ ["/","usr","local","bin"] = filename:split("/usr/local/bin"),
+ ["foo","bar"]= filename:split("foo/bar"),
+ ["foo", "bar", "hello"]= filename:split("foo////bar//hello"),
+ ["foo", "bar", "hello"]= filename:split(["foo//",'//bar//h',"ello"]),
+ ["foo", "bar", "hello"]= filename:split(["foo//",'//bar//h'|ello]),
["/"] = filename:split("/"),
[] = filename:split(""),
case os:type() of
- {win32,_} ->
- ?line ["a:/","msdev","include"] =
- filename:split("a:/msdev/include"),
- ?line ["a:/","msdev","include"] =
- filename:split("A:/msdev/include"),
- ?line ["msdev","include"] =
- filename:split("msdev\\include"),
- ?line ["a:/","msdev","include"] =
- filename:split("a:\\msdev\\include"),
- ?line ["a:","msdev","include"] =
- filename:split("a:msdev\\include"),
- ok;
- _ ->
+ {win32,_} ->
+ ["a:/","msdev","include"] =
+ filename:split("a:/msdev/include"),
+ ["a:/","msdev","include"] =
+ filename:split("A:/msdev/include"),
+ ["msdev","include"] =
+ filename:split("msdev\\include"),
+ ["a:/","msdev","include"] =
+ filename:split("a:\\msdev\\include"),
+ ["a:","msdev","include"] =
+ filename:split("a:msdev\\include"),
+ ok;
+ _ ->
ok
end.
t_nativename(Config) when is_list(Config) ->
- ?line "abcedf" = filename:nativename(abcedf),
- ?line "abcedf" = filename:nativename(["abc", "edf"]),
- ?line "abcgluff" = filename:nativename(["abc", gluff]),
+ "abcedf" = filename:nativename(abcedf),
+ "abcedf" = filename:nativename(["abc", "edf"]),
+ "abcgluff" = filename:nativename(["abc", gluff]),
case os:type() of
- {win32, _} ->
- ?line "a:\\temp\\arne.exe" =
- filename:nativename("A:/temp//arne.exe/");
- _ ->
- ?line "/usr/tmp/arne" =
- filename:nativename("/usr/tmp//arne/")
+ {win32, _} ->
+ "a:\\temp\\arne.exe" =
+ filename:nativename("A:/temp//arne.exe/");
+ _ ->
+ "/usr/tmp/arne" =
+ filename:nativename("/usr/tmp//arne/")
end.
find_src(Config) when is_list(Config) ->
- ?line {Source,_} = filename:find_src(file),
- ?line ["file"|_] = lists:reverse(filename:split(Source)),
- ?line {_,_} = filename:find_src(init, [{".","."}, {"ebin","src"}]),
+ {Source,_} = filename:find_src(file),
+ ["file"|_] = lists:reverse(filename:split(Source)),
+ {_,_} = filename:find_src(init, [{".","."}, {"ebin","src"}]),
%% Try to find the source for a preloaded module.
- ?line {error,{preloaded,init}} = filename:find_src(init),
+ {error,{preloaded,init}} = filename:find_src(init),
%% Make sure that find_src works for a slim BEAM file.
OldPath = code:get_path(),
try
- PrivDir = ?config(priv_dir, Config),
- code:add_patha(PrivDir),
- Src = "simple",
- SrcPath = filename:join(PrivDir, Src) ++ ".erl",
- SrcContents = "-module(simple).\n",
- ok = file:write_file(SrcPath, SrcContents),
- {ok,simple} = compile:file(SrcPath, [slim,{outdir,PrivDir}]),
- BeamPath = filename:join(PrivDir, Src),
- {BeamPath,[]} = filename:find_src(simple)
+ PrivDir = ?config(priv_dir, Config),
+ code:add_patha(PrivDir),
+ Src = "simple",
+ SrcPath = filename:join(PrivDir, Src) ++ ".erl",
+ SrcContents = "-module(simple).\n",
+ ok = file:write_file(SrcPath, SrcContents),
+ {ok,simple} = compile:file(SrcPath, [slim,{outdir,PrivDir}]),
+ BeamPath = filename:join(PrivDir, Src),
+ {BeamPath,[]} = filename:find_src(simple)
after
- code:set_path(OldPath)
+ code:set_path(OldPath)
end,
ok.
@@ -452,50 +453,51 @@ find_src(Config) when is_list(Config) ->
absname_bin(Config) when is_list(Config) ->
case os:type() of
- {win32, _} ->
- ?line [Drive|_] = ?config(priv_dir, Config),
- ?line Temp = filename:join([Drive|":/"], "temp"),
- ?line case file:make_dir(Temp) of
- ok -> ok;
- {error,eexist} -> ok
- end,
- ?line {ok,Cwd} = file:get_cwd(),
- ?line ok = file:set_cwd(Temp),
- ?line <<Drive:8,":/temp/foo">> = filename:absname(<<"foo">>),
- ?line <<Drive:8,":/temp/../ebin">> = filename:absname(<<"../ebin">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\src">>),
- ?line <<Drive:8,":/temp/erlang">> = filename:absname(<<Drive:8,":erlang">>),
- ?line <<Drive:8,":/temp/erlang/src">> =
- filename:absname(<<Drive:8,":erlang/src">>),
- ?line <<Drive:8,":/temp/erlang/src">> =
- filename:absname(<<Drive:8,":erlang\\src\\">>),
- ?line <<"a:/erlang">> = filename:absname(<<"a:erlang">>),
-
- ?line file:set_cwd(<<Drive:8,":/">>),
- ?line <<Drive:8,":/foo">> = filename:absname(<<"foo">>),
- ?line <<Drive:8,":/../ebin">> = filename:absname(<<"../ebin">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\\\src">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<Drive:8,":erlang">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>),
- ?line <<"a:/erlang">> = filename:absname(<<"a:erlang">>),
-
- ?line file:set_cwd(Cwd),
- ok;
- {unix, _} ->
- ?line ok = file:set_cwd(<<"/usr">>),
- ?line <<"/usr/foo">> = filename:absname(<<"foo">>),
- ?line <<"/usr/../ebin">> = filename:absname(<<"../ebin">>),
- ?line file:set_cwd(<<"/">>),
- ?line <<"/foo">> = filename:absname(<<"foo">>),
- ?line <<"/../ebin">> = filename:absname(<<"../ebin">>),
- ?line <<"/erlang">> = filename:absname(<<"/erlang">>),
- ?line <<"/erlang/src">> = filename:absname(<<"/erlang/src">>),
- ?line <<"/erlang/src">> = filename:absname(<<"/erlang///src">>),
- ok
+ {win32, _} ->
+ [Drive|_] = ?config(priv_dir, Config),
+ Temp = filename:join([Drive|":/"], "temp"),
+ case file:make_dir(Temp) of
+ ok -> ok;
+ {error,eexist} -> ok
+ end,
+ {ok,Cwd} = file:get_cwd(),
+ ok = file:set_cwd(Temp),
+ <<Drive:8,":/temp/foo">> = filename:absname(<<"foo">>),
+ <<Drive:8,":/temp/../ebin">> = filename:absname(<<"../ebin">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\src">>),
+ <<Drive:8,":/temp/erlang">> = filename:absname(<<Drive:8,":erlang">>),
+ <<Drive:8,":/temp/erlang/src">> =
+ filename:absname(<<Drive:8,":erlang/src">>),
+ <<Drive:8,":/temp/erlang/src">> =
+ filename:absname(<<Drive:8,":erlang\\src\\">>),
+ <<"a:/erlang">> = filename:absname(<<"a:erlang">>),
+
+ file:set_cwd(<<Drive:8,":/">>),
+ <<Drive:8,":/foo">> = filename:absname(<<"foo">>),
+ <<Drive:8,":/../ebin">> = filename:absname(<<"../ebin">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\\\src">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<Drive:8,":erlang">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>),
+ <<"a:/erlang">> = filename:absname(<<"a:erlang">>),
+
+ file:set_cwd(Cwd),
+ ok;
+ {unix,_} ->
+ ok = file:set_cwd(<<"/usr">>),
+ <<"/usr/foo">> = filename:absname(<<"foo">>),
+ <<"/usr/../ebin">> = filename:absname(<<"../ebin">>),
+
+ file:set_cwd(<<"/">>),
+ <<"/foo">> = filename:absname(<<"foo">>),
+ <<"/../ebin">> = filename:absname(<<"../ebin">>),
+ <<"/erlang">> = filename:absname(<<"/erlang">>),
+ <<"/erlang/src">> = filename:absname(<<"/erlang/src">>),
+ <<"/erlang/src">> = filename:absname(<<"/erlang///src">>),
+ ok
end.
@@ -503,108 +505,104 @@ absname_bin(Config) when is_list(Config) ->
absname_bin_2(Config) when is_list(Config) ->
case os:type() of
- {win32, _} ->
- ?line [Drive|_] = ?config(priv_dir, Config),
- ?line <<Drive:8,":/temp/foo">> = filename:absname(<<"foo">>, <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/temp/../ebin">> = filename:absname(<<"../ebin">>,
- <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>, <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>,
- <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\src">>,
- <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/temp/erlang">> = filename:absname(<<Drive:8,":erlang">>,
- <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/temp/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>,
- <<Drive:8,":/temp">>),
- ?line <<Drive:8,":/temp/erlang/src">> =
- filename:absname(<<Drive:8,":erlang\\src\\">>, <<Drive:8,":/temp">>),
- ?line <<"a:/erlang">> = filename:absname(<<"a:erlang">>, <<Drive:8,":/temp">>),
-
- ?line file:set_cwd(<<Drive:8,":/">>),
- ?line <<Drive:8,":/foo">> = filename:absname(foo, <<Drive:8,":/">>),
- ?line <<Drive:8,":/foo">> = filename:absname(<<"foo">>, <<Drive:8,":/">>),
- ?line <<Drive:8,":/../ebin">> = filename:absname(<<"../ebin">>, <<Drive:8,":/">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>, <<Drive:8,":/">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>,
- <<Drive:8,":/">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\\\src">>,
- <<Drive:8,":/">>),
- ?line <<Drive:8,":/erlang">> = filename:absname(<<Drive:8,":erlang">>,
- <<Drive:8,":/">>),
- ?line <<Drive:8,":/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>,
- <<Drive:8,":/">>),
- ?line <<"a:/erlang">> = filename:absname(<<"a:erlang">>, <<Drive:8,":/">>),
-
- ok;
- _ ->
- ?line <<"/usr/foo">> = filename:absname(<<"foo">>, <<"/usr">>),
- ?line <<"/usr/../ebin">> = filename:absname(<<"../ebin">>, <<"/usr">>),
-
- ?line <<"/foo">> = filename:absname(<<"foo">>, <<"/">>),
- ?line <<"/../ebin">> = filename:absname(<<"../ebin">>, <<"/">>),
- ?line <<"/erlang">> = filename:absname(<<"/erlang">>, <<"/">>),
- ?line <<"/erlang/src">> = filename:absname(<<"/erlang/src">>, <<"/">>),
- ?line <<"/erlang/src">> = filename:absname(<<"/erlang///src">>, <<"/">>),
- ok
+ {win32, _} ->
+ [Drive|_] = ?config(priv_dir, Config),
+ <<Drive:8,":/temp/foo">> = filename:absname(<<"foo">>, <<Drive:8,":/temp">>),
+ <<Drive:8,":/temp/../ebin">> = filename:absname(<<"../ebin">>,
+ <<Drive:8,":/temp">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>, <<Drive:8,":/temp">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>,
+ <<Drive:8,":/temp">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\src">>,
+ <<Drive:8,":/temp">>),
+ <<Drive:8,":/temp/erlang">> = filename:absname(<<Drive:8,":erlang">>,
+ <<Drive:8,":/temp">>),
+ <<Drive:8,":/temp/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>,
+ <<Drive:8,":/temp">>),
+ <<Drive:8,":/temp/erlang/src">> =
+ filename:absname(<<Drive:8,":erlang\\src\\">>, <<Drive:8,":/temp">>),
+ <<"a:/erlang">> = filename:absname(<<"a:erlang">>, <<Drive:8,":/temp">>),
+
+ file:set_cwd(<<Drive:8,":/">>),
+ <<Drive:8,":/foo">> = filename:absname(foo, <<Drive:8,":/">>),
+ <<Drive:8,":/foo">> = filename:absname(<<"foo">>, <<Drive:8,":/">>),
+ <<Drive:8,":/../ebin">> = filename:absname(<<"../ebin">>, <<Drive:8,":/">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<"/erlang">>, <<Drive:8,":/">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"/erlang/src">>,
+ <<Drive:8,":/">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<"\\erlang\\\\src">>,
+ <<Drive:8,":/">>),
+ <<Drive:8,":/erlang">> = filename:absname(<<Drive:8,":erlang">>,
+ <<Drive:8,":/">>),
+ <<Drive:8,":/erlang/src">> = filename:absname(<<Drive:8,":erlang/src">>,
+ <<Drive:8,":/">>),
+ <<"a:/erlang">> = filename:absname(<<"a:erlang">>, <<Drive:8,":/">>),
+
+ ok;
+ _ ->
+ <<"/usr/foo">> = filename:absname(<<"foo">>, <<"/usr">>),
+ <<"/usr/../ebin">> = filename:absname(<<"../ebin">>, <<"/usr">>),
+ <<"/foo">> = filename:absname(<<"foo">>, <<"/">>),
+ <<"/../ebin">> = filename:absname(<<"../ebin">>, <<"/">>),
+ <<"/erlang">> = filename:absname(<<"/erlang">>, <<"/">>),
+ <<"/erlang/src">> = filename:absname(<<"/erlang/src">>, <<"/">>),
+ <<"/erlang/src">> = filename:absname(<<"/erlang///src">>, <<"/">>),
+ ok
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
basename_bin_1(Config) when is_list(Config) ->
- ?line Dog = test_server:timetrap(test_server:seconds(10)),
- ?line <<".">> = filename:basename(<<".">>),
- ?line <<"foo">> = filename:basename(<<"foo">>),
- ?line <<"foo">> = filename:basename(<<"/usr/foo">>),
- ?line <<"foo.erl">> = filename:basename(<<"A:usr/foo.erl">>),
- ?line case os:type() of
- {win32, _} ->
- ?line <<"foo">> = filename:basename(<<"A:\\usr\\foo">>),
- ?line <<"foo">> = filename:basename(<<"A:foo">>);
- _ ->
- ?line <<"strange\\but\\true">> =
- filename:basename(<<"strange\\but\\true">>)
- end,
- ?line test_server:timetrap_cancel(Dog),
+ Dog = test_server:timetrap(test_server:seconds(10)),
+ <<".">> = filename:basename(<<".">>),
+ <<"foo">> = filename:basename(<<"foo">>),
+ <<"foo">> = filename:basename(<<"/usr/foo">>),
+ <<"foo.erl">> = filename:basename(<<"A:usr/foo.erl">>),
+ case os:type() of
+ {win32, _} ->
+ <<"foo">> = filename:basename(<<"A:\\usr\\foo">>),
+ <<"foo">> = filename:basename(<<"A:foo">>);
+ _ ->
+ <<"strange\\but\\true">> = filename:basename(<<"strange\\but\\true">>)
+ end,
+ test_server:timetrap_cancel(Dog),
ok.
basename_bin_2(Config) when is_list(Config) ->
- ?line Dog = test_server:timetrap(test_server:seconds(10)),
- ?line <<".">> = filename:basename(<<".">>, <<".erl">>),
- ?line <<"foo">> = filename:basename(<<"foo.erl">>, <<".erl">>),
- ?line <<"foo.erl">> = filename:basename(<<"/usr/foo.erl">>, <<".hrl">>),
- ?line <<"foo.erl">> = filename:basename(<<"/usr.hrl/foo.erl">>, <<".hrl">>),
- ?line <<"foo">> = filename:basename(<<"/usr.hrl/foo">>, <<".hrl">>),
- ?line <<"foo">> = filename:basename(<<"usr/foo/">>, <<".erl">>),
- ?line <<"foo.erl">> = filename:basename(<<"usr/foo.erl/">>, <<".erl">>),
- ?line case os:type() of
- {win32, _} ->
- ?line <<"foo">> = filename:basename(<<"A:foo">>, <<".erl">>),
- ?line <<"foo.erl">> = filename:basename(<<"a:\\usr\\foo.erl">>,
- <<".hrl">>),
- ?line <<"foo.erl">> = filename:basename(<<"c:\\usr.hrl\\foo.erl">>,
- <<".hrl">>),
- ?line <<"foo">> = filename:basename(<<"A:\\usr\\foo">>, <<".hrl">>);
- _ ->
- ?line <<"strange\\but\\true">> =
- filename:basename(<<"strange\\but\\true.erl">>, <<".erl">>),
- ?line <<"strange\\but\\true">> =
- filename:basename(<<"strange\\but\\true">>, <<".erl">>)
- end,
- ?line test_server:timetrap_cancel(Dog),
+ Dog = test_server:timetrap(test_server:seconds(10)),
+ <<".">> = filename:basename(<<".">>, <<".erl">>),
+ <<"foo">> = filename:basename(<<"foo.erl">>, <<".erl">>),
+ <<"foo.erl">> = filename:basename(<<"/usr/foo.erl">>, <<".hrl">>),
+ <<"foo.erl">> = filename:basename(<<"/usr.hrl/foo.erl">>, <<".hrl">>),
+ <<"foo">> = filename:basename(<<"/usr.hrl/foo">>, <<".hrl">>),
+ <<"foo">> = filename:basename(<<"usr/foo/">>, <<".erl">>),
+ <<"foo.erl">> = filename:basename(<<"usr/foo.erl/">>, <<".erl">>),
+ case os:type() of
+ {win32, _} ->
+ <<"foo">> = filename:basename(<<"A:foo">>, <<".erl">>),
+ <<"foo.erl">> = filename:basename(<<"a:\\usr\\foo.erl">>, <<".hrl">>),
+ <<"foo.erl">> = filename:basename(<<"c:\\usr.hrl\\foo.erl">>, <<".hrl">>),
+ <<"foo">> = filename:basename(<<"A:\\usr\\foo">>, <<".hrl">>);
+ _ ->
+ <<"strange\\but\\true">> =
+ filename:basename(<<"strange\\but\\true.erl">>, <<".erl">>),
+ <<"strange\\but\\true">> =
+ filename:basename(<<"strange\\but\\true">>, <<".erl">>)
+ end,
+ test_server:timetrap_cancel(Dog),
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dirname_bin(Config) when is_list(Config) ->
case os:type() of
- {win32,_} ->
- <<"A:/usr">> = filename:dirname(<<"A:/usr/foo.erl">>),
- <<"A:usr">> = filename:dirname(<<"A:usr/foo.erl">>),
- <<"/usr">> = filename:dirname(<<"\\usr\\foo.erl">>),
- <<"/">> = filename:dirname(<<"\\usr">>),
- <<"A:">> = filename:dirname(<<"A:">>);
- _ -> true
+ {win32,_} ->
+ <<"A:/usr">> = filename:dirname(<<"A:/usr/foo.erl">>),
+ <<"A:usr">> = filename:dirname(<<"A:usr/foo.erl">>),
+ <<"/usr">> = filename:dirname(<<"\\usr\\foo.erl">>),
+ <<"/">> = filename:dirname(<<"\\usr">>),
+ <<"A:">> = filename:dirname(<<"A:">>);
+ _ -> true
end,
<<"usr">> = filename:dirname(<<"usr///foo.erl">>),
<<".">> = filename:dirname(<<"foo.erl">>),
@@ -612,7 +610,6 @@ dirname_bin(Config) when is_list(Config) ->
<<"/">> = filename:dirname(<<"/">>),
<<"/">> = filename:dirname(<<"/usr">>),
ok.
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -624,10 +621,9 @@ extension_bin(Config) when is_list(Config) ->
<<"">> = filename:extension(<<"A:/usr/foo">>),
case os:type() of
{win32, _} ->
- ?line <<"">> = filename:extension(<<"A:\\usr\\foo">>),
- ?line <<".erl">> =
- filename:extension(<<"A:/usr.bar/foo.nisse.erl">>),
- ?line <<"">> = filename:extension(<<"A:/usr.bar/foo">>),
+ <<"">> = filename:extension(<<"A:\\usr\\foo">>),
+ <<".erl">> = filename:extension(<<"A:/usr.bar/foo.nisse.erl">>),
+ <<"">> = filename:extension(<<"A:/usr.bar/foo">>),
ok;
_ -> ok
end.
@@ -635,22 +631,22 @@ extension_bin(Config) when is_list(Config) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
join_bin(Config) when is_list(Config) ->
- ?line <<"/">> = filename:join([<<"/">>]),
- ?line <<"/">> = filename:join([<<"//">>]),
- ?line <<"usr/foo.erl">> = filename:join(<<"usr">>,<<"foo.erl">>),
- ?line <<"/src/foo.erl">> = filename:join(usr, <<"/src/foo.erl">>),
- ?line <<"/src/foo.erl">> = filename:join([<<"/src/">>,'foo.erl']),
- ?line <<"/src/foo.erl">> = filename:join(<<"usr">>, ["/sr", 'c/foo.erl']),
- ?line <<"/src/foo.erl">> = filename:join(<<"usr">>, <<"/src/foo.erl">>),
+ <<"/">> = filename:join([<<"/">>]),
+ <<"/">> = filename:join([<<"//">>]),
+ <<"usr/foo.erl">> = filename:join(<<"usr">>,<<"foo.erl">>),
+ <<"/src/foo.erl">> = filename:join(usr, <<"/src/foo.erl">>),
+ <<"/src/foo.erl">> = filename:join([<<"/src/">>,'foo.erl']),
+ <<"/src/foo.erl">> = filename:join(<<"usr">>, ["/sr", 'c/foo.erl']),
+ <<"/src/foo.erl">> = filename:join(<<"usr">>, <<"/src/foo.erl">>),
%% Make sure that redundant slashes work too.
- ?line <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c/////d//e/f/g">>]),
- ?line <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c/">>, <<"d//e/f/g">>]),
- ?line <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"d//e/f/g">>]),
- ?line <<"/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"/d//e/f/g">>]),
- ?line <<"/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"//d//e/f/g">>]),
+ <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c/////d//e/f/g">>]),
+ <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c/">>, <<"d//e/f/g">>]),
+ <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"d//e/f/g">>]),
+ <<"/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"/d//e/f/g">>]),
+ <<"/d/e/f/g">> = filename:join([<<"a//b/c">>, <<"//d//e/f/g">>]),
- ?line <<"foo/bar">> = filename:join([$f,$o,$o,$/,[]], <<"bar">>),
+ <<"foo/bar">> = filename:join([$f,$o,$o,$/,[]], <<"bar">>),
%% Single dots - should be removed if in the middle of the path,
%% but not at the end of the path.
@@ -699,30 +695,25 @@ join_bin(Config) when is_list(Config) ->
<<"/a/b">> = filename:join([<<"/a/">>,<<"b/">>]),
<<"/a/b">> = filename:join(<<"/a/">>,<<"b/">>),
- ?line case os:type() of
- {win32, _} ->
- ?line <<"d:/">> = filename:join([<<"D:/">>]),
- ?line <<"d:/">> = filename:join([<<"D:\\">>]),
- ?line <<"d:/abc">> = filename:join([<<"D:/">>, <<"abc">>]),
- ?line <<"d:abc">> = filename:join([<<"D:">>, <<"abc">>]),
- ?line <<"a/b/c/d/e/f/g">> =
- filename:join([<<"a//b\\c//\\/\\d/\\e/f\\g">>]),
- ?line <<"a:usr/foo.erl">> =
- filename:join([<<"A:">>,<<"usr">>,<<"foo.erl">>]),
- ?line <<"/usr/foo.erl">> =
- filename:join([<<"A:">>,<<"/usr">>,<<"foo.erl">>]),
- ?line <<"c:usr">> = filename:join(<<"A:">>,<<"C:usr">>),
- ?line <<"a:usr">> = filename:join(<<"A:">>,<<"usr">>),
- ?line <<"c:/usr">> = filename:join(<<"A:">>, <<"C:/usr">>),
- ?line <<"c:/usr/foo.erl">> =
- filename:join([<<"A:">>,<<"C:/usr">>,<<"foo.erl">>]),
- ?line <<"c:usr/foo.erl">> =
- filename:join([<<"A:">>,<<"C:usr">>,<<"foo.erl">>]),
- ?line <<"d:/foo">> = filename:join([$D, $:, $/, []], <<"foo">>),
- ok;
- _ ->
- ok
- end.
+ case os:type() of
+ {win32, _} ->
+ <<"d:/">> = filename:join([<<"D:/">>]),
+ <<"d:/">> = filename:join([<<"D:\\">>]),
+ <<"d:/abc">> = filename:join([<<"D:/">>, <<"abc">>]),
+ <<"d:abc">> = filename:join([<<"D:">>, <<"abc">>]),
+ <<"a/b/c/d/e/f/g">> = filename:join([<<"a//b\\c//\\/\\d/\\e/f\\g">>]),
+ <<"a:usr/foo.erl">> = filename:join([<<"A:">>,<<"usr">>,<<"foo.erl">>]),
+ <<"/usr/foo.erl">> = filename:join([<<"A:">>,<<"/usr">>,<<"foo.erl">>]),
+ <<"c:usr">> = filename:join(<<"A:">>,<<"C:usr">>),
+ <<"a:usr">> = filename:join(<<"A:">>,<<"usr">>),
+ <<"c:/usr">> = filename:join(<<"A:">>, <<"C:/usr">>),
+ <<"c:/usr/foo.erl">> = filename:join([<<"A:">>,<<"C:/usr">>,<<"foo.erl">>]),
+ <<"c:usr/foo.erl">> = filename:join([<<"A:">>,<<"C:usr">>,<<"foo.erl">>]),
+ <<"d:/foo">> = filename:join([$D, $:, $/, []], <<"foo">>),
+ ok;
+ _ ->
+ ok
+ end.
pathtype_bin(Config) when is_list(Config) ->
relative = filename:pathtype(<<"..">>),
@@ -730,14 +721,14 @@ pathtype_bin(Config) when is_list(Config) ->
relative = filename:pathtype(<<"foo/bar">>),
relative = filename:pathtype('foo/bar'),
case os:type() of
- {win32, _} ->
- volumerelative = filename:pathtype(<<"/usr/local/bin">>),
- volumerelative = filename:pathtype(<<"A:usr/local/bin">>),
- ok;
- _ ->
- absolute = filename:pathtype(<<"/">>),
- absolute = filename:pathtype(<<"/usr/local/bin">>),
- ok
+ {win32, _} ->
+ volumerelative = filename:pathtype(<<"/usr/local/bin">>),
+ volumerelative = filename:pathtype(<<"A:usr/local/bin">>),
+ ok;
+ _ ->
+ absolute = filename:pathtype(<<"/">>),
+ absolute = filename:pathtype(<<"/usr/local/bin">>),
+ ok
end.
rootname_bin(Config) when is_list(Config) ->
@@ -756,29 +747,204 @@ split_bin(Config) when is_list(Config) ->
[<<"/">>] = filename:split(<<"/">>),
[] = filename:split(<<"">>),
case os:type() of
- {win32,_} ->
- [<<"a:/">>,<<"msdev">>,<<"include">>] =
- filename:split(<<"a:/msdev/include">>),
- [<<"a:/">>,<<"msdev">>,<<"include">>] =
- filename:split(<<"A:/msdev/include">>),
- [<<"msdev">>,<<"include">>] =
- filename:split(<<"msdev\\include">>),
- [<<"a:/">>,<<"msdev">>,<<"include">>] =
- filename:split(<<"a:\\msdev\\include">>),
- [<<"a:">>,<<"msdev">>,<<"include">>] =
- filename:split(<<"a:msdev\\include">>),
- ok;
- _ ->
- ok
+ {win32,_} ->
+ [<<"a:/">>,<<"msdev">>,<<"include">>] =
+ filename:split(<<"a:/msdev/include">>),
+ [<<"a:/">>,<<"msdev">>,<<"include">>] =
+ filename:split(<<"A:/msdev/include">>),
+ [<<"msdev">>,<<"include">>] =
+ filename:split(<<"msdev\\include">>),
+ [<<"a:/">>,<<"msdev">>,<<"include">>] =
+ filename:split(<<"a:\\msdev\\include">>),
+ [<<"a:">>,<<"msdev">>,<<"include">>] =
+ filename:split(<<"a:msdev\\include">>),
+ ok;
+ _ ->
+ ok
end.
t_nativename_bin(Config) when is_list(Config) ->
- ?line <<"abcedf">> = filename:nativename(<<"abcedf">>),
+ <<"abcedf">> = filename:nativename(<<"abcedf">>),
+ case os:type() of
+ {win32, _} ->
+ <<"a:\\temp\\arne.exe">> =
+ filename:nativename(<<"A:/temp//arne.exe/">>);
+ _ ->
+ <<"/usr/tmp/arne">> =
+ filename:nativename(<<"/usr/tmp//arne/">>)
+ end.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% basedirs
+t_basedir_api(Config) when is_list(Config) ->
+ true = is_list(filename:basedir(site_data, "My App")),
+ true = is_list(filename:basedir(site_config, "My App")),
+ true = is_list(filename:basedir(user_data, "My App")),
+ true = is_list(filename:basedir(user_log, "My App")),
+ true = is_list(filename:basedir(user_config, "My App")),
+ true = is_list(filename:basedir(user_cache, "My App")),
+
+ true = is_list(filename:basedir(site_data, <<"My App">>)),
+ true = is_list(filename:basedir(site_config, <<"My App">>)),
+ true = is_binary(filename:basedir(user_data, <<"My App">>)),
+ true = is_binary(filename:basedir(user_log, <<"My App">>)),
+ true = is_binary(filename:basedir(user_config, <<"My App">>)),
+ true = is_binary(filename:basedir(user_cache, <<"My App">>)),
+
+ %% simulate for windows
+ case os:type() of
+ {win32,_} -> ok;
+ _ ->
+ os:putenv("APPDATA", "C:\\Documents and Settings\\otptest\\Application Data")
+ end,
+
+ true = is_list(filename:basedir(site_data, "My App", #{})),
+ true = is_list(filename:basedir(site_config, "My App", #{os=>linux})),
+ true = is_list(filename:basedir(user_data, "My App", #{os=>darwin})),
+ true = is_list(filename:basedir(user_log, "My App", #{os=>windows})),
+ true = is_list(filename:basedir(user_config, "My App",#{author=>"Erl"})),
+ true = is_list(filename:basedir(user_config, "My App",#{os=>darwin,
+ author=>"Erl"})),
+ true = is_list(filename:basedir(user_config, "My App",#{os=>linux,
+ author=>"Erl"})),
+ true = is_list(filename:basedir(user_cache, "My App",#{os=>windows,
+ author=>"Erl"})),
+ true = is_list(filename:basedir(user_config, "My App",#{os=>darwin,
+ author=>"Erla",
+ version=>"1.0"})),
+ true = is_list(filename:basedir(user_config, "My App",#{os=>linux,
+ version=>"2.0.1",
+ author=>"Erl"})),
+ true = is_list(filename:basedir(user_cache, "My App",#{os=>windows,
+ version=>"3.1.2",
+ author=>"Erl"})),
+ true = is_binary(filename:basedir(user_config, "My App",#{os=>darwin,
+ author=>"Erla",
+ version=><<"1.0">>})),
+ true = is_binary(filename:basedir(user_config, "My App",#{os=>windows,
+ version=>"2.0.1",
+ author=><<"Erl">>})),
+ true = is_binary(filename:basedir(user_cache, "My App",#{os=>linux,
+ version=><<"3.1.2">>,
+ author=>"Erl"})),
+ %% simulate for windows
+ case os:type() of
+ {win32,_} -> ok;
+ _ -> os:unsetenv("APPDATA")
+ end,
+
+ {'EXIT', _} = (catch filename:basedir(wrong_config, "My App")),
+ {'EXIT', _} = (catch filename:basedir(user_cache, {bad,name})),
+ {'EXIT', _} = (catch filename:basedir(user_cache, "My App", badopts)),
+ {'EXIT', _} = (catch filename:basedir(user_cache, "My App", [])),
+ ok.
+
+t_basedir_windows(Config) when is_list(Config) ->
+ Types = [user_data,user_log,user_config,user_cache],
case os:type() of
- {win32, _} ->
- ?line <<"a:\\temp\\arne.exe">> =
- filename:nativename(<<"A:/temp//arne.exe/">>);
- _ ->
- ?line <<"/usr/tmp/arne">> =
- filename:nativename(<<"/usr/tmp//arne/">>)
+ {win32,_} ->
+ ok = check_basedir_windows(Types, #{});
+ _ ->
+ %% Windows 7 and beyond
+ os:putenv("APPDATA", "C:\\Users\\otptest\\AppData\\Roaming"),
+ os:putenv("LOCALAPPDATA", "C:\\Users\\otptest\\AppData\\Local"),
+ io:format("APPDATA ~p~n", [os:getenv("APPDATA")]),
+ io:format("LOCALAPPDATA ~p~n", [os:getenv("LOCALAPPDATA")]),
+ ok = check_basedir_windows(Types,#{os=>windows}),
+ %% Windows XP
+ os:unsetenv("LOCALAPPDATA"),
+ os:putenv("APPDATA", "C:\\Documents and Settings\\otptest\\Application Data"),
+ io:format("APPDATA ~p~n", [os:getenv("APPDATA")]),
+ io:format("APPLOCALDATA ~p~n", [os:getenv("APPLOCALDATA")]),
+ ok = check_basedir_windows(Types,#{os=>windows}),
+ os:unsetenv("APPDATA")
+ end,
+ ok.
+
+check_basedir_windows([],_) -> ok;
+check_basedir_windows([Type|Types],Opt) ->
+ Name = "Some Application",
+ io:format("type: ~p~n", [Type]),
+ ok = check_basedir_windows_path(Type,
+ [Name],
+ filename:basedir(Type, Name, Opt)),
+ ok = check_basedir_windows_path(Type,
+ ["Erl",Name],
+ filename:basedir(Type, Name, Opt#{author=>"Erl"})),
+ ok = check_basedir_windows_path(Type,
+ [Name,"1.0"],
+ filename:basedir(Type, Name, Opt#{version=>"1.0"})),
+ ok = check_basedir_windows_path(Type,
+ ["Erl",Name,"1.0"],
+ filename:basedir(Type, Name, Opt#{author=>"Erl",
+ version=>"1.0"})),
+ check_basedir_windows(Types, Opt).
+
+check_basedir_windows_path(Type,Check0,Basedir) ->
+ BDR = lists:reverse(filename:split(Basedir)),
+ Check = lists:reverse(Check0),
+ io:format("~w: ~p ~p~n", [Type,Check,BDR]),
+ case Type of
+ user_log -> check_basedir_windows_path_split(["Logs"|Check],BDR);
+ user_cache -> check_basedir_windows_path_split(["Cache"|Check],BDR);
+ _ -> check_basedir_windows_path_split(Check,BDR)
+ end.
+
+check_basedir_windows_path_split([],_) -> ok;
+check_basedir_windows_path_split([Same|Check],[Same|BDR]) ->
+ check_basedir_windows_path_split(Check,BDR).
+
+
+t_basedir_xdg(Config) when is_list(Config) ->
+ check_basedir_xdg([user_data,user_log,user_config,user_cache,
+ site_data,site_config]),
+ ok.
+
+check_basedir_xdg([]) -> ok;
+check_basedir_xdg([Type|Types]) ->
+ Name = "some_app",
+ Opt = #{os=>linux},
+ Key = basedir_xdg_env(Type),
+ io:format("type: ~p~n", [Type]),
+ Home = os:getenv("HOME"),
+ NDir = "/some/absolute/path",
+ DefPath = basedir_xdg_def(Type,Home,Name),
+ EnvPath = case Type of
+ user_log -> filename:join([NDir,Name,"log"]);
+ site_data -> [filename:join([NDir,Name])];
+ site_config -> [filename:join([NDir,Name])];
+ _ -> filename:join([NDir,Name])
+ end,
+ os:unsetenv(Key),
+ ok = check_basedir(Type, DefPath, filename:basedir(Type, Name, Opt)),
+ os:putenv(Key, NDir),
+ ok = check_basedir(Type, EnvPath, filename:basedir(Type, Name, Opt)),
+ os:unsetenv(Key),
+ ok = check_basedir(Type, DefPath, filename:basedir(Type, Name, Opt)),
+ check_basedir_xdg(Types).
+
+check_basedir(Type, Path, Basedir) ->
+ io:format("~w: ~p = ~p~n", [Type,Path,Basedir]),
+ Path = Basedir,
+ ok.
+
+basedir_xdg_env(Type) ->
+ case Type of
+ user_data -> "XDG_DATA_HOME";
+ user_config -> "XDG_CONFIG_HOME";
+ user_cache -> "XDG_CACHE_HOME";
+ user_log -> "XDG_CACHE_HOME";
+ site_data -> "XDG_DATA_DIRS";
+ site_config -> "XDG_CONFIG_DIRS"
+ end.
+
+basedir_xdg_def(Type,Home,Name) ->
+ case Type of
+ user_data -> filename:join([Home,".local","share",Name]);
+ user_config -> filename:join([Home,".config",Name]);
+ user_cache -> filename:join([Home,".cache",Name]);
+ user_log -> filename:join([Home,".cache",Name,"log"]);
+ site_data -> [filename:join([Dir,Name]) ||
+ Dir <- ["/usr/local/share/","/usr/share/"]];
+ site_config -> [filename:join(["/etc/xdg",Name])]
end.