Skip to content

Commit

Permalink
Fix: constants are now always resolved first
Browse files Browse the repository at this point in the history
This change in crystal caused the test suite to use the default
`.shards` and `libs` folders instead of the specified ones in the
`test` folder.
  • Loading branch information
ysbaddaden committed May 5, 2016
1 parent 333bdca commit ca0e505
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/commands/prune.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module Shards
return unless lockfile?
locks = Lock.from_file(lockfile_path)

Dir[File.join(INSTALL_PATH, "*")].each do |path|
Dir[File.join(Shards.install_path, "*")].each do |path|
next unless Dir.exists?(path)
name = File.basename(path)

if locks.none? { |d| d.name == name }
FileUtils.rm_rf(path)
Shards.logger.info "Pruned #{File.join(File.basename(INSTALL_PATH), name)}"
Shards.logger.info "Pruned #{File.join(File.basename(Shards.install_path), name)}"
end
end
end
Expand Down
17 changes: 14 additions & 3 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ module Shards
SPEC_FILENAME = "shard.yml"
LOCK_FILENAME = "shard.lock"

CACHE_DIRECTORY = ENV["SHARDS_CACHE_PATH"]? || File.join(Dir.current, ".shards")
INSTALL_PATH = ENV["SHARDS_INSTALL_PATH"]? || File.join(Dir.current, "libs")

DEFAULT_COMMAND = "install"
DEFAULT_VERSION = "0"

def self.cache_path
@@cache_path ||= ENV.fetch("SHARDS_CACHE_PATH", File.join(Dir.current, ".shards"))

This comment has been minimized.

Copy link
@luislavena

luislavena May 6, 2016

Contributor

By using ENV.fetch(var, default) syntax, the default part is always evaluated, even when var is set. Shouldn't block version be used instead?

ENV.fetch("SHARDS_CACHE_PATH") { File.join(Dir.current, ".shards") }

This comment has been minimized.

Copy link
@ysbaddaden

ysbaddaden May 6, 2016

Author Contributor

Good point. Mind to propose a PR?

This comment has been minimized.

Copy link
@luislavena

luislavena May 6, 2016

Contributor

@ysbaddaden sure! will get to it at my lunch break! 😄

This comment has been minimized.

Copy link
@luislavena

luislavena May 6, 2016

Contributor

Sent! #104 😄

end

def self.cache_path=(@@cache_path : String)
end

def self.install_path
@@install_path ||= ENV.fetch("SHARDS_INSTALL_PATH", File.join(Dir.current, "libs"))
end

def self.install_path=(@@install_path : String)
end

@@production = false

def self.production?
Expand Down
6 changes: 3 additions & 3 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ module Shards
end

def sha1_path
File.join(CACHE_DIRECTORY, "#{ dependency.name }.sha1")
File.join(Shards.cache_path, "#{ dependency.name }.sha1")
end

def local_path
File.join(CACHE_DIRECTORY, dependency.name)
File.join(Shards.cache_path, dependency.name)
end

def git_url
Expand Down Expand Up @@ -177,7 +177,7 @@ module Shards
end

private def clone_repository
Dir.mkdir_p(CACHE_DIRECTORY) unless Dir.exists?(CACHE_DIRECTORY)
Dir.mkdir_p(Shards.cache_path) unless Dir.exists?(Shards.cache_path)
run "git clone --mirror --quiet -- #{FileUtils.escape git_url} #{dependency.name}",
path: File.dirname(local_path)
rescue Error
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/resolver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Shards
end

protected def install_path
File.join(INSTALL_PATH, dependency.name)
File.join(Shards.install_path, dependency.name)
end

protected def cleanup_install_directory
Expand Down
13 changes: 6 additions & 7 deletions test/test_helper.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
require "minitest/autorun"

ENV["SHARDS_CACHE_PATH"] = File.expand_path("../.shards", __FILE__)
ENV["SHARDS_INSTALL_PATH"] = File.expand_path("../.libs", __FILE__)

require "../src/config"
require "../src/logger"
require "../src/manager"

Shards.cache_path = File.join(__DIR__, ".shards")
Shards.install_path = File.join(__DIR__, ".libs")

require "./support/factories"
require "./support/mock_resolver"

Expand All @@ -22,11 +21,11 @@ class Minitest::Test

def clear_repositories
run "rm -rf #{ tmp_path }/*"
run "rm -rf #{ Shards::CACHE_DIRECTORY }/*"
run "rm -rf #{ Shards::INSTALL_PATH }/*"
run "rm -rf #{ Shards.cache_path }/*"
run "rm -rf #{ Shards.install_path }/*"
end

def install_path(project, *path_names)
File.join(Shards::INSTALL_PATH, project, *path_names)
File.join(Shards.install_path, project, *path_names)
end
end

0 comments on commit ca0e505

Please sign in to comment.