Files
chromebrew/tests/cycle_test
Maximilian Downey Twiss 7a5eff8945 Miscellaneous crew changes (#9311)
* Make greater use of File.join when loading device.json

* Remove redundant check that the compatibility property exists (already checked by prop_test as part of CI)

* Don't pass architecture to lib/package.rb

* Replace @device[:architecture] with ARCH, do not create architecture section in device.json

* Refactor getting urls and sha256s in package.rb

* Use inplace sort on installed_packages instead of creating sorted_installed_packages

* Rework load_package to always only take one argument

* Only rescue package loading errors in set_package

* Remove generate_compatible

* Replace all calls to load_package with set_package

* Use _args instead of _ in prop_command

* Merge @short_verbose and @verbose

* Simplify filename detection in download

* Bump crew version
2024-02-12 12:38:18 -05:00

68 lines
1.5 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# This test checks whether the packages create a dependency cycle.
# Add >LOCAL< lib to LOAD_PATH
$LOAD_PATH.unshift '../lib'
require 'find'
require_relative '../lib/const'
require_relative '../lib/color'
require_relative '../lib/package'
@all_pkgs = {}
puts "Running dependency cycle tests...\n".yellow
# Loads all packages
Dir['../packages/*.rb'].each do |filename|
pkg = Package.load_package(filename)
@all_pkgs[name] = pkg
end
# Looking for cycles. @path will keep the current dependency path.
# @state will store :on_path for vertices on the current dependency path
# and :visited for vertices that have already been checked not to lead to
# cycles.
@failed = 0
@state = {}
@path = []
@uniq_path = []
def dfs(pkg)
@path.push(pkg.name)
case @state[pkg]
when :on_path
@path.shift while @path.first != @path.last
if (!@uniq_path.include? @path.to_s) && @path.to_s.include?(',')
@uniq_path.push(@path.to_s)
@failed += 1
end
when nil
@state[pkg] = :on_path
pkg.dependencies&.each_key do |name|
dfs(@all_pkgs[name]) if name != pkg.name
end
@state[pkg] = :visited
end
@path.pop
end
# Calls dfs for every path
@all_pkgs.each_value do |pkg|
dfs(pkg)
end
# Display dependency cycles
@uniq_path.sort.each do |path|
puts path.lightred
end
@cycles = 'cycles'
@cycles = 'cycle' if @failed == 1
if @failed.positive?
abort "\n#{@failed} dependency #{@cycles} found.".lightred
else
puts "\nNo dependency cycles found.".lightgreen
end