Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ SYNOPSIS
URIS

http://github.com/ahoward/systemu
http://rubyforge.org/projects/codeforpeople/

INSTALL

Expand Down
1 change: 0 additions & 1 deletion README.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SYNOPSIS
URIS

http://github.com/ahoward/systemu
http://rubyforge.org/projects/codeforpeople/

INSTALL

Expand Down
100 changes: 60 additions & 40 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
This.rubyforge_project = 'codeforpeople'
require 'rbconfig'

This.author = "Ara T. Howard"
This.email = "ara.t.howard@gmail.com"
This.homepage = "https://github.com/ahoward/#{ This.lib }"

desc('Write "Ruby" to a file "LICENSE"')
task :license do
open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
end

desc('Print all available tasks')
task :default do
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
end

desc('Run all tests')
task :test do
run_tests!
end

namespace :test do
desc('Run tests in a sub-directory "unit" of the test directory')
task(:unit){ run_tests!(:unit) }
desc('Run tests in a sub-directory "functional" of the test directory')
task(:functional){ run_tests!(:functional) }
desc('Run tests in a sub-directory "integration" of the test directory')
task(:integration){ run_tests!(:integration) }
end

##
# Run all or a sub-set of the scripts ending in "_test.rb" within the "test" dir
#
# The parameter "which" can be utilized to request that only tests within a
# sub-directory of a certain name of "test" shall be executed.
def run_tests!(which = nil)
which ||= '**'
test_dir = File.join(This.dir, "test")
Expand Down Expand Up @@ -59,7 +71,7 @@ def run_tests!(which = nil)
end
end


desc('Write the "systemu.gemspec" file')
task :gemspec do
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
ignore_directories = ['pkg']
Expand Down Expand Up @@ -145,7 +157,6 @@ task :gemspec do

spec.extensions.push(*<%= extensions.inspect %>)

spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
spec.author = <%= This.author.inspect %>
spec.email = <%= This.email.inspect %>
spec.homepage = <%= This.homepage.inspect %>
Expand All @@ -160,6 +171,7 @@ task :gemspec do
This.gemspec = gemspec
end

desc('Clean the "pkg" directory and (re-)create the gem file')
task :gem => [:clean, :gemspec] do
Fu.mkdir_p(This.pkgdir)
before = Dir['*.gem']
Expand All @@ -171,6 +183,7 @@ task :gem => [:clean, :gemspec] do
This.gem = File.join(This.pkgdir, File.basename(gem))
end

desc('Re-generate the "README" file from the samples and the template')
task :readme do
samples = ''
prompt = '~ > '
Expand Down Expand Up @@ -214,12 +227,12 @@ task :readme do
open("README", "w"){|fd| fd.puts template}
end


desc('Remove all files from the "pkg" directory')
task :clean do
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
end


desc('Clean existing gems, (re-)create gem and publish')
task :release => [:clean, :gemspec, :gem] do
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
raise "which one? : #{ gems.inspect }" if gems.size > 1
Expand All @@ -230,21 +243,14 @@ task :release => [:clean, :gemspec, :gem] do
puts
system(cmd)
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?

cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
puts cmd
puts
system(cmd)
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
end





BEGIN {
# support for this rakefile
#
# support for this rakefile
$VERBOSE = nil

require 'ostruct'
Expand All @@ -253,28 +259,26 @@ BEGIN {
require 'rbconfig'
require 'pp'

# fu shortcut
#
# create a shortcut "Fu" for FileUtils
Fu = FileUtils

# cache a bunch of stuff about this rakefile/environment
#
# cache a bunch of stuff about this Rakefile and its environment
This = OpenStruct.new

This.file = File.expand_path(__FILE__)
This.dir = File.dirname(This.file)
This.pkgdir = File.join(This.dir, 'pkg')

# grok lib
#
# determine the library's name
lib = ENV['LIB']
unless lib
# drop anything after (including) the last '-' from the directory name to
# derive the library's name
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
end
This.lib = lib

# grok version
#
# determine the library's version
version = ENV['VERSION']
unless version
require "./lib/#{ This.lib }"
Expand All @@ -284,62 +288,78 @@ BEGIN {
end
This.version = version

# see if dependencies are export by the module
#
# see if dependencies are export by the module
if This.object.respond_to?(:dependencies)
This.dependencies = This.object.dependencies
end

# we need to know the name of the lib an it's version
#
# the library's name and version are mandatory to be known
abort('no lib') unless This.lib
abort('no version') unless This.version

# discover full path to this ruby executable
#
c = Config::CONFIG
# discover the full path to this ruby executable
c = ::RbConfig::CONFIG
bindir = c["bindir"] || c['BINDIR']
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
ruby_ext = c['EXEEXT'] || ''
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
This.ruby = ruby

# some utils
#
##
# Module with utility methods used by the Rakefile
module Util
##
# Indent a string "s" with a number "n" of spaces
#
# The string will be un-intended with #unindent before the new indentation
# is being conducted.
def indent(s, n = 2)
s = unindent(s)
ws = ' ' * n
s.gsub(%r/^/, ws)
end

##
# Unindent a string "s"
#
# The indentation of the string is determined by the leading whitespaces of
# the first non-empty, non-entirely-whitespace line.
def unindent(s)
indent = nil
s.each_line do |line|
next if line =~ %r/^\s*$/
indent = line[%r/^\s*/] and break
next if line =~ %r/^\s*$/
indent = line[%r/^\s*/] and break
end
indent ? s.gsub(%r/^#{ indent }/, "") : s
end
indent ? s.gsub(%r/^#{ indent }/, "") : s
end

extend self
end

# template support
#
##
# Class for loading and executing ERB template code
class Template
##
# Create a new instance from a block returning the template's code
def initialize(&block)
@block = block
@template = block.call.to_s
end

##
# Execute the ERB template's block with an optional binding
#
# If no binding is given the binding of the blocked which got passed to the
# initializer will be used.
def expand(b=nil)
ERB.new(Util.unindent(@template)).result((b||@block).binding)
end

alias_method 'to_s', 'expand'
end
def Template(*args, &block) Template.new(*args, &block) end

# colored console output support
#
# colored console output support
This.ansi = {
:clear => "\e[0m",
:reset => "\e[0m",
Expand Down Expand Up @@ -369,6 +389,7 @@ BEGIN {
:on_cyan => "\e[46m",
:on_white => "\e[47m"
}

def say(phrase, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
options[:color] = args.shift.to_s.to_sym unless args.empty?
Expand All @@ -388,7 +409,6 @@ BEGIN {
Kernel.send(method, parts.join)
end

# always run out of the project dir
#
# always run out of the project dir itself
Dir.chdir(This.dir)
}
28 changes: 13 additions & 15 deletions lib/systemu.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require 'tmpdir'
require 'socket'
require 'fileutils'
Expand All @@ -11,29 +9,32 @@ def systemu(*a, &b) SystemUniversal.new(*a, &b).systemu end
end

class SystemUniversal
#
# constants
#
#
# constants
#
SystemUniversal::VERSION = '2.6.5' unless SystemUniversal.send(:const_defined?, :VERSION)
def SystemUniversal.version() SystemUniversal::VERSION end
def version() SystemUniversal::VERSION end
def SystemUniversal.description
"universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc."
end
#
# class methods
#

#
# instance variables
#
@host = Socket.gethostname
@ppid = Process.ppid
@pid = Process.pid
@turd = ENV['SYSTEMU_TURD']
@ruby = nil

#
# class methods
#
def self.ruby
return @ruby if @ruby

c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
c = ::RbConfig::CONFIG
ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
@ruby = if system(ruby, '-e', '42')
ruby
Expand All @@ -50,10 +51,9 @@ def quote(*words)
end
end

#
# instance methods
#

#
# instance methods
#
def initialize argv, opts = {}, &block
getopt = getopts opts

Expand Down Expand Up @@ -180,8 +180,6 @@ def quietly

def child_program config
<<-program
# encoding: utf-8

PIPE = STDOUT.dup
begin
config = Marshal.load(IO.read('#{ config }',:mode=>"rb"))
Expand Down
1 change: 0 additions & 1 deletion systemu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Gem::Specification::new do |spec|

spec.extensions.push(*[])

spec.rubyforge_project = "codeforpeople"
spec.author = "Ara T. Howard"
spec.email = "ara.t.howard@gmail.com"
spec.homepage = "https://github.com/ahoward/systemu"
Expand Down
10 changes: 10 additions & 0 deletions test/systemu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
end
end

testing 'query systemu version' do
# query systemu's version through the class itself
assert { SystemU.version =~ /\d+\.\d+\.\d+/ }
# query systemu's version through a class instance
assert do
a = SystemU.new('ls')
a.version =~ /\d+\.\d+\.\d+/
end
end

end


Expand Down