File: test_case.rake

package info (click to toggle)
ruby-org 0.9.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 3,044; lisp: 50; makefile: 4
file content (96 lines) | stat: -rw-r--r-- 3,339 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require 'org-ruby'

namespace :testcase do
  @data_directory = File.join(File.dirname(__FILE__), "../spec/html_examples")
  
  desc "List all of the current HTML test cases"
  task :list do
    org_files = File.expand_path(File.join(@data_directory, "*.org" ))
    files = Dir.glob(org_files)
    files.each do |file|
      puts File.basename(file, ".org")
    end
  end

  desc "Accept the current org-ruby output for the test case as correct"
  task :accept, :case do |t, args|
    basename = args[:case]
    raise "Must supply a test case name. Example: rake testcase:accept[casename]" unless basename
    fname = File.expand_path(File.join(@data_directory, "#{basename}.org"))
    oname = File.expand_path(File.join(@data_directory, "#{basename}.html"))
    data = IO.read(fname)
    puts "=== #{fname} is:          ===>>>\n\n"
    puts data
    puts "\n\n=== ACCEPTING OUTPUT: ===>>>\n\n"
    p = Orgmode::Parser.new(data)
    puts p.to_html
    File.open(oname, "w") do |s|
      s.write(p.to_html)
    end
  end

  desc "Look at the current org-ruby output for a test case"
  task :inspect, :case do |t, args|
    basename = args[:case]
    raise "Must supply a test case name. Example: rake testcase:accept[casename]" unless basename
    fname = File.expand_path(File.join(@data_directory, "#{basename}.org"))
    data = IO.read(fname)
    puts "=== #{fname} is:          ===>>>\n\n"
    puts data
    puts "\n\n=== #{fname} converts to: ===>>>\n\n"
    p = Orgmode::Parser.new(data)
    puts p.to_html
  end

  # Special namespace to test syntax highlighting with different technologies
  namespace :highlight do
    @code_syntax_examples_directory = File.join(File.dirname(__FILE__), "../spec/html_code_syntax_highlight_examples")

    desc "List all of the current HTML test cases"
    task :list do
      org_files = File.expand_path(File.join(@code_syntax_examples_directory, "*.org" ))
      files = Dir.glob(org_files)
      files.each do |file|
        puts File.basename(file, ".org")
      end
    end

    desc "Special tests cases for code syntax highlight support"
    task :accept, :case do |t, args|
      basename = args[:case]
      raise "Must supply a test case name. Example: rake testcase:accept[casename]" unless basename

      fname = File.expand_path(File.join(@code_syntax_examples_directory, "#{basename}.org"))
      oname = File.expand_path(File.join(@code_syntax_examples_directory, "#{basename}.html"))

      data = IO.read(fname)
      puts "=== #{fname} is:          ===>>>\n\n"
      puts data
      puts "\n\n=== ACCEPTING OUTPUT: ===>>>\n\n"
      p = Orgmode::Parser.new(data)
      puts p.to_html
      File.open(oname, "w") do |s|
        s.write(p.to_html)
      end
    end

    desc "Inspect code syntax highlight support"
    task :inspect, :case do |t, args|
      basename = args[:case]
      raise "Must supply a test case name. Example: rake testcase:inspecthighlight[casename]" unless basename

      fname = File.expand_path(File.join(@code_syntax_examples_directory, "#{basename}.org"))

      data = IO.read(fname)
      puts "=== #{fname} is:          ===>>>\n\n"
      puts data
      puts "\n\n=== #{fname} converts to: ===>>>\n\n"
      p = Orgmode::Parser.new(data)
      puts p.to_html
    end
  end

end

desc "Alias for testcase:list"
task :testcase => ["testcase:list"]