From ed8a8b26a9827bb4eacefe47ffc6e5a74fd545c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 16 Aug 2023 11:07:35 +0200 Subject: [PATCH] Remove double .cr extensions --- spec/compiler/crystal_path/crystal_path_spec.cr | 16 ++++++++-------- src/compiler/crystal/crystal_path.cr | 13 +++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/compiler/crystal_path/crystal_path_spec.cr b/spec/compiler/crystal_path/crystal_path_spec.cr index 1270e0875030..d9ecb3f0b9f2 100644 --- a/spec/compiler/crystal_path/crystal_path_spec.cr +++ b/spec/compiler/crystal_path/crystal_path_spec.cr @@ -111,8 +111,8 @@ describe Crystal::CrystalPath do it "foo.cr" do assert_iterates_yielding [ "x/foo.cr", - "x/foo.cr/foo.cr.cr", - "x/foo.cr/src/foo.cr.cr", + "x/foo.cr/foo.cr", + "x/foo.cr/src/foo.cr", ], path.each_file_expansion("foo.cr", "x") end @@ -130,11 +130,11 @@ describe Crystal::CrystalPath do it "foo.cr/bar.cr" do assert_iterates_yielding [ "x/foo.cr/bar.cr", - "x/foo.cr/src/bar.cr.cr", - "x/foo.cr/src/foo.cr/bar.cr.cr", - "x/foo.cr/bar.cr/bar.cr.cr", - "x/foo.cr/src/bar.cr/bar.cr.cr", - "x/foo.cr/src/foo.cr/bar.cr/bar.cr.cr", + "x/foo.cr/src/bar.cr", + "x/foo.cr/src/foo.cr/bar.cr", + "x/foo.cr/bar.cr/bar.cr", + "x/foo.cr/src/bar.cr/bar.cr", + "x/foo.cr/src/foo.cr/bar.cr/bar.cr", ], path.each_file_expansion("foo.cr/bar.cr", "x") end @@ -156,7 +156,7 @@ describe Crystal::CrystalPath do it "./foo.cr" do assert_iterates_yielding [ "x/./foo.cr", - "x/./foo.cr/foo.cr.cr", + "x/./foo.cr/foo.cr", ], path.each_file_expansion("./foo.cr", "x") end diff --git a/src/compiler/crystal/crystal_path.cr b/src/compiler/crystal/crystal_path.cr index 0e2da64781cd..c6064d04c0fd 100644 --- a/src/compiler/crystal/crystal_path.cr +++ b/src/compiler/crystal/crystal_path.cr @@ -138,27 +138,28 @@ module Crystal if !filename_is_relative && shard_path shard_src = "#{relative_to}/#{shard_name}/src" + shard_path_stem = shard_path.rchop(".cr") # If it's "foo/bar/baz", check if "foo/src/bar/baz.cr" exists (for a shard, non-namespaced structure) - yield "#{shard_src}/#{shard_path}.cr" + yield "#{shard_src}/#{shard_path_stem}.cr" # Then check if "foo/src/foo/bar/baz.cr" exists (for a shard, namespaced structure) - yield "#{shard_src}/#{shard_name}/#{shard_path}.cr" + yield "#{shard_src}/#{shard_name}/#{shard_path_stem}.cr" # If it's "foo/bar/baz", check if "foo/bar/baz/baz.cr" exists (std, nested) - basename = File.basename(relative_filename) + basename = File.basename(relative_filename, ".cr") yield "#{relative_filename}/#{basename}.cr" # If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, non-namespaced, nested) - yield "#{shard_src}/#{shard_path}/#{shard_path}.cr" + yield "#{shard_src}/#{shard_path}/#{shard_path_stem}.cr" # If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, namespaced, nested) - yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path}.cr" + yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path_stem}.cr" return nil end - basename = File.basename(relative_filename) + basename = File.basename(relative_filename, ".cr") # If it's "foo", check if "foo/foo.cr" exists (for the std, nested) yield "#{relative_filename}/#{basename}.cr"