Commit ece23e64 authored by Yan Couto's avatar Yan Couto

Making tests self-contained

test_all runs all tests automatically.
no_cycles checks local packages instead of packages in /usr/local/lib
Added REAME for explanation.
Modifying crew file to have a "init only" functionality
parent 0e3e0c6a
...@@ -70,20 +70,6 @@ USER = `whoami`.chomp ...@@ -70,20 +70,6 @@ USER = `whoami`.chomp
$LOAD_PATH.unshift "#{CREW_LIB_PATH}lib" $LOAD_PATH.unshift "#{CREW_LIB_PATH}lib"
# Parse arguments using docopt
require 'docopt'
begin
args = Docopt::docopt(DOC)
rescue Docopt::Exit => e
puts e.message
exit 1
end
@opt_keep = args["--keep"]
@opt_verbose = args["--verbose"]
@opt_src = args["--build-from-source"]
# colorization # colorization
class String class String
def colorize(color_code, shade) def colorize(color_code, shade)
...@@ -155,9 +141,24 @@ class String ...@@ -155,9 +141,24 @@ class String
end end
end end
return 0 if defined? CREW_INIT_ONLY
#disallow sudo #disallow sudo
abort "Chromebrew should not be run as root.".lightred if Process.uid == 0 abort "Chromebrew should not be run as root.".lightred if Process.uid == 0
# Parse arguments using docopt
require 'docopt'
begin
args = Docopt::docopt(DOC)
rescue Docopt::Exit => e
puts e.message
exit 1
end
@opt_keep = args["--keep"]
@opt_verbose = args["--verbose"]
@opt_src = args["--build-from-source"]
@device = JSON.parse(File.read(CREW_CONFIG_PATH + 'device.json'), symbolize_names: true) @device = JSON.parse(File.read(CREW_CONFIG_PATH + 'device.json'), symbolize_names: true)
#symbolize also values #symbolize also values
@device.each do |key, elem| @device.each do |key, elem|
......
## Creating tests
To create a test, just create a `.rb` file. It should finish normally if the test passed, and end with `exit 1` otherwise, preferably explaining why the test failed.
## Running tests
Just run the `test_all` file. Running tests manually may not work!
require 'find'
@all_pkgs = {}
# Loads all packages
Find.find("../packages") do |filename|
if File.extname(filename) == '.rb'
name = File.basename(filename, '.rb')
require("../packages/" + name)
pkg = Object.const_get(name.capitalize)
pkg.name = name
@all_pkgs[name] = pkg
end
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.
@state = {}
@path = []
def dfs(pkg)
@path.push(pkg.name)
if @state[pkg] == :on_path
puts "Found dependency cycle!".lightred
while @path.first != @path.last
@path.shift
end
puts @path.to_s
exit 1
elsif @state[pkg] == nil
@state[pkg] = :on_path
if pkg.dependencies
pkg.dependencies.each do |name, v|
if name != pkg.name
dfs(@all_pkgs[name])
end
end
end
@state[pkg] = :visited
end
@path.pop
end
# Calls dfs for every path
@all_pkgs.each do |name, pkg|
dfs(pkg)
end
puts "No dependency cycles found.".lightgreen
#!/usr/bin/env ruby
CREW_INIT_ONLY = true
load '../crew'
puts "Running tests..."
Find.find(".") do |filename|
if File.extname(filename) == '.rb'
puts "\nTest Name: #{File.basename(filename, ".rb")}"
load filename
end
end
puts "\nAll tests successful.".lightgreen
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment