File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,17 @@ defmodule Temp do
122
122
end
123
123
end
124
124
125
+ @ doc """
126
+ Function allows add file to tracker, which will be removed on Temp.cleanup
127
+ """
128
+ @ spec track_file ( any ) :: { :error , :tracker_not_found } | { :ok , Path . t }
129
+ def track_file ( path , tracker \\ get_tracker ( ) ) do
130
+ case is_nil ( tracker ) do
131
+ true -> { :error , :tracker_not_found }
132
+ false -> { :ok , register_path ( tracker , path ) }
133
+ end
134
+ end
135
+
125
136
@ doc """
126
137
Same as `open/1`, but raises an exception on failure.
127
138
"""
Original file line number Diff line number Diff line change @@ -120,4 +120,19 @@ defmodule TempTest do
120
120
assert_receive { :cleaned , 1 }
121
121
refute File . exists? ( dir )
122
122
end
123
+
124
+ test :track_file do
125
+ assert { :ok , tracker } = Temp . track
126
+
127
+ path_of_tmp_file = "test/tmp_file_created_by_programmer"
128
+ File . write! ( path_of_tmp_file , "Make Elixir Gr8 Again" )
129
+
130
+ assert File . exists? ( path_of_tmp_file )
131
+
132
+ Temp . track_file ( path_of_tmp_file , tracker )
133
+
134
+ Temp . cleanup ( tracker )
135
+
136
+ refute File . exists? ( path_of_tmp_file )
137
+ end
123
138
end
You can’t perform that action at this time.
0 commit comments