1
0
forked from extern/nix-config
donovanglover-nix-config/tests/check_top_level_imports.cr

29 lines
863 B
Crystal
Raw Normal View History

2023-06-09 15:06:04 +02:00
require "spec"
2023-06-10 15:37:52 +02:00
require "colorize"
2023-06-09 15:06:04 +02:00
2023-06-10 15:37:52 +02:00
def check_top_level_imports(directory)
describe "./#{directory}/default.nix" do
it "imports all modules in ./#{directory}/", tags: "local" do
2023-06-10 15:37:52 +02:00
all_modules = Dir.children(directory)
all_modules.delete("default.nix")
modules = File.read("./#{directory}/default.nix")
all_modules.each do |current_module|
modules.includes?("./#{current_module}").should be_true
end
end
it "only imports modules that exist in ./#{directory}/", tags: "local" do
2023-06-10 15:37:52 +02:00
all_modules = Dir.children(directory)
all_modules.delete("default.nix")
File.each_line("./#{directory}/default.nix") do |line|
if line.includes? "./"
imported_file = line.lstrip(' ').lstrip("./")
all_modules.includes?(imported_file).should be_true
end
end
end
end
end