Test::Unit::TestCase
Test global parameters
# File test/Global/Global.rb, line 19 19: def setup 20: setRootDir(File.dirname(__FILE__)) 21: end
# File test/Global/Global.rb, line 29 29: def testDisplayedWarning 30: # Save $stderr before altering it 31: lOrgSTDERR = $stderr.clone 32: # Crate the temporary file that will store $stderr 33: lFile = Tempfile.new('warning') 34: lFileName = lFile.path 35: RCodeLeveler.setWarningSeverity(1) 36: $stderr.reopen(lFile) 37: begin 38: requireFile('MissingParameterDefault') 39: rescue 40: # Reaffect $stderr before exiting 41: $stderr.reopen(lOrgSTDERR) 42: raise 43: end 44: # Reaffect $stderr 45: $stderr.reopen(lOrgSTDERR) 46: assert_equal(nil,$Var) 47: lFile.close 48: # Check content 49: File.open(lFileName,'r') do |iFile| 50: assert_equal(["RCodeLeveler - warning: #{File.dirname(__FILE__)}/RequiredFiles/MissingParameterDefault.rb:10: Malformed line: #__LVL__ $Var = 1\n"], iFile.readlines) 51: end 52: File.delete(lFileName) 53: end
# File test/Global/Global.rb, line 54 54: def testExceptionWarning 55: RCodeLeveler.setWarningSeverity(2) 56: assert_raise(RCodeLeveler::ParseError) do 57: requireFile('MissingParameterDefault') 58: end 59: assert_equal(nil,$Var) 60: end
Test missing file
# File test/Global/Global.rb, line 63 63: def testMissingFile 64: assert_raise(LoadError) do 65: requireFile('MissingFile') 66: end 67: end
Test warning severities
# File test/Global/Global.rb, line 24 24: def testNoWarning 25: RCodeLeveler.setWarningSeverity(0) 26: requireFile('MissingParameterDefault') 27: assert_equal(nil,$Var) 28: end
Test non Ruby file
# File test/Global/Global.rb, line 70 70: def testNonRubyFile 71: assert_raise(LoadError) do 72: requireFile('NonRubyFile.so') 73: end 74: end
Test using RCodeLeveler.getLeveledFileContent
# File test/Global/Global.rb, line 77 77: def testgetLeveledFileContent 78: RCodeLeveler::setLevel(2) 79: lNewContent, lDiff = RCodeLeveler.getLeveledFileContent('RequiredFiles/SimpleFile') 80: File.open("#{File.dirname(__FILE__)}/RequiredFiles/SimpleFile.rb", 'r') do |iFile| 81: assert_not_equal(lNewContent, iFile.readlines) 82: end 83: assert_equal(true, lDiff) 84: end
Test using RCodeLeveler.getLeveledFileContent on a missing file
# File test/Global/Global.rb, line 119 119: def testgetLeveledFileContentMissingFile 120: assert_raise(LoadError) do 121: RCodeLeveler.getLeveledFileContent('RequiredFiles/MissingFile') 122: end 123: end
Test using RCodeLeveler.getLeveledFileContent with a file having no LVL macros
# File test/Global/Global.rb, line 87 87: def testgetLeveledFileContentNoLVL 88: RCodeLeveler::setLevel(2) 89: lNewContent, lDiff = RCodeLeveler.getLeveledFileContent('RequiredFiles/SimpleFileWithNoLVL') 90: File.open("#{File.dirname(__FILE__)}/RequiredFiles/SimpleFileWithNoLVL.rb", 'r') do |iFile| 91: assert_equal(iFile.readlines, lNewContent) 92: end 93: assert_equal(false, lDiff) 94: end
Test using RCodeLeveler.getLeveledFileContent on a non Ruby file
# File test/Global/Global.rb, line 126 126: def testgetLeveledFileContentNonRubyFile 127: assert_raise(LoadError) do 128: RCodeLeveler.getLeveledFileContent('RequiredFiles/NonRubyFile.so') 129: end 130: end
Test using RCodeLeveler.getLeveledFileContent with a file having useless LVL macros
# File test/Global/Global.rb, line 97 97: def testgetLeveledFileContentUselessLVL 98: # If set to 1, nothing will be leveled. 99: RCodeLeveler::setLevel(1) 100: lNewContent, lDiff = RCodeLeveler.getLeveledFileContent('RequiredFiles/SimpleFile') 101: File.open("#{File.dirname(__FILE__)}/RequiredFiles/SimpleFile.rb", 'r') do |iFile| 102: assert_equal(iFile.readlines, lNewContent) 103: end 104: assert_equal(false, lDiff) 105: end
Test using RCodeLeveler.getLeveledFileContent with a file having useless LVL macros of blocks
# File test/Global/Global.rb, line 108 108: def testgetLeveledFileContentUselessLVLBlock 109: # If set to 2, nothing will be leveled. 110: RCodeLeveler::setLevel(2) 111: lNewContent, lDiff = RCodeLeveler.getLeveledFileContent('RequiredFiles/SimpleFileBlock') 112: File.open("#{File.dirname(__FILE__)}/RequiredFiles/SimpleFileBlock.rb", 'r') do |iFile| 113: assert_equal(iFile.readlines, lNewContent) 114: end 115: assert_equal(false, lDiff) 116: end
Test using RCodeLeveler.setOutputDirectory
# File test/Global/Global.rb, line 133 133: def testsetOutputDirectory 134: lOutputDir = Dir.tmpdir 135: RCodeLeveler::setOutputDirectory(lOutputDir) 136: RCodeLeveler::setLevel(2) 137: requireFile('SimpleFile') 138: lOutputFileName = "#{lOutputDir}/RequiredFiles/SimpleFile.leveled.rb" 139: assert(File.exist?(lOutputFileName)) 140: lNewContent = nil 141: File.open(lOutputFileName, 'r') do |iNewFile| 142: lNewContent = iNewFile.readlines 143: end 144: File.open("#{File.dirname(__FILE__)}/RequiredFiles/SimpleFile.rb", 'r') do |iFile| 145: assert_not_equal(iFile.readlines, lNewContent) 146: end 147: # Remove the new file 148: File.delete(lOutputFileName) 149: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.