Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replaced Sprout::Log with Sprout.stdout and added fakes for the test …

…helper
  • Loading branch information...
commit 93525c1233a5e3e2bfcbdc12228de782fa4b8b72 1 parent f6dc4ee
@lukebayes authored
View
1  .gitignore
@@ -1,6 +1,7 @@
.svn
.DS_Store
*.gem
+*.log
pkg
doc
doc/**/**/*
View
27 lib/sprout.rb
@@ -5,13 +5,14 @@
# External tools and std libs:
require 'rake'
require 'delegate'
+require 'logger'
# Core, Process and Platform support:
require 'sprout/version'
+require 'sprout/output_buffer'
require 'sprout/progress_bar'
require 'sprout/dir'
require 'sprout/string'
-require 'sprout/log'
require 'sprout/errors'
require 'sprout/platform'
require 'sprout/process_runner'
@@ -94,6 +95,30 @@ def generator_cache
def current_system
Sprout::System.create
end
+
+ def stdout=(out)
+ @stdout = out
+ end
+
+ def stdout
+ @stdout ||= $stdout
+ end
+
+ def stdout_test
+ OutputBuffer.new 'test-stdout.log'
+ end
+
+ def stderr=(err)
+ @stderr = err
+ end
+
+ def stderr
+ @stderr ||= $stderr
+ end
+
+ def stderr_test
+ OutputBuffer.new 'test-stderr.log'
+ end
##
# @return [File] Path to the file from the 'caller' property of
View
6 lib/sprout/daemon.rb
@@ -213,8 +213,8 @@ def wait_for_prompt expected_prompt=nil
if char == "\n"
line = ''
end
- Sprout::Log.printf char
- Sprout::Log.flush
+ Sprout.stdout.printf char
+ Sprout.stdout.flush
return true unless line.match(expected_prompt).nil?
end
end
@@ -286,7 +286,7 @@ def execute_actions
# Execute a single action.
def execute_action action, silence=false
action = action.strip
- Sprout::Log.puts(action) unless silence
+ Sprout.stdout.puts(action) unless silence
process_runner.puts action
wait_for_prompt
end
View
6 lib/sprout/library.rb
@@ -179,7 +179,7 @@ def define_lib_dir_task_if_necessary dir
if !File.exists?(dir)
define_file_task dir do
FileUtils.mkdir_p dir
- Sprout::Log.puts ">> Created directory at: #{dir}"
+ Sprout.stdout.puts ">> Created directory at: #{dir}"
end
end
end
@@ -196,7 +196,7 @@ def define_project_path_task pkg_name, path
def define_directory_copy_task path, install_path
define_file_task install_path do
FileUtils.cp_r path, install_path
- Sprout::Log.puts ">> Copied files from: (#{path}) to: (#{install_path})"
+ Sprout.stdout.puts ">> Copied files from: (#{path}) to: (#{install_path})"
end
install_path
end
@@ -206,7 +206,7 @@ def define_file_copy_task path, install_path
define_file_task task_name do
FileUtils.mkdir_p install_path
FileUtils.cp path, "#{install_path}/"
- Sprout::Log.puts ">> Copied file from: (#{path}) to: (#{task_name})"
+ Sprout.stdout.puts ">> Copied file from: (#{path}) to: (#{task_name})"
end
task_name
end
View
46 lib/sprout/log.rb
@@ -1,46 +0,0 @@
-
-module Sprout
- class Log
- @@debug = false
- @@output = ''
- @@printout = ''
-
- def Log.debug=(debug)
- @@debug = debug
- end
-
- def Log.debug
- return @@debug
- end
-
- def Log.puts(msg)
- @@output << msg + "\n"
- Log.flush
- end
-
- def Log.print(msg)
- @@printout << msg
- Log.flush_print
- end
-
- def Log.printf(msg)
- @@printout << msg
- Log.flush_print
- end
-
- def Log.flush_print
- if(!Log.debug)
- $stdout.printf @@printout
- @@printout = ''
- end
- end
-
- def Log.flush
- if(!Log.debug)
- $stdout.printf @@output
- @@output = ''
- end
- end
- end
-end
-
View
35 lib/sprout/output_buffer.rb
@@ -0,0 +1,35 @@
+
+module Sprout
+
+ class OutputBuffer < Logger
+
+ def initialize *args
+ super
+ @characters = ''
+ end
+
+ def puts msg
+ flush if @characters.size > 0
+ info msg
+ end
+
+ def print msg
+ @characters << msg
+ flush
+ end
+
+ def printf msg
+ @characters << msg
+ flush
+ end
+
+ def flush
+ if @characters.match /\n/
+ info @characters
+ @characters = ''
+ end
+ end
+
+ end
+end
+
View
2  lib/sprout/remote_file_target.rb
@@ -44,7 +44,7 @@ def unpacked_file
protected
def logger
- Sprout::Log
+ Sprout.stdout
end
def expand_local_path path
View
4 lib/sprout/system/base_system.rb
@@ -68,13 +68,13 @@ def can_execute? platform
# Raises a +Sprout::Errors::ExecutionError+ if the process writes to stderr
#
def execute(tool, options='')
- Sprout::Log.puts("#{tool} #{options}")
+ Sprout.stdout.puts("#{tool} #{options}")
runner = get_and_execute_process_runner(tool, options)
error = runner.read_err
result = runner.read
if(result.size > 0)
- Sprout::Log.puts result
+ Sprout.stdout.puts result
end
if(error.size > 0)
View
2  lib/sprout/system/unix_system.rb
@@ -50,7 +50,7 @@ def attempt_to_repair_executable path
def repair_executable path
content = File.read(path)
if(content.match(/\r\n/))
- Sprout::Log.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
+ Sprout.stdout.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
content.gsub!(/\r\n/, "\n")
File.open(path, 'w+') do |f|
f.write content
View
5 lib/sprout/test_helper.rb
@@ -424,8 +424,9 @@ def find_reached_root? path
# bare_setup - place this in setup method to create the app_root folder for each test
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or app_root folder after each test
-
# Prevent log messages from interrupting the test output:
-Sprout::Log.debug = true
+Sprout.stdout = Sprout.stdout_test
+Sprout.stderr = Sprout.stderr_test
+
#Sprout::ProgressBar.debug = true
View
2  test/unit/daemon_test.rb
@@ -7,8 +7,6 @@ class DaemonTest < Test::Unit::TestCase
context "a new daemon delegate" do
setup do
- # Uncomment to see actual output:
- #Sprout::Log.debug = false
configure_fdb_fake
end
Please sign in to comment.
Something went wrong with that request. Please try again.