forked from extern/nix-config
tests: Modularize import checker
This commit is contained in:
parent
36ddba7e9b
commit
c91d02adc0
@ -1,38 +1,7 @@
|
||||
require "spec"
|
||||
require "colorize"
|
||||
require "./spec_helper"
|
||||
|
||||
hint = ""
|
||||
|
||||
describe "./modules/default.nix" do
|
||||
it "imports all modules in directory" do
|
||||
all_modules = Dir.children("modules")
|
||||
all_modules.delete("default.nix")
|
||||
modules = File.read("./modules/default.nix")
|
||||
|
||||
all_modules.each do |current_module|
|
||||
hint = "Missing ./#{current_module} import in ./modules/default.nix."
|
||||
modules.includes?("./#{current_module}").should be_true
|
||||
end
|
||||
|
||||
hint = ""
|
||||
end
|
||||
|
||||
it "only imports modules that exist" do
|
||||
all_modules = Dir.children("modules")
|
||||
all_modules.delete("default.nix")
|
||||
|
||||
File.each_line("./modules/default.nix") do |line|
|
||||
if line.includes? "./"
|
||||
imported_file = line.lstrip(' ').lstrip("./")
|
||||
hint = "./#{imported_file} was imported but doesn't exist in directory ./modules/."
|
||||
all_modules.includes?(imported_file).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
hint = ""
|
||||
end
|
||||
end
|
||||
check_top_level_imports("modules")
|
||||
|
||||
describe "./overlays/joshuto/default.nix" do
|
||||
it "uses the latest joshuto commit" do
|
||||
@ -45,7 +14,3 @@ describe "./overlays/rofi/default.nix" do
|
||||
check_latest_commit("lbonn/rofi", branch: "wayland")
|
||||
end
|
||||
end
|
||||
|
||||
Spec.after_suite do
|
||||
hint.empty? || puts "✗ #{hint}".colorize(:yellow)
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
require "spec"
|
||||
require "http/client"
|
||||
require "json"
|
||||
require "colorize"
|
||||
|
||||
def check_latest_commit(repository, branch = "master")
|
||||
response = HTTP::Client.get "https://api.github.com/repos/#{repository}/branches/#{branch}"
|
||||
@ -14,3 +15,41 @@ def check_latest_commit(repository, branch = "master")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
hint = ""
|
||||
|
||||
def check_top_level_imports(directory)
|
||||
describe "./#{directory}/default.nix" do
|
||||
it "imports all modules in directory" do
|
||||
all_modules = Dir.children(directory)
|
||||
all_modules.delete("default.nix")
|
||||
modules = File.read("./#{directory}/default.nix")
|
||||
|
||||
all_modules.each do |current_module|
|
||||
hint = "Missing ./#{current_module} import in ./#{directory}/default.nix."
|
||||
modules.includes?("./#{current_module}").should be_true
|
||||
end
|
||||
|
||||
hint = ""
|
||||
end
|
||||
|
||||
it "only imports modules that exist" do
|
||||
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("./")
|
||||
hint = "./#{imported_file} was imported but doesn't exist in directory ./#{directory}/."
|
||||
all_modules.includes?(imported_file).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
hint = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Spec.after_suite do
|
||||
hint.empty? || puts "✗ #{hint}".colorize(:yellow)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user