Commit Graph

26 Commits

Author SHA1 Message Date
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
6a1e7b3996 pkg/shell: Add more daemon-related tests.
Also:

- Remove duplicate code for closing daemon client.

- Avoid using (*testing.T).TempDir - it uses test name in the path, which can
  exceed the limit of the address when calling bind(2):
  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html#tag_13_6
7_04
2022-06-19 21:45:36 +01:00
Qi Xiao
e06bf69a74 pkg/shell: Add tests for DB path. 2022-06-19 20:29:50 +01:00
Qi Xiao
78d914b24b pkg/shell: Run TestInteract_ConnectsToDaemon on Windows too.
This test now succeeds on Windows too, now that the daemon also uses Unix
sockets on Windows.
2022-06-19 19:08:11 +01:00
Qi Xiao
f3ea882bd2 Warn about files in ~/.elvish instead of the directory itself. 2022-06-12 14:21:57 +01:00
Qi Xiao
cb8628bcb6 Print a warning if ~/.elvish exists as a directory.
This addresses #1554.
2022-06-07 23:35:13 +01:00
Kurtis Rader
f681a73a1d Don't dot import pkg/testutil
Qualified imports of pkg/testutil outnumber unqualified (55 to 7). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Qi Xiao
33a04f8dc1 Revamp flag handling in pkg/prog.
Instead of putting all possible flags in prog.Flags, flags are now registered by
the individual subprograms. The 3 flags -sock, -db and -json are shared by
multiple subprograms and still handled by the prog package.

This new design allows separating the support for -cpuprofile into a separate
subprogram, which is no longer included by the default entry point, making the
binary slightly smaller. A new entrypoint "withpprof" is created.

Also include the LSP subprogram in the nodaemon entry point.
2022-02-05 14:52:29 +00: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
Qi Xiao
f3eb4a81a1 pkg/shell: Replace the run function with the fixture.run method in tests. 2021-08-07 00:00:35 +01:00
Qi Xiao
d0c6a4e1c3 Fix tests on Windows. 2021-08-06 23:39:02 +01:00
Qi Xiao
07f64d8345 pkg/shell: Introduce a common setup on top of progtest.Setup. 2021-08-06 23:31:25 +01:00
Qi Xiao
e9d328aa16 Make use of (*testing.T).Cleanup for test cleanups.
This allows turning the following pattern in tests:

  value, cleanup := setupSomething()
  defer cleanup()

into the following:

  value := setupSomething(t)
2021-08-06 23:21:23 +01:00
Qi Xiao
adf8066819 pkg/testutil: Make MustWriteFile easier to use.
The function now take a string for the file content, and always uses 0600 for
file permission.
2021-08-06 21:38:37 +01:00
Qi Xiao
a9039e8904 pkg/shell: Add tests for different paths of rc.elv. 2021-08-06 21:31:39 +01:00
Qi Xiao
44090025bf pkg/shell: Refactor tests to be more high-level.
This commit changes tests against the internal script and interact functions to
test against the overall Program behavior instead.
2021-08-05 22:33:41 +01:00
Qi Xiao
9c9a473826 pkg/shell: Rearrange files and reduce API surface. 2021-07-10 20:15:03 +01:00
Qi Xiao
d92c4bc08a Refactor shell and daemon initialization code.
In particular, the code for retrieving file paths needed by the runtime is
simplified a lot, and the paths only needed for the storage daemon is cleanly
separated from other paths.
2021-06-28 20:02:38 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
de562f84d4 Deprecate the $-exports- mechanism in 0.15. 2021-01-19 23:28:38 +00:00
Qi Xiao
75baa0b5a2 pkg/eval: Remove (*Ns).Append.
This change makes Ns immutable from the exposed API. Internally there is exactly
one place that still mutates Ns, in scopeOp; this will be addressed later.
2021-01-05 01:09:04 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +00:00
Kurtis Rader
3643f252f3 Verify stdout and stderr in shell tests
While working on my next commit, to prevent I/O deadlocks, I experienced
some problems because I had a syntax error in the Elvish code to generate
the output. That wasn't immediately obvious because I had copied another
test that only tested the stdout of the shell and the syntax error was
written to stderr. This change modifies existing tests to verify both
stdout and stderr have the expected content.

Note that there are three interactive tests for which we still do not
verify the content of stderr. That's because stderr for those tests only
contains a shell prompt whose content changes each time the test is run.
TBD is modifying the interactive tests to have a predictable prompt.
2020-08-11 15:58:20 +01:00
Kurtis Rader
1045fa3d1f Panic during shell unit tests should be failures
While debugging my fix for issue #661 I noticed that a panic that invokes
the `rescue` function causes Go to think the test passed due to launching
a rescue shell. This introduces a mechanism for elvish unit tests to
request that panics be fatal; i.e., exit with a non-zero status rather
than launch a rescue shell.

This also changes the behavior of panics by non-interactive elvish
shells to no longer launch an unexpected rescue shell.
2020-07-11 14:16:48 +01:00
Qi Xiao
78cae6a695 pkg/prog/{shell,web} -> pkg/{shell,web}. 2020-04-25 00:12:18 +01:00