-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtkx-prove
executable file
·214 lines (182 loc) · 5.26 KB
/
tkx-prove
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/perl -w
use strict;
use Tkx;
use Time::HiRes qw(time);
Tkx::package_require("tile");
my $mw = Tkx::widget->new(".");
my $pane = $mw->new_ttk__panedwindow(
-orient => "vertical",
);
$pane->g_pack(
-expand => 1,
-fill => "both",
);
my $frame = $pane->new_frame;
$pane->add($frame, -weight => 1);
my $tree = $frame->new_ttk__treeview(
-columns => [qw(status time)],
-height => 5,
);
$tree->heading("#0", -text => "Test Name", -command => sub { sort_rows("#0") });
$tree->heading("status", -text => "Status", -command => sub { sort_rows("status") });
$tree->column("status", -width => 45, -anchor => "center");
$tree->heading("time", -text => "Time", -command => sub { sort_rows("time") });
$tree->column("time", -width => 45, -anchor => "e");
my $sb = $frame->new_ttk__scrollbar(
-orient => "vertical",
-command => [$tree, "yview"],
);
$sb->g_pack(
-side => "right",
-fill => "y",
);
$tree->configure(-yscrollcommand => [$sb, "set"]);
$tree->g_pack(
-expand => 1,
-fill => "both",
-side => "left",
);
my $text = $pane->new_text(
-font => "Helvetica 10",
-width => 10,
-height => 2,
);
$text->tag_configure("heading", -font => "Helvetica 12 bold");
$text->tag_configure("code", -font => "Courier 8");
$pane->add($text, -weight => 3);
$frame = $mw->new_frame(
-bd => 5,
);
$frame->g_pack(-fill => "x");
my $bb = $frame->new_ttk__button(
-text => "Run all tests",
-command => sub { run_tests(Tkx::SplitList($tree->children(""))) },
);
$bb->g_pack(-side => "left");
$bb = $frame->new_ttk__button(
-text => "Run selected tests",
-command => sub { run_tests(Tkx::SplitList($tree->selection)) },
);
$bb->g_pack(-side => "left");
$bb = $frame->new_ttk__button(
-text => "New dir",
-command => \&new_test_dir,
);
$bb->g_pack(-side => "left");
my $dir;
my %result;
sub new_test_dir {
my $dir = Tkx::tk___chooseDirectory(
-parent => $mw,
-title => "New test directory",
-mustexist => 1,
);
if ($dir) {
$dir =~ s,/t/?$,,;
set_dir($dir);
}
}
sub set_dir {
$dir = shift;
%result = ();
$tree->delete($tree->children(""));
$text->delete("1.0", "end");
use File::Find qw(find);
find({
wanted => sub {
return unless -f $_;
return unless /\.t$/;
my $name = substr($File::Find::name, length("$dir/t") + 1);
substr($name, -2, 2, "");
$tree->insert("", "end", -text => $name, -values => ["-", "-"]);
},
no_chdir => 1,
}, "$dir/t");
}
use Test::Harness::Straps;
my $strap = Test::Harness::Straps->new;
$tree->g_bind("<<TreeviewSelect>>", \&tree_select);
new_test_dir();
Tkx::MainLoop();
sub run_tests {
my $old_selection = $tree->selection;
for my $item (@_) {
my $test = "t/" . $tree->item($item, "-text") . ".t";
#print "Item $item $test\n";
delete $result{$item};
$tree->selection_set($item);
$tree->see($item);
$tree->set($item, "status", "-");
$tree->set($item, "time", "-");
Tkx::update();
my $cmd = $strap->_command_line("$dir/$test");
my $before = time;
my @output = qx($cmd);
my $used = time - $before;
my $status = $?;
my %res = $strap->analyze($item, \@output);
$res{output} = join("", @output);
$res{start_time} = $before;
$res{used_time} = sprintf "%.03f", $used;
$res{status} = $status;
#use Data::Dump; print Data::Dump::dump(\%res), "\n";
$result{$item} = \%res;
$tree->set($item, "status", $res{passing} ? ($res{skip_all} ? "skipped" : "ok") : "fail");
$tree->set($item, "time", sprintf "%.2f", $used);
tree_select();
Tkx::update();
#select(undef, undef, undef, 0.4);
}
$tree->selection_set($old_selection);
#$tree->yview_moveto(0);
}
sub tree_select {
my @sel = Tkx::SplitList($tree->selection);
#print "[select @sel]\n";
$text->delete("1.0", "end");
if (@sel == 0) {
$text->insert("end", "No test selected\n");
}
elsif (@sel == 1) {
my $name = $tree->item($sel[0], "-text");
#$text->insert("end", "$name\n");
if (my $res = $result{$sel[0]}) {
$text->insert("end", "Skipped: $res->{skip_all}\n", "heading") if $res->{skip_all};
$text->insert("end", "Passed $res->{ok} of $res->{max} tests in $res->{used_time} seconds.\n");
$text->insert("end", "Todo tests: $res->{todo}\n") if $res->{todo};
$text->insert("end", "Bonus tests: $res->{bonus}\n") if $res->{bonus};
$text->insert("end", "Skipped tests: $res->{skip}\n") if $res->{skip};
$text->insert("end", "Status: $res->{status}\n") if $res->{status};
$text->insert("end", "\nComplete test output\n\n", "heading");
$text->insert("end", $res->{output}, "code");
}
else {
$text->insert("end", "No result\n");
}
}
else {
my $num_tests = @sel;
$text->insert("end", "$num_tests tests selected\n");
}
}
BEGIN {
my %ascending;
sub sort_rows {
my $col = shift;
$ascending{$col} = !$ascending{$col};
my $kids = $tree->children("");
my @kids = Tkx::SplitList($kids);
@kids = map { $_->[0] }
sort {
my $cmp = $a->[1] cmp $b->[1];
$cmp = -$cmp if $ascending{$col};
$cmp
}
map { [$_, $col eq "#0" ? $tree->item($_, "-text") : $tree->set($_, $col) ] }
@kids;
$tree->detach($kids);
for my $item (@kids) {
$tree->move($item, "", "end");
}
}
}