aboutsummaryrefslogtreecommitdiff
path: root/lib/test/test.go
AgeCommit message (Collapse)Author
3 dayslib/test: rewrite Assert to use [diff.Unified]Shulhan
Using diff Unified improve the test output readability when two large strings are not match.
2025-01-23all: replace "interface{}" with "any"Shulhan
2025-01-22lib/test: call Helper method inside AssertShulhan
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.
2024-12-28lib/test: update comment to show link on reflect.EqualerShulhan
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
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
2023-09-11lib/test: refactoring, rename TestWriter to BufferWriterShulhan
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.
2023-05-30lib/test: update documentation related to Assert and DataShulhan
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.
2023-05-25lib/test: use different package for exampleShulhan
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.
2023-03-12lib/test: update the Assert comment related to latest changesShulhan
While at it, update the CHANGELOG to add that previous changes.
2023-03-02lib/test: simplify the string diff output from AssertShulhan
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.
2022-09-21lib/test: fix Assert always fail if no changes after string diffShulhan
While at it, update the Assert documentation by describing output lines after "----" and "++++".
2022-09-15lib/test: use text/diff to compare strings on AssertShulhan
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).
2022-09-13lib/test: change the Assert parameter to WriterShulhan
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.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
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.
2020-11-23test: refactoring Assert with better error messageShulhan
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.
2020-03-20reflect: add function IsEqual that works with Equaler interfaceShulhan
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.
2020-03-20test: check if exp implement reflect.EqualerShulhan
If the exp parameter implement the extended "reflect.Equaler" interface then it will use the method IsEqual() with "got" as parameter.
2019-03-26test: change the error format to print "got" before "expectation"Shulhan
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
2018-11-30all: minimize and suppress linter warnings for global variablesShulhan
2018-09-01[chore] Update documentationsShulhan
2018-05-10Refactor parser using bytes.ReaderShulhan
Previous benchmark result (22dcd07 Move buffer to reader), BenchmarkParse-2 500 19534400 ns/op 4656335 B/op 81163 allocs/op New benchmark result, BenchmarkParse-2 20000 71120 ns/op 35368 B/op 549 allocs/op
2018-05-10test: add parameter for name of field to assertShulhan
2018-05-07Add library for simplify testingShulhan