Commit Graph

52 Commits

Author SHA1 Message Date
Qi Xiao
d7fe04414b pkg/eval/evaltest: Import all builtin modules.
This removes the need for various "use-foo" setups for the standard library
modules - test code can just call "use foo" like normal Elvish code.
2024-02-01 14:46:37 +00:00
Qi Xiao
d4f11db983 pkg/eval/evaltest: Remove the old testing framework. 2024-01-30 20:53:56 +00:00
Qi Xiao
747a34aef1 pkg/eval/evaltest: Generate .elvts files from non-transcript tests.
This is done implicitly in evaltest.Run. This commit will be reverted after the
.elvts files are generated and cleaned up.
2024-01-30 20:15:58 +00:00
Qi Xiao
0e2999dee8 Support using Elvish transcripts as tests.
- evaltest.TestTranscriptsInFS runs transcripts in .elv and .elvts files as
  tests.

- Extend the syntax of Elvish transcripts with headings and comments; the former
  is used to split a single .elvts file into multiple sessions.
2024-01-30 20:15:58 +00:00
Qi Xiao
5775c8b3ed pkg/diag: Rework API and presentation of Context and Error.
- Change Context to export all its fields.

- Include end position in Context, and include it in Show.

- Remove the Type field from Error, and express it using an ErrorTag type
  parameter instead.

- Make {Pack Unpack}CognateErrors type-safe with the new ErrorTag mechanism, and
  rename them to just {Pack Unpack}Errors.
2024-01-16 11:04:52 +00:00
Qi Xiao
791b4857e1 pkg/eval/evaltest: Fix the bytes output error message. 2024-01-08 15:44:14 +00:00
Qi Xiao
607fa68aca Implement os:stat.
Time fields are omitted for now; they will be added when there's a proper Elvish
binding for time.Time.

This addresses #1659.
2023-08-21 00:05:05 -04:00
Qi Xiao
65bc9580cb pkg/eval/evaltest: Print value diffs by converting them with Repr first.
The options to go-cmp doesn't seem to actually transform lists and maps
properly, so use the string representation for diffs now.
2023-08-20 23:30:30 -04:00
Qi Xiao
95ba078ff6 pkg/eval/evaltest: Implement value matchers with interface. 2023-08-13 23:20:54 -04:00
Qi Xiao
e847e677fe Move a lot of symbols from path: to os:.
Most of the symbols moved originate from Go's os package. However,
eval-symlink, which is provided by Go's path/filepath package, is also moved to
the os: module since it requires actual filesystem access. The idea is that
Elvish's path: will only provide functionalities for lexically manipulating
file paths without referencing the actual filesystem, akin to Python's
pathlib.PurePath.

The old symbols in path: are not formally deprecated since the compiler can't
statically check symbols in modules yet.
2023-08-06 12:06:41 -04:00
Qi Xiao
a1b30deb86 pkg/eval/evaltest: Rename TestWithFullSetup -> TestWithSetup.
The old TestWithSetup is now more accurately called TestWithEvalerSetup.
2023-07-22 23:04:18 +01:00
Qi Xiao
981388d5c2 Add file:open-output. 2023-07-22 17:20:19 +01:00
Qi Xiao
19bd75db57 pkg/eval: Make the peach test cases print $best-run on failure. 2023-05-08 23:34:04 +01:00
Qi Xiao
0557e2a3be pkg/eval/evaltests: Make APIs of special matchers functions. 2023-05-08 23:27:53 +01:00
Qi Xiao
da576e221c pkg/eval: Use a Context inside Frame to pass interrupts. 2023-05-07 21:44:28 +01:00
Qi Xiao
97a73e2d95 evaltest.capturePort -> eval.CapturePort.
Also rename the original eval.CapturePort to ValueCapturePort.
2023-01-15 16:44:25 +00:00
Qi Xiao
c7ed16d3cb pkg/eval/evaltest: Print byte output diff with go-cmp. 2023-01-15 16:44:25 +00:00
Qi Xiao
121509d8d2 pkg/eval: Preserve all compilation errors.
Multiple compilation errors are packed using diag.PackCognateErrors, like parse errors.
2022-11-30 01:40:03 +00:00
Qi Xiao
94ab1b5390 Generalize parse.Errors and move it to diag.
This generalized type will be used to pack multiple compilation errors.
2022-11-30 01:05:16 +00:00
Qi Xiao
93e28d846b Fixup for #1618.
- Simplify the matcher for compilation errors.

- Various stylistic fixes.
2022-11-20 16:39:01 +00:00
Kurtis Rader
358e52a7f5 Make testing compilation errors more deterministic
A year ago I submitted a change to replace AnyError with tests for specific
errors (see https://github.com/elves/elvish/commit/87656c99).  This does
something similar for DoesNotCompile. This ensures the test does what
is implied and makes correlating specific unit tests with compilation
errors easier.

This includes a couple of changes to compilation error messages to improve
readability (IMHO) but those are not the primary purpose of this change.

Related #1560
2022-11-20 16:33:29 +00:00
Qi Xiao
2e788c846d Run gofmt.
https://tip.golang.org/doc/go1.19#go-doc
2022-08-07 22:30:11 +01:00
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
6ec410753b evaltest: Fix diff output. 2022-04-07 20:46:30 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
957c8a7521 evaltest: Check that stderr is empty if PrintsStderrWith is not called.
Among other things, this will check for deprecation warnings. Also fix test code
that uses deprecated features.
2022-03-20 09:50:05 +00:00
Qi Xiao
5f1673c6c4 Use go-cmp to report unexpected test results.
cmp.Diff panics when comparing a struct that has unexported fields and no String
or Equal method, so change some structs to either export all their fields or
have an Equal method.

This fixes #1136.
2022-03-11 22:49:32 +00:00
Qi Xiao
097e32b375 pkg/eval/vals: Add ReprPlain, Repr without pretty-printing.
Also de-export NoPretty now that it is no longer needed.
2021-12-31 21:05:07 +00:00
Kurtis Rader
87656c99fa Replace AnyError in tests with a specific error
The `AnyError` placeholder error can cause tests to succeed for errors
other than what was expected. That is, the use of `AnyError` can mask
bugs in a unit test. So replace it with the specific error, or error type,
the test expects to be raised.

This does not remove the anyError structure because it is used in
the TestCase.DoesNotCompile() method. To keep the size of this change
as small as possible I want to defer updating that use to a separate
change. However, remove the public AnyError var so future test writers
don't attempt to use it.
2021-12-13 01:08:24 +00:00
Qi Xiao
fc754f6822 pkg/eval: Deliver message for finished bg job using editor notification.
This fixes #1067.
2021-10-05 00:08:14 +01:00
Qi Xiao
68168da9fc pkg/eval: Convert elements of slice return value from a GoFn to individual outputs. 2021-10-03 16:34:52 +01:00
Qi Xiao
418ae40ea9 pkg/eval/evaltest: Update godoc (TestCase -> Case). 2021-09-15 20:19:25 +01:00
Qi Xiao
90d5d01cc5 pkg/eval/evaltest: Fix package godoc.
There was an empty line between the godoc and the package line by mistake.
2021-09-12 18:04:24 +01:00
Qi Xiao
7ef7cb9f1b pkg/eval/evaltest: Clean up godoc and some minor API details. 2021-09-12 14:13:18 +01:00
Qi Xiao
b6d69d0b30 pkg/prog/progtest: Rewrite the progtest API.
The progtest package now provides a declarative framework, modelled after
pkg/eval/evaltest. Tests that use progtest are now much more concise.
2021-09-12 14:06:05 +01:00
Kurtis Rader
57cf018e06 Update unit tests that use p[rw]close
Replaces uses of the deprecated builtin `prclose` and `pwclose` commands
with `file close` in unit tests.

This also fixes one test that was not verifying what it intended due to
it's use of `.Throws(AnyError)` which was matching an Elvish error caused
by invalid command `file:prclose $p`.
2021-08-01 21:17:02 +01:00
Qi Xiao
82b9bddb15 Test almost all commands correctly bubble output errors.
Also make the helper thatOutputErrorIsBubbled more precise by matching for the
exact error that is thrown.
2021-06-24 23:24:43 +01:00
Qi Xiao
90acb4a242 Minor fixup for path:temp-{dir file}.
* Remove `MatchesRegexp` from eval/vals since it is not part of the
  Elvish value protocol.

* Simplify implementation of value matching in `eval/evaltest`.

* Documentation wording tweaks.
2021-04-25 23:03:44 +01:00
Kurtis Rader
bc37099c92 Add equivalent of mktemp as builtin commands.
This implements `path:temp-dir` and `path:temp-file`.

Resolves #1255
2021-04-25 17:34:23 -04:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
8d1a6b34db pkg/eval/evaltest: Support testing evaluation of multiple code pieces.
Also use this to simplify TestMultipleEval in pkg/eval.
2021-01-10 00:08:58 +00:00
Qi Xiao
402861fcfb eval/evaltest: Simplify EvalAndCollect. 2021-01-10 00:04:07 +00:00
Qi Xiao
b77a052e7e pkg/eval: Make Exception an interface.
This change is a preparation step for refining all *Op types to return Exception
as the error.

Keeping Exception as a struct type will make such a change error-prone, since
a (*Exception)(nil) != error(nil), so if an *Op returns a nil *Exception, it
is not nil if the return value is stored in an error-typed variable.
2021-01-08 00:56:45 +00:00
Qi Xiao
2033600881 pkg/eval: Clean up Port related code. 2021-01-05 05:23:17 +00:00
Qi Xiao
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +00:00
Qi Xiao
dc59cbfeb4 pkg/eval: Make (*Evaler).Eval accept a Source instead of an Op.
Most callers can now call it with the source to evaluate, without having to call
ParseAndCompile first themselves.
2021-01-02 00:10:26 +00:00
Kurtis Rader
9c7c9cf7d9 [cleanup] trivial golint suggested changes
As with commit #eb2a792 I acknowledge that `golint` recommendations are
controversial and should not automatically be acted on. Nonetheless,
this change fixes legitimate lint issues such as copy/paste cleanups,
style problems I introduced (`i += 1` versus `i++`) or method/var comments
that are not in the preferred form.
2020-12-25 01:11:33 +00:00
Qi Xiao
f3c2185dae pkg/eval/evaltest: Move Must* functions to the testutil package.
Also exclude those functions from test coverage calculation.
2020-09-04 21:57:20 +01:00
Qi Xiao
bd33459eaf pkg/eval/evaltest: Move value and error matching code to separate file. 2020-09-04 20:55:19 +01:00
Qi Xiao
90a99c1792 pkg/eval/evaltest: Consolidate all the Throws* methods into one. 2020-09-04 20:31:47 +01:00