Skip to content

Instantly share code, notes, and snippets.

@cho45

cho45/mruby_build_test.rb

Last active Aug 29, 2015
Embed
What would you like to do?
#!/usr/bin/env ruby
MRUBY_CONFIG = 'sketch_mruby_config.rb'
File.open(MRUBY_CONFIG, "w") do |f|
f.puts `git show HEAD:build_config.rb`
end
ENV['MRUBY_CONFIG'] = MRUBY_CONFIG
def enable_gems
warn "enable_gems"
build_config = File.read(MRUBY_CONFIG)
File.open(MRUBY_CONFIG, "w") do |f|
f.puts build_config.gsub(/^#:test: (.+)$/) { Regexp.last_match[1] }
end
end
def disable_gems
warn "disable_gems"
build_config = File.read(MRUBY_CONFIG)
File.open(MRUBY_CONFIG, "w") do |f|
f.puts build_config.gsub(/^\s*conf\.gem.*$/) { "#:test: #{Regexp.last_match[0]}" }
end
end
def info(s)
puts "\x1b[31;1m#{s}\x1b[0m"
end
def write_files
data = DATA.read.split(/^== (.+)/)
data.shift
data.each_slice(2) do |name, content|
File.open(name, "w") do |f|
f.puts content
end
info "Wrote #{name}"
end
end
write_files
info "Default #{'=' * 50}"
system("rake clean")
system("rake")
system("./bin/mrbc -Bcode sketch.rb && gcc -Iinclude/ -Lbuild/host/lib -lmruby -o sketch sketch_loader.c")
system("./sketch")
info "Expected exitstatus:0 got:#{ $?.exitstatus }"
puts
system("rake clean > /dev/null")
info "Disable all gems (DISABLE_GEMS=1) #{'=' * 50}"
disable_gems
system("rake")
system("./bin/mrbc -Bcode sketch.rb && gcc -Iinclude/ -Lbuild/host/lib -lmruby -o sketch sketch_loader.c")
system("./sketch")
info "Expected exitstatus:255 got:#{ $?.exitstatus }"
puts
info "Re-enable gems without `rake clean`"
enable_gems
system("rake")
system("./bin/mrbc -Bcode sketch.rb && gcc -Iinclude/ -Lbuild/host/lib -lmruby -o sketch sketch_loader.c")
system("./sketch")
info "Build summary includes `Included Gems` but actually not."
info "Expected exitstatus:0 got:#{ $?.exitstatus }"
puts
__END__
== sketch_loader.c
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/data.h"
#include "mruby/compile.h"
#include "mruby/string.h"
#include "mruby/numeric.h"
#include <math.h>
#include <stdlib.h>
#include "sketch.c"
int main (int argc, char **argv) {
mrb_state* mrb;
mrb_value ret;
mrb = mrb_open();
if (mrb == NULL) return 1;
ret = mrb_load_irep(mrb, code);
if (mrb->exc) {
return -1;
}
mrb_close(mrb);
return 0;
}
== sketch.rb
rand # rand is from mrbgems/mruby-random
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.