Sha256: 958c153a71b7d08eff68069b781bef043c3dd266463eb2b8ab92912c53d91fb1

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

# -*- encoding: utf-8 -*-

require 'test/unit'
require 'helper'
require 'webgen/tag'

class TestTagExecuteCommand < Test::Unit::TestCase

  include Test::WebsiteHelper

  def setup
    super
    @obj = Webgen::Tag::ExecuteCommand.new
  end

  def call(context, command, process, escape)
    @obj.set_params({'tag.executecommand.command' => command,
                      'tag.executecommand.process_output' => process,
                      'tag.executecommand.escape_html' => escape})
    result = @obj.call('execute_cmd', '', context)
    @obj.set_params({})
    [result.first.chomp.strip, result.last]
  end

  def test_call
    root = Webgen::Node.new(Webgen::Tree.new.dummy_root, '/', '/')
    context = Webgen::Context.new(:chain => [root])

    test_text = "a\"b\""
    assert_equal([test_text, false], call(context, echo_cmd(test_text), false, false))
    assert_equal([test_text, true], call(context, echo_cmd(test_text), true, false))
    assert_equal(['a&quot;b&quot;', true], call(context, echo_cmd(test_text), true, true))
    assert_equal(['a&quot;b&quot;', true], call(context, echo_cmd(test_text), true, true))
    assert_raise(Webgen::RenderError) { call(context, 'invalid_echo_command', true, true) }
  end

  def echo_cmd(data)
    (Config::CONFIG['host_os'] =~ /mswin|mingw/ ?  "echo #{data}" : "echo '#{data}'")
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
webgen-0.5.17 test/test_tag_executecommand.rb
webgen-0.5.15 test/test_tag_executecommand.rb
webgen-0.5.14 test/test_tag_executecommand.rb
webgen-0.5.13 test/test_tag_executecommand.rb
webgen-0.5.12 test/test_tag_executecommand.rb
webgen-0.5.11 test/test_tag_executecommand.rb
webgen-0.5.10 test/test_tag_executecommand.rb
webgen-0.5.9 test/test_tag_executecommand.rb