Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
73c73855
Commit
73c73855
authored
May 19, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testing: add t.Failed() bool
R=r DELTA=18 (10 added, 4 deleted, 4 changed) OCL=29000 CL=29034
parent
b91a043d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
testing.go
src/lib/testing/testing.go
+14
-8
No files found.
src/lib/testing/testing.go
View file @
73c73855
...
...
@@ -21,11 +21,16 @@ import (
// Report as tests are run; default is silent for success.
var
chatty
=
flag
.
Bool
(
"chatty"
,
false
,
"chatty"
)
// Insert
tabs after newlines - but not the last one
// Insert
final newline if needed and tabs after internal newlines.
func
tabify
(
s
string
)
string
{
for
i
:=
0
;
i
<
len
(
s
)
-
1
;
i
++
{
// -1 because if last char is newline, don't bother
n
:=
len
(
s
);
if
n
>
0
&&
s
[
n
-
1
]
!=
'\n'
{
s
+=
"
\n
"
;
n
++
;
}
for
i
:=
0
;
i
<
n
-
1
;
i
++
{
// -1 to avoid final newline
if
s
[
i
]
==
'\n'
{
return
s
[
0
:
i
+
1
]
+
"
\t
"
+
tabify
(
s
[
i
+
1
:
len
(
s
)
]);
return
s
[
0
:
i
+
1
]
+
"
\t
"
+
tabify
(
s
[
i
+
1
:
n
]);
}
}
return
s
...
...
@@ -44,6 +49,11 @@ func (t *T) Fail() {
t
.
failed
=
true
}
// Failed returns whether the Test function has failed.
func
(
t
*
T
)
Failed
()
bool
{
return
t
.
failed
}
// FailNow marks the Test function as having failed and stops its execution.
// Execution will continue at the next Test.
func
(
t
*
T
)
FailNow
()
{
...
...
@@ -61,11 +71,7 @@ func (t *T) Log(args ...) {
// Log formats its arguments according to the format, analogous to Printf(),
// and records the text in the error log.
func
(
t
*
T
)
Logf
(
format
string
,
args
...
)
{
t
.
errors
+=
tabify
(
fmt
.
Sprintf
(
"
\t
"
+
format
,
args
));
l
:=
len
(
t
.
errors
);
if
l
>
0
&&
t
.
errors
[
l
-
1
]
!=
'\n'
{
t
.
errors
+=
"
\n
"
}
t
.
errors
+=
"
\t
"
+
tabify
(
fmt
.
Sprintf
(
format
,
args
));
}
// Error is equivalent to Log() followed by Fail().
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment