xot 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/task/git.rake CHANGED
@@ -1,6 +1,11 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
+ %w[status diff push pull].each do |t|
5
+ task t.intern => "git:#{t}"
6
+ end
7
+
8
+
4
9
  namespace :git do
5
10
 
6
11
 
data/task/lib.rake CHANGED
@@ -5,28 +5,36 @@ require 'rbconfig'
5
5
  require 'rake/loaders/makefile'
6
6
 
7
7
 
8
+ task :lib => 'lib:build'
9
+
10
+ %w[clean].each do |t|
11
+ task t.intern => "lib:#{t}"
12
+ end
13
+
14
+
8
15
  namespace :lib do
9
16
 
10
17
 
11
18
  rbconf = RbConfig::CONFIG
12
19
 
13
- mod = MODULE
14
- name = env :NAME, MODULE.name.downcase
15
- incdir = env :INCDIR, 'include'
16
- srcdir = env :SRCDIR, 'src'
17
- libdir = env :LIBDIR, 'lib'
18
- cc = env :CC, rbconf['CC'] || 'g++'
19
- ar = env :AR, 'ar'
20
- defs = env :DEFS, []
21
- incdirs = env(:INCDIRS) ? env(:INCDIRS) : []
22
- cflags = env(:CFLAGS, '-Wall -O -g').dup
23
- arflags = env(:ARFLAGS, 'crs').dup
20
+ mod = MODULE
21
+ name = env :NAME, MODULE.name.downcase
22
+ incdir = env :INCDIR, 'include'
23
+ srcdir = env :SRCDIR, 'src'
24
+ libdir = env :LIBDIR, 'lib'
25
+ cxx = env :CXX, rbconf['CXX'] || 'g++'
26
+ ar = env :AR, rbconf['AR'] || 'ar'
27
+ defs = env :DEFS, []
28
+ debug = env :DEBUG, false
29
+ incdirs = env :INCDIRS, []
30
+ cxxflags = env(:CXXFLAGS, rbconf['CXXFLAGS']).dup
31
+ arflags = env(:ARFLAGS, 'crs').dup
24
32
 
25
33
  outname = "lib#{name}.a"
26
34
  out = File.join libdir, outname
27
35
 
28
- rbs = glob '**/*.rb'
29
- erbs = convertions glob("**/*.erb"), {".erb" => ""}
36
+ erbs = glob *[incdir, srcdir].map {|s| "#{s}/**/*.erb"}
37
+ erbs = convertions erbs, {".erb" => ""}
30
38
  headers = glob("include/**/*.h") | erbs.values.grep(/\.h$/)
31
39
  srcs = glob("src/**/*.cpp") | erbs.values.grep(/\.cpp$/)
32
40
  srcs += glob("src/**/*.mm") if cocoa?
@@ -42,10 +50,16 @@ namespace :lib do
42
50
  ]
43
51
  incdirs.uniq!
44
52
 
45
- defs << 'WIN32' if win32?
46
- defs << 'COCOA' if cocoa?
47
- cflags << defs.map{|s| " -D#{s}"}.join
48
- cflags << incdirs.map{|s| " -I#{s}"}.join
53
+ defs << '_DEBUG' if debug
54
+ defs << 'NDEBUG' unless debug
55
+ defs << 'WIN32' if win32?
56
+ defs << 'COCOA' if cocoa?
57
+ defs << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
58
+ cxxflags << ' ' << rbconf['debugflags'] if debug
59
+ cxxflags.gsub! /-O\d?/, '' if debug
60
+ cxxflags << ' --stdlib=libc++' if clang?
61
+ cxxflags << defs.map{|s| " -D#{s}"}.join
62
+ cxxflags << incdirs.map{|s| " -I#{s}"}.join
49
63
 
50
64
  depend = 'depend.mf'
51
65
  objs = convertions srcs, {".cpp" => ".o", ".mm" => ".o"}
@@ -54,20 +68,20 @@ namespace :lib do
54
68
 
55
69
  task :build => out
56
70
 
57
- task :compile => objs.values
58
-
59
- task :erb => erbs.values
60
-
61
71
  task :clean do
62
72
  sh %( rm -rf #{tmps.join " "} #{out} )
63
73
  end
64
74
 
75
+ task :compile => objs.values
76
+
77
+ task :erb => erbs.values
78
+
65
79
  file out => objs.values do
66
80
  sh %( #{ar} #{arflags} #{out} #{objs.values.join " "} )
67
81
  end
68
82
 
69
83
  file depend => erbs.values do
70
- sh %( #{cc} -M #{cflags} #{srcs.join ' '} > #{depend} )
84
+ sh %( #{cxx} -M #{cxxflags} #{srcs.join ' '} > #{depend} )
71
85
  input = open(depend) {|f| f.read}
72
86
  open(depend, 'w') do |output|
73
87
  output << input.gsub(/\w+\.o/, srcdir + '/\0')
@@ -78,13 +92,13 @@ namespace :lib do
78
92
 
79
93
  objs.each do |(src, obj)|
80
94
  file obj => [depend, src] + erbs.values do
81
- sh %( #{cc} -c #{cflags} -o #{obj} #{src} )
95
+ sh %( #{cxx} -c #{cxxflags} -o #{obj} #{src} )
82
96
  end
83
97
  end
84
98
 
85
99
  erbs.each do |(erb, out)|
86
- file out => [erb] + rbs do
87
- print "#{erb}: compiling to #{out}..."
100
+ file out => erb do
101
+ print "#{erb}: compiling to #{out} ..."
88
102
  compile erb, out
89
103
  puts "ok"
90
104
  end
@@ -0,0 +1,51 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
4
+ SUBMODULE_TASKS = %w[
5
+ build clean lib ext doc test gem
6
+ status diff push pull
7
+ install uninstall upload
8
+ ]
9
+
10
+
11
+ SUBMODULE_TASKS.each do |name|
12
+ t = task "#{name}-all".intern
13
+ t.prerequisites.unshift "submodule:#{name}", :header
14
+ t.prerequisites.push name.intern
15
+ end if File.exist? '.gitmodules'
16
+
17
+ task :submodule => "submodule:init"
18
+
19
+ task :header do
20
+ header MODULE
21
+ end
22
+
23
+
24
+ namespace :submodule do
25
+
26
+
27
+ mods = env :SUBMODULES, []
28
+ git = env :GIT, 'git'
29
+
30
+
31
+ (SUBMODULE_TASKS + [:init]).each do |t|
32
+ task t.intern => mods.map {|m| "submodule:#{m}:#{t}"}
33
+ end
34
+
35
+ mods.each do |mod|
36
+ namespace mod.intern do
37
+
38
+ empty_task :init
39
+
40
+ SUBMODULE_TASKS.each do |t|
41
+ task t.intern => "submodule:#{mod}:init" do
42
+ header mod
43
+ sh %( cd #{mod} && rake #{t} )
44
+ end
45
+ end
46
+
47
+ end# mod.intern
48
+ end
49
+
50
+
51
+ end# submodule
data/task/test.rake ADDED
@@ -0,0 +1,35 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
4
+ require 'rake/testtask'
5
+
6
+
7
+ task :test => 'test:all'
8
+
9
+ empty_task :ext
10
+
11
+
12
+ namespace :test do
13
+
14
+
15
+ alones = env :TESTS_ALONE, []
16
+ excludes = env :TESTS_EXCLUDE, []
17
+ ruby = env :RUBY, 'ruby'
18
+
19
+
20
+ task :all => [:ext, :full, :alones]
21
+
22
+ Rake::TestTask.new :full do |t|
23
+ t.libs << 'lib'
24
+ t.test_files = FileList['test/test_*.rb'] - alones - excludes
25
+ t.verbose = true
26
+ end
27
+
28
+ task :alones do
29
+ alones.each do |rb|
30
+ next if excludes.include? rb
31
+ sh %( #{ruby} #{rb} )
32
+ end
33
+ end
34
+
35
+ end# :test
data/test/helpers.rb ADDED
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'bundler/setup'
5
+ require 'test/unit'
6
+ require 'xot'
7
+ require 'xot/tester'
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestBlockUtil < Test::Unit::TestCase
8
+
9
+ include Xot::BlockUtil::ClassMethods
10
+
11
+ class Temp
12
+
13
+ attr_accessor :value
14
+
15
+ end# Temp
16
+
17
+ def temp (*args)
18
+ Temp.new
19
+ end
20
+
21
+ def test_instance_eval_or_block_call ()
22
+ t = temp
23
+ t.value = 1
24
+
25
+ assert_equal 2, instance_eval_or_block_call(t) {|x| x.value = 2}
26
+ assert_equal 2, t.value
27
+
28
+ assert_equal 3, instance_eval_or_block_call(t) {|x| t.value = 3}
29
+ assert_equal 3, t.value
30
+
31
+ assert_equal 4, instance_eval_or_block_call(t) {self.value = 4}
32
+ assert_equal 4, t.value
33
+
34
+ assert_equal 5, instance_eval_or_block_call(t) {t.value = 5}
35
+ assert_equal 5, t.value
36
+
37
+ assert_raise NoMethodError do
38
+ instance_eval_or_block_call(t) {|x| self.value = 9}
39
+ end
40
+ end
41
+
42
+ end# TestBlockUtil
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestHookable < Test::Unit::TestCase
8
+
9
+ class Temp
10
+
11
+ include Xot::Hookable
12
+
13
+ attr_reader :log
14
+
15
+ def initialize ()
16
+ @log = []
17
+ end
18
+
19
+ def test (val1, val2)
20
+ @log << val1 << val2
21
+ end
22
+
23
+ def zero ()
24
+ @log << 0
25
+ end
26
+
27
+ end# Temp
28
+
29
+ def temp (*args)
30
+ Temp.new
31
+ end
32
+
33
+ def test_hook ()
34
+ o = temp
35
+ o.hook(:test) do |*args|
36
+ super -1, 0
37
+ o.log << args
38
+ super *args
39
+ super 8, 9
40
+ end
41
+ o.test 1, 2
42
+ assert_equal [-1, 0, [1, 2], 1, 2, 8, 9], o.log
43
+ end
44
+
45
+ def test_before ()
46
+ o = temp
47
+ o.before(:zero) {o.log << 1}
48
+ o.zero
49
+ assert_equal [1, 0], o.log
50
+ end
51
+
52
+ def test_after ()
53
+ o = temp
54
+ o.after(:zero) {o.log << 1}
55
+ o.zero
56
+ assert_equal [0, 1], o.log
57
+ end
58
+
59
+ def test_on ()
60
+ o = temp
61
+ o.on(:zero) {o.log << 1}
62
+ o.zero
63
+ assert_equal [1], o.log
64
+ end
65
+
66
+ def test_hook_self ()
67
+ o, id = temp, nil
68
+ o.hook(:zero) {id = __id__}
69
+ o.zero
70
+ assert_equal o.__id__, id
71
+ end
72
+
73
+ end# TestHookable
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+ require 'xot/rake'
6
+
7
+ include Xot::Rake
8
+
9
+
10
+ Const = 'const'
11
+ Zero = 0
12
+ NonZero = 1
13
+ ZeroStr = '0'
14
+ NonZeroStr = '1'
15
+ True = true
16
+ False = false
17
+ TrueStr = 'true'
18
+ FalseStr = 'false'
19
+
20
+
21
+ class TestRakeHelpers < Test::Unit::TestCase
22
+
23
+ def test_set ()
24
+ assert_equal 'const', env(:Const, :dummy)
25
+ assert_equal 0, env(:Zero, :dummy)
26
+ assert_equal 1, env(:NonZero, :dummy)
27
+ assert_equal 0, env(:ZeroStr, :dummy)
28
+ assert_equal 1, env(:NonZeroStr, :dummy)
29
+ assert_equal true, env(:True, :dummy)
30
+ assert_equal false, env(:False, :dummy)
31
+ assert_equal true, env(:TrueStr, :dummy)
32
+ assert_equal false, env(:FalseStr, :dummy)
33
+ end
34
+
35
+ end# TestRakeHelpers
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestSetter < Test::Unit::TestCase
8
+
9
+ class Temp
10
+
11
+ include Xot::Setter
12
+
13
+ attr_accessor :x, :y
14
+
15
+ end# Temp
16
+
17
+ def temp (*args)
18
+ Temp.new
19
+ end
20
+
21
+ def test_set ()
22
+ o = temp
23
+ o.set :x, 1
24
+ assert_equal 1, o.x
25
+ end
26
+
27
+ def test_set_by_hash ()
28
+ o = temp
29
+ o.set :x => 1, :y => 2
30
+ assert_equal [1, 2], [o.x, o.y]
31
+ end
32
+
33
+ def test_invalid_name ()
34
+ assert_raise(NoMethodError) {temp.set :badname, 1}
35
+ assert_raise(NoMethodError) {temp.set :badname}
36
+ end
37
+
38
+ def test_invalid_value ()
39
+ assert_raise(ArgumentError) {temp.set :x}
40
+ end
41
+
42
+ end# TestSetter
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestTester < Test::Unit::TestCase
8
+
9
+ def test_native ()
10
+ assert Xot::Tester.test_native
11
+ end
12
+
13
+ end# TestTester
data/xot.gemspec CHANGED
@@ -1,53 +1,41 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- $: << File.join(File.dirname(__FILE__), 'lib')
4
+ $: << File.expand_path('../lib', __FILE__)
5
5
 
6
- require 'rake'
7
6
  require 'xot/module'
8
7
 
9
8
 
10
- MODULE = Xot
11
- NAME = MODULE.name.downcase
12
-
13
-
14
- FILES = FileList[*%W[
15
- README
16
- ChangeLog
17
- Rakefile
18
- #{NAME}.gemspec
19
- VERSION
20
- task/**/*.rake
21
- include/**/*.h
22
- lib/**/*.rb
23
- src/**/*.h
24
- src/**/*.cpp
25
- ]]
26
-
27
- RDOCS = FileList[*%W[
28
- README
29
- ]]
9
+ Gem::Specification.new do |s|
10
+ def glob (*patterns)
11
+ patterns.map {|pat| Dir.glob(pat).to_a}.flatten
12
+ end
30
13
 
14
+ mod = Xot
15
+ name = mod.name.downcase
16
+ rdocs = glob *%w[README]
31
17
 
32
- Gem::Specification.new do |s|
33
- s.name = NAME
18
+ s.name = name
34
19
  s.summary = 'A Utility library for C++ developemt.'
35
20
  s.description = 'This library include some useful utility classes and functions for development with C++.'
36
- s.version = MODULE.version
21
+ s.version = mod.version
37
22
 
38
23
  s.authors = %w[snori]
39
24
  s.email = 'snori@xord.org'
40
- s.homepage = "http://github.com/xord/#{NAME}"
25
+ s.homepage = "http://github.com/xord/#{name}"
41
26
 
42
- s.platform = Gem::Platform::RUBY
27
+ s.platform = Gem::Platform::RUBY
28
+ s.required_ruby_version = '>=1.9.0'
43
29
 
30
+ s.add_runtime_dependency 'bundler'
44
31
  s.add_development_dependency 'rake'
45
32
  s.add_development_dependency 'gemcutter'
46
33
 
47
- s.files = FILES.to_a
48
-
34
+ s.files = `git ls-files`.split $/
35
+ s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
36
+ s.test_files = s.files.grep %r{^(test|spec|features)/}
37
+ s.extra_rdoc_files = rdocs.to_a
49
38
  s.has_rdoc = true
50
- s.extra_rdoc_files = RDOCS.to_a
51
39
 
52
40
  s.extensions << 'Rakefile'
53
41
  end