-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaketests
executable file
·110 lines (85 loc) · 2.46 KB
/
maketests
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env ruby
require 'json'
require 'fileutils'
module_dir = Dir.pwd + '/' + ARGV[0].to_s
test_dir = module_dir + '/tests'
puts 'Module dir:'+module_dir
if !Dir.exist?(test_dir)
Dir.mkdir(test_dir)
end
file = File.read(module_dir + 'composer.json')
json = JSON.parse(file)
psr4 = json['autoload']['psr-4']
puts psr4.inspect
flipped = psr4.map(&:reverse).to_h
puts flipped.inspect
# @todo Add check for tests and tests/
test_namespace = flipped['tests/']
puts test_namespace
puts
Dir.glob(module_dir + 'src/**/*.php').each do|file|
puts "FILE:#{file}"
path = file.gsub(module_dir, '')
puts 'PATH: ' + path
path_splits = path.split('/')
path_splits.shift
path_splits.pop
puts path_splits.inspect
if !file.include? '/tests/'
puts "DEBUG: Generating test skeleton for #{file}"
splits = file.split '/'
phpfile = splits[-1]
File.open(file, 'r') do |handle|
php = "<?php\n\n"
php << "namespace "
php << flipped['tests/']
php << path_splits.join("\\")
php << ";\n\n"
php << "use \\SilverStripe\\Dev\\SapphireTest;"
php << "\n\n"
puts php
filename = phpfile.gsub '.php', ''
php << "class #{filename}Test extends SapphireTest {\n"
while line = handle.gets
if (line.include? 'function ')
line.gsub! 'public', ''
line.gsub! 'private', ''
line.gsub! 'protected', ''
line.gsub! 'static', ''
line.strip!
is_comment = line[0] == '*' || line[0,1] == '/*' || line[0,1] == '//'
if !is_comment
puts "DEBUG: LINE=" + line
#
# DEBUG: LINE=function canView($member = null)
# DEBUG: name=function canView
# DEBUG: LINE=function canCreate($member = null, $context = array())
splits = line.split '('
name = splits[-2].strip
puts "DEBUG: name=" + name
name.gsub!('function ', '')
name[0] = name[0].chr.upcase
name = 'test' + name
php << "\tpublic function #{name}() {\n"
php << "\t\t$this->markTestSkipped('TODO');\n"
php << "\t}\n\n";
end
end
end
php << "}\n";
puts php
phpfile.gsub! '.php', 'Test.php'
puts "DEBUG: path splits= " + path_splits.inspect
filepath = module_dir+'tests/'+path_splits.join("/") + '/' + phpfile
puts("DEBUG: SAVING TO " + filepath)
#path_splits.pop
FileUtils.mkdir_p module_dir+'/tests/'+path_splits.join("/") + "/"
puts
puts filepath
skel = File.new(filepath, "w+")
skel.puts php
skel.close
puts "DEBUG:"
end
end
end