@@ -195,7 +195,7 @@ defmodule Mix.Tasks.Compile.ElixirTest do
195195 end )
196196 end
197197
198- test "compiles mtime changed files" do
198+ test "compiles mtime changed files if content changed but not length " do
199199 in_fixture ( "no_mixfile" , fn ->
200200 assert Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] ) == { :ok , [ ] }
201201 assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
@@ -204,6 +204,8 @@ defmodule Mix.Tasks.Compile.ElixirTest do
204204 Mix . shell ( ) . flush
205205 purge ( [ A , B ] )
206206
207+ same_length_content = "lib/a.ex" |> File . read! ( ) |> String . replace ( "A" , "Z" )
208+ File . write! ( "lib/a.ex" , same_length_content )
207209 future = { { 2038 , 1 , 1 } , { 0 , 0 , 0 } }
208210 File . touch! ( "lib/a.ex" , future )
209211 Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] )
@@ -225,6 +227,36 @@ defmodule Mix.Tasks.Compile.ElixirTest do
225227 end )
226228 end
227229
230+ test "does not recompile mtime changed but identical files" do
231+ in_fixture ( "no_mixfile" , fn ->
232+ assert Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] ) == { :ok , [ ] }
233+ assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
234+ assert_received { :mix_shell , :info , [ "Compiled lib/b.ex" ] }
235+
236+ Mix . shell ( ) . flush
237+ purge ( [ A , B ] )
238+
239+ future = { { 2038 , 1 , 1 } , { 0 , 0 , 0 } }
240+ File . touch! ( "lib/a.ex" , future )
241+ Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] )
242+
243+ message =
244+ "warning: mtime (modified time) for \" lib/a.ex\" was set to the future, resetting to now"
245+
246+ assert_received { :mix_shell , :error , [ ^ message ] }
247+
248+ message =
249+ "warning: mtime (modified time) for \" lib/b.ex\" was set to the future, resetting to now"
250+
251+ refute_received { :mix_shell , :error , [ ^ message ] }
252+ refute_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
253+ refute_received { :mix_shell , :info , [ "Compiled lib/b.ex" ] }
254+
255+ File . touch! ( "_build/dev/lib/sample/.mix/compile.elixir" , future )
256+ assert Mix.Tasks.Compile.Elixir . run ( [ ] ) == { :noop , [ ] }
257+ end )
258+ end
259+
228260 test "compiles size changed files" do
229261 in_fixture ( "no_mixfile" , fn ->
230262 past = { { 2010 , 1 , 1 } , { 0 , 0 , 0 } }
@@ -257,8 +289,7 @@ defmodule Mix.Tasks.Compile.ElixirTest do
257289 Mix . shell ( ) . flush
258290 purge ( [ A , B ] )
259291
260- future = { { 2038 , 1 , 1 } , { 0 , 0 , 0 } }
261- File . touch! ( "lib/b.ex" , future )
292+ force_recompilation ( "lib/b.ex" )
262293 Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] )
263294
264295 assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
@@ -283,7 +314,7 @@ defmodule Mix.Tasks.Compile.ElixirTest do
283314
284315 Code . put_compiler_option ( :ignore_module_conflict , true )
285316 Code . compile_file ( "lib/b.ex" )
286- File . touch! ( "lib/a.ex" , { { 2038 , 1 , 1 } , { 0 , 0 , 0 } } )
317+ force_recompilation ( "lib/a.ex" )
287318
288319 Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] )
289320 assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
@@ -472,8 +503,7 @@ defmodule Mix.Tasks.Compile.ElixirTest do
472503 assert_received { :mix_shell , :info , [ "Compiled lib/b.ex" ] }
473504 purge ( [ A , B ] )
474505
475- future = { { 2038 , 1 , 1 } , { 0 , 0 , 0 } }
476- File . touch! ( "lib/a.ex" , future )
506+ force_recompilation ( "lib/a.ex" )
477507
478508 assert Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] ) == { :ok , [ ] }
479509 assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
@@ -615,8 +645,7 @@ defmodule Mix.Tasks.Compile.ElixirTest do
615645 Mix . shell ( ) . flush
616646 purge ( [ A , B ] )
617647
618- future = { { 2038 , 1 , 1 } , { 0 , 0 , 0 } }
619- File . touch! ( "lib/a.ex" , future )
648+ force_recompilation ( "lib/a.ex" )
620649 Mix.Tasks.Compile.Elixir . run ( [ "--verbose" ] )
621650
622651 assert_received { :mix_shell , :info , [ "Compiled lib/a.ex" ] }
0 commit comments