| Age | Commit message (Collapse) | Author |
|
Using diff Unified improve the test output readability when two large
strings are not match.
|
|
|
|
With help of spdxconv tool [1], we able to bulk update all files license
and copyright format to comply with SPDX formats.
[1] https://kilabit.info/project/spdxconv/
|
|
The first line in test data file may contains line prefixed with "//"
as comment.
The use case is for license and copyright lines.
|
|
Given the path to directory `destDir`, create all of the
[test.Data.Input] with key as its file name.
If the input name contains "/", the path before the base name will be
created along with its parent as long as it is under the `destDir`.
For example, given input name "a/b/c.txt", it will create path "a/b/"
inside `destDir` first, followed by file "c.txt" inside that path.
|
|
Also, fix typo on the LoadDataDir regarding suffix by replacing it with
the exported constant.
|
|
The "nolint" tag is used to ignore lines from being processed by
golangci-lint.
Since we are not using golangci-lint anymore, now and in the
future, those lines can be removed.
|
|
Go 1.22 now support for-range on numeric value.
|
|
|
|
The Helper method mark the Assert function as test helper, which when
printing file and line information, the stack trace from Assert function
will be skipped.
This remove manual lines skipping that previously we have.
|
|
|
|
The Simulate function simulate HTTP server handler by generating
[http.Request] from fields in [SimulateRequest]; and then call
[http.HandlerFunc].
The HTTP response from serve along with its raw body and original HTTP
request then returned in [*SimulateResult].
|
|
HTTP request now implicitly create request with context.
Any false positive related to not closing HTTP response body has been
annotated with "nolint:bodyclose".
In the example code, use consistent "// Output:" comment format, by
prefixing with single space.
Any comment on code now also prefixing with single space.
An error returned without variables now use [errors.New] instead of
[fmt.Errorf].
Any error returned using [fmt.Errorf] now wrapped using "%w" instead of
"%s".
Also, replace error checking using [errors.Is] or [errors.As], instead
of using equal/not-equal operator.
Any statement like "x = x OP y" now replaced with "x OP= y".
Also, swap statement is simplified using "x, y = y, x".
Any switch statement with single case now replaced with if-condition.
Any call to defer on function or program that call [os.Exit], now
replaced by calling the deferred function directly.
Any if-else condition now replaced with switch statement, if possible.
|
|
There are several reasons that why we move from github.com.
First, related to the name of package.
We accidentally name the package with "share" a common word in English
that does not reflect the content of repository.
By moving to other repository, we can rename it to better and unique
name, in this "pakakeh.go".
Pakakeh is Minang word for tools, and ".go" suffix indicate that the
repository related to Go programming language.
Second, supporting open source.
The new repository is hosted under sourcehut.org, the founder is known
to support open source, and all their services are licensed under AGPL,
unlike GitHub that are closed sources.
Third, regarding GitHub CoPilot.
The GitHub Terms of Service [1], allow any public content that are hosted
there granted them to parse the content.
On one side, GitHub helps and flourish the open source, but on another
side have an issues regarding scraping the copyleft license [2].
[1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us
[2]: https://githubcopilotinvestigation.com
|
|
The RandReader implement [io.Reader].
To provide predictable result, the RandReader is seeded with slice of
bytes.
A call to Read will fill the passed bytes with those seed.
For example, given seed as "abc" (length is three), calling Read with
bytes length five will return "abcab".
|
|
There are some reports that I disagree with revive, in example, code
should not declare the type after variables.
In my opinion, on some cases, declaring the type make the code more
readable and explicit.
Since I did not want to add new configuration file, we changes it and
follow revive for now.
|
|
|
|
This reduce the struct size from 24 to 16 bytes (-8).
|
|
Continuing previous refactoring, we rename the file test_buffer to
buffer_writer to match with its type name.
|
|
The name TestWriter is considered stutter if its called from external
package, test.TestWriter.
While at it, implement the Error and Errorf in BufferWriter and add
comment to each exported methods.
|
|
The type ReadWriter provide two buffer, BufRead and BufWrite.
The BufRead is for io.Reader and BufWrite for io.Writer or
io.StringWriter.
The type provide one method helper, Reset, to reset all buffers.
|
|
The documentation is based on the article published at
https://kilabit.local/journal/2023/go_test_data/
after reviewing and explain how to use both of them to public.
|
|
This example show expected, got, and diff between them.
|
|
The idea is to prevent using non-exported function in example.
Case in point, in this changes the testWriter is used in example and
not exported which make our test not runnable on public website.
To fix that we export TestWriter with this changes.
|
|
While at it, update the CHANGELOG to add that previous changes.
|
|
In the output, instead of using %q we replace it with %s, because printing
string with double quote cause escaping and hard to read
This change may cause difference in white spaces not showed in the
terminal.
In the diff changes, only print the Old and New, without printing each
chunk.
|
|
While at it, update the Assert documentation by describing output lines
after "----" and "++++".
|
|
If both exp and got types are string and its longer than 50 chars, it
will use the text/diff.Text to show the difference between them.
The diff output is as follow,
!!! string not matched:
--++
<LINE_NUM> - "<LINE_EXP>"
<LINE_NUM> + "<LINE_GOT>"
^<COL_NUM> - "<DELETED_STRING>"
^<COL_NUM> + "<INSERTED_STRING>"
The "<LINE_NUM> - " print the line number in exp followed by line itself.
The "<LINE_NUM> + " print the line number in got followed by line itself.
The "^<COL_NUM> - " show the character number in exp line followed by
deleted string (or string that not exist in got).
The "^<COL_NUM> + " show the character number in got line followed by
inserted string (or string that not exist in exp).
|
|
Since we only need to call Log and Fatalf during Assert, no need to pass
the whole instance of testing.T to Assert.
By changing it to Writer, we also can test the Assert.
This remove the AssertBench, because it have the same function
parameters and body as Assert.
|
|
Given the following input and output,
>>>
input
<<<
output
EOF
The input and output content always have new line at the end.
This may cause unexpected input or output.
If input or output content expecting new line at the end, add two empty
lines at the end of it.
|
|
This is to make the list of files being tested is consistent.
|
|
Previously, the LoadDataDir load all files from directory that have
".txt" extension.
This may cause unknown non-test data files loaded and may cause an error.
To distinguish it with other text files, inside the directory to be loaded
load only the file that has suffix "_test.txt".
|
|
Data contains predefined input and output values that is loaded from
file to be used during test.
The data provides zero or more flags, an optional description, zero or
more input, and zero or more output.
The data file name must end with ".txt".
The data content use the following format,
[FLAG_KEY ":" FLAG_VALUE LF]
[LF DESCRIPTION]
">>>" [INPUT_NAME] LF
INPUT_CONTENT
LF
"<<<" [OUTPUT_NAME] LF
OUTPUT_CONTENT
The data can contains zero or more flag.
A flag is key and value separated by ":".
The flag key must not contain spaces.
The data may contain description.
The line that start with "\n>>>" defined the beginning of input.
An input can have a name, if its empty it will be set to "default".
An input can be defined multiple times, with different names.
The line that start with "\n<<<" defined the beginning of output.
An output can have a name, if its empty it will be set to "default".
An output also can be defined multiple times, with different names.
|
|
|
|
|
|
Since Go 1.16, the ioutil package has been deprecated.
This changes replace any usage that use functions from ioutil package
with their replacement from package os or package io.
|
|
Previously, the test.Assert and test.AssertBench functions has the
boolean parameter to print the stack trace of test in case its not equal.
Since this parameter is not mandatory and its usually always set to
"true", we remove them from function signature to simplify the call
to Assert and AssertBench.
|
|
The new Assert function use the reflect.DoEqual that return an error
which describe which field have unmatched value.
This changes affect other test that use "false" as the last parameter.
|
|
|
|
The IsEqual() function is like reflect.DeepEqual but its check if a
struct have method "IsEqual", if its exist it will call the method to
compare the value.
|
|
If the exp parameter implement the extended "reflect.Equaler" interface
then it will use the method IsEqual() with "got" as parameter.
|
|
|
|
The valid syntax to suppress linter warnings is "//nolint:<name>" with
no space between comment and "nolint" and between ":". Also, we move the
placement of nolint directive to the top of statements for multiple
nolint in the same scope.
While at it, fix and supress some linter warnings.
|
|
Following CodeReviewComments on Go wiki about Useful Test Failures [1],
the common idiom here is that the actual value is printed first followed
by the expected value.
[1] https://github.com/golang/go/wiki/CodeReviewComments#useful-test-failures
|
|
Most of the warnings caused by update to linter which cause global
variables declared with grouping "( ... )" and that has been suppressed,
are become false-positive again.
|
|
|
|
|
|
|
|
This package can be useful for testing output of command that print
message to stdout or stderr.
|
|
|