-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compiler command
crystal clear_cache
(#13553)
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
- Loading branch information
1 parent
33a74d1
commit a12dcf8
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "../../../spec_helper" | ||
|
||
class Crystal::CacheDir | ||
class_setter instance | ||
|
||
def initialize(@dir) | ||
Dir.mkdir_p(dir) | ||
end | ||
end | ||
|
||
describe Crystal::Command do | ||
describe "clear_cache" do | ||
around_each do |example| | ||
old_cache_dir = CacheDir.instance | ||
temp_dir_name = File.tempname | ||
begin | ||
CacheDir.instance = CacheDir.new(temp_dir_name) | ||
example.run | ||
ensure | ||
FileUtils.rm_rf(temp_dir_name) | ||
CacheDir.instance = old_cache_dir | ||
end | ||
end | ||
|
||
it "clears any cached compiler files" do | ||
file_path = File.tempname(dir: CacheDir.instance.dir) | ||
Dir.mkdir_p(File.dirname(file_path)) | ||
File.touch(file_path) | ||
File.exists?(file_path).should be_true | ||
|
||
Crystal::Command.run(["clear_cache"]) | ||
|
||
File.exists?(file_path).should be_false | ||
File.exists?(CacheDir.instance.dir).should be_false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Implementation of the `crystal clear_cache` command | ||
|
||
class Crystal::Command | ||
private def clear_cache | ||
verbose = false | ||
OptionParser.parse(@options) do |opts| | ||
opts.banner = <<-'BANNER' | ||
Usage: crystal clear_cache | ||
|
||
Clears the compiler cache | ||
|
||
Options: | ||
BANNER | ||
|
||
opts.on("-h", "--help", "Show this message") do | ||
puts opts | ||
exit | ||
end | ||
|
||
opts.on("-v", "--verbose", "Display detailed information") do | ||
verbose = true | ||
end | ||
end | ||
puts "Clearing compiler cache at #{CacheDir.instance.dir.inspect}" if verbose | ||
FileUtils.rm_rf(CacheDir.instance.dir) | ||
end | ||
end |