Commit Graph

33 Commits

Author SHA1 Message Date
Jun Wu
a459d31cae testutil/dott: use bindings.commands to run commands
Summary:
This makes it possible to execute Rust commands from the Python tests.

Test changes:
- test-command-template-t: non-utf8 command-line arguments are rejected at the
  function signature level
- test-dispatch-debug-prefix-t: the error is now printed by Rust code, which
  uses spaces instead of tabs.
- test-root-t: the test now passes

Reviewed By: xavierd

Differential Revision: D16866459

fbshipit-source-id: 386931c5497b04c53efc08fbb4de708812517ad9
2019-08-28 19:26:26 -07:00
Jun Wu
c18159134f testutil/dott: set commands.names
Summary:
This gives the Rust code path hints to names of Python command names.

Ideally, the Rust command dispatch logic can just load the Python command table
and figure out it more accurately, and more parts of dispatch.py (ex. extension
loading, debugger, profiler, atexit, etc) are moved to Rust clidispatch or
hgcommands. But that would be a larger change.

Reviewed By: xavierd

Differential Revision: D16866462

fbshipit-source-id: eb993091d5644710686b8f720fd07258b9a5968c
2019-08-28 19:26:26 -07:00
Jun Wu
cadeb66132 testutil/dott: translate piped commands correctly
Summary: Previously, `|` was treated as an argument of a command. Fix it.

Reviewed By: singhsrb

Differential Revision: D16473729

fbshipit-source-id: 0c9a76cd01fc3a22bd43cd0b7d96ce9c6e61ce37
2019-08-02 17:04:00 -07:00
Jun Wu
6253e8a50e testutil/dott: make translate use posix shell quote
Summary:
`util.shellquote` is platform-dependent. In case of the translator, it always
uses `shlex.split`. Therefore the posix shell quote should be used.

This makes the the test stable across multiple platforms. Namely, `"` is not
used on Windows.

Reviewed By: xavierd

Differential Revision: D16606904

fbshipit-source-id: 879e06b54fc427a6ad1aa959927a0df52f33269a
2019-08-01 17:59:20 -07:00
Jun Wu
5e701ebdaf testutil/dott: fix parsecmd
Summary:
`parsecmd` uses `for name in dictobj`, which can get different results due to
different random seed being used. Use an explicit list instead to avoid the issue.

Reviewed By: xavierd

Differential Revision: D16596261

fbshipit-source-id: c81665cb550a0ce76885aa7f3caee959d63f7b67
2019-08-01 17:59:20 -07:00
Jun Wu
5f1e0890a0 testutil/dott: split the translate function
Summary:
This makes it possible to test the translate behavior without writing anything
to filesystem.

Reviewed By: xavierd

Differential Revision: D16473728

fbshipit-source-id: 3c07b2b5e41d40444b98e7f02de840d2105082fe
2019-08-01 17:59:19 -07:00
Jun Wu
11522e065c testutil/dott: normalize Windows path after decoding "(esc)"
Summary:
The old code replaces `\foo (esc)` to `/foo (esc)`, and break the `(esc)`
decoding. Change the order so we decode `(esc)` first before normalizing
the path.

Reviewed By: sfilipco

Differential Revision: D16501047

fbshipit-source-id: ac49fa89fe0123436a994548b045edc0cef0a982
2019-07-25 17:43:41 -07:00
Jun Wu
eaabc7f3c6 edenscm: move sys.path handling to top-level edenscm
Summary:
Make `import edenscm` take care of `sys.path` so as long as `import edenscm`
works, 3rd party pure Python dependencies and edenscmnative should be
importable.

This reduces adhoc sys.path handling in testutil.dott, and fixes an issue where
testing on Windows where `testuitl.dott` fails to run hg commands due to
missing 3rd party dependencies (because `edenscm.mercurial.entrypoint.run` is
not called, and edenscmdeps.zip is not in sys.path).

Reviewed By: sfilipco

Differential Revision: D16499458

fbshipit-source-id: 17e6e5754614dfcf352127d471c649ded4189e1a
2019-07-25 17:43:41 -07:00
Jun Wu
60cf7203a4 testutil/dott: add a note about endless output
Summary:
The `output` API is the thing that stops infinite output from being used.

If endless output is needed, it can be expressed using something like Python
generator. Then the callsites using `stdin` needs update as well.

Reviewed By: xavierd

Differential Revision: D16464660

fbshipit-source-id: 1b81c44c5089f03687aa63ed3ffda9a5399c199b
2019-07-24 14:32:29 -07:00
Jun Wu
96c5c34019 testutil/dott: implement pipes, head and tail
Summary:
This makes it possible to write:

  sh % 'command' | 'head -2'

in tests

Reviewed By: xavierd

Differential Revision: D16452932

fbshipit-source-id: 8af1355cebc40085fb7af67ceb24a4d54783d388
2019-07-24 14:32:24 -07:00
Jun Wu
462a97942d testutil/dott: implement chmod +x
Summary: Some tests use `chmod +x`. Implement it.

Reviewed By: xavierd

Differential Revision: D16452926

fbshipit-source-id: e354e7e0be97422c8c7e0e7c620c34945481a982
2019-07-24 14:32:24 -07:00
Jun Wu
d49bdd9fed testutil/dott: restore cwd after a command
Summary:
In case the command is `hg --cwd ...`, the side effect of changing pwd should
be reverted at the end of the command.

Reviewed By: xavierd

Differential Revision: D16452924

fbshipit-source-id: 82f96b66ad3fed123cb2e906fc51d6627b16c1f0
2019-07-24 14:32:24 -07:00
Jun Wu
4ee9de2bd7 testutil/dott: fix (re) pattern matching
Summary:
Fixes 2 obvious mistakes:
- Other code uses `trailing space` instead of `trailing spaces`.
- The second `re.match` was mistyped.

Reviewed By: xavierd

Differential Revision: D16452929

fbshipit-source-id: d13cb1f792c2a7275e130ff5314d733b307dd635
2019-07-24 14:32:24 -07:00
Jun Wu
ca42b02813 testutil/dott: fix test command
Summary: The "succeed" code path was missing in the `test` command.

Reviewed By: xavierd

Differential Revision: D16452921

fbshipit-source-id: a276b774c528edaf60e0ecbbad00c15ddd8ba1d1
2019-07-24 14:32:23 -07:00
Jun Wu
b88812e338 testutil: stop generating lines with trailing spaces
Summary:
The `_repr` implementation can generate docstrings with trailing spaces if
`indent` is > 0.

Fix it by special handling the blank line case.

Reviewed By: xavierd

Differential Revision: D16452935

fbshipit-source-id: 99704ba3fb30b93aa35ba4fb16c1d853c58c6635
2019-07-24 14:32:23 -07:00
Jun Wu
8beb778255 testutil/dott: fix translator dropping redirections
Summary:
In case there are multiple commands in a line, and the first command uses
redirections:

  foo > bar && baz

The `> bar` got lost after translation. This is because the same `opts` Python
object (including `> bar` information) was returned and it was mutated.

Solve it by returning a copy of `opts` per command.

Reviewed By: xavierd

Differential Revision: D16452936

fbshipit-source-id: a7ab55cc44ebe628817f821412576e17f6f68a6f
2019-07-24 14:32:23 -07:00
Jun Wu
6cd7d1799c encoding: add a way to change HGENCODING at runtime
Summary:
Make it possible to change the internal state of HGENCODING so we can run hg
logic within a single process without shelling out in the new dott test
framework.

Update testutil/dott to use it.

Reviewed By: xavierd

Differential Revision: D16452925

fbshipit-source-id: d21329854eeee171cc5d02d4f42f11dd273f2150
2019-07-24 14:32:23 -07:00
Jun Wu
237846d4ca tests: try to make build_nupkg.py test work
Summary:
build_nupkg.py test will copy tests/ to build/embedded/tests/ before running
them. That breaks testutil.dott "edenscm" module discovery. Try to fix it by
making "edenscm" module discovery consider "build/embedded/python27.zip".

Reviewed By: xavierd

Differential Revision: D16383017

fbshipit-source-id: 52e19182d3e5e7267221244bd39d9a146928d8df
2019-07-19 15:08:17 -07:00
Jun Wu
59c9cee23a testutil/dott: append '(trailing spaces)' to lines with trailing spaces
Summary:
Some linters or editers are unhappy with trailing spaces in heredoc.
Workaround it.

Reviewed By: xavierd

Differential Revision: D16344717

fbshipit-source-id: 63be8b992e2e4718faea1a55655c592f0e87b206
2019-07-17 21:11:32 -07:00
Jun Wu
77dbcbbf24 testutil/dott: add a script to translate .t files
Summary:
Add a script to automatically translate .t tests to .py tests using
testutil.dott.

Reviewed By: xavierd

Differential Revision: D16172903

fbshipit-source-id: a1d736ae3e8035ac254af59c6dff5eb9f204f1fb
2019-07-17 21:11:31 -07:00
Jun Wu
4853d63b69 testutil/dott: implement per-command environment variables
Summary: This allows FOO=bar to work in some tests.

Reviewed By: xavierd

Differential Revision: D16344718

fbshipit-source-id: b600d928a42e9e8e36a2ab9f5db97fd489878d02
2019-07-17 21:11:31 -07:00
Jun Wu
b8f57dbe27 testutil/dott: implement feature test
Summary:
`.t` tests use `hghave` to test features, and can have `#testcases` for
multiple test cases. Implement them.

Reviewed By: xavierd

Differential Revision: D16209201

fbshipit-source-id: 1e8ea32d966f922efcf94e555cc9ab946cc85b27
2019-07-17 21:11:31 -07:00
Jun Wu
4a0d11f14f testutil/dott: implement "source library.sh"
Summary:
Tests use "source" to enable new features. One the main sources is
"library.sh", which includes remotefilelog utilties. Implement it.

Reviewed By: xavierd

Differential Revision: D16209209

fbshipit-source-id: 3bce4296861947e753e37bccf83c05129960dece
2019-07-17 21:11:30 -07:00
Jun Wu
57483c41b1 testutil/dott: implement some tinit.sh functions
Summary: tinit.sh provides some handy functions. Implement them.

Reviewed By: xavierd

Differential Revision: D16209205

fbshipit-source-id: 084669833086fef61e215865e792260dc2e35794
2019-07-17 21:11:30 -07:00
Jun Wu
c5a7b31dbf testutil/dott: implement "hg"
Summary:
Implement hg commands. This uses the dispatch code path to run hg commands
without startup overhead. It's possible that some side effects in the Python
world can cause unwanted behavior. Therefore a "reload" function was provided.

Once we have Rust as the entry point, we might still want to have some Python
binding to the Rust logic so the test code can use them.

Reviewed By: xavierd

Differential Revision: D16209204

fbshipit-source-id: e510f59629b46afd6b140c7bec9de07698b523b9
2019-07-17 21:11:30 -07:00
Jun Wu
1364b3a3ae testutil/dott: implement a subset of coreutils
Summary: Implement a subset of coreutils so functions used by .t can run.

Reviewed By: xavierd

Differential Revision: D16209202

fbshipit-source-id: 953bebbfdc09cf191e8aa04c5ee1468c764b4360
2019-07-17 21:11:30 -07:00
Jun Wu
6977426d45 testutil/dott: remove indentation from heredoc
Summary:
To make the code look better, indentation gets added to heredoc content.
Remove them. This replaces `inspect.cleandoc`. The difference is
`inspect.cleandoc` special handles the first line, which is undesirable.

Reviewed By: xavierd

Differential Revision: D16344716

fbshipit-source-id: c69c20607ddc5292bc6bcdd840587258276016ed
2019-07-17 21:11:29 -07:00
Jun Wu
744a504d00 testutil/dott: implement TESTTMP support
Summary:
TESTTMP was handled by run-tests.py. This diff extracts a subset of TESTTMP
logic so tests using testutil/dott can run via Python directly without using
run-tests.py

Reviewed By: xavierd

Differential Revision: D16209203

fbshipit-source-id: 7605505a725c30c9d07d83b7d3bfe92ec215cefc
2019-07-17 21:11:29 -07:00
Jun Wu
b87a92215f testutil/dott: implement advanced output matching
Summary:
`run-tests.py` supports `(glob)`, `(re)`, `(esc)` for output matching.
Implement them.

Note: `(?)` is harder to implement. It is not implemented in this diff.

Reviewed By: xavierd

Differential Revision: D16209212

fbshipit-source-id: 52172158c41286a0673e6ae25bde2c774ac24c52
2019-07-17 21:11:28 -07:00
Jun Wu
08c15a105a testutil/dott: normalize error messages
Summary:
run-tests.py uses common-pattern.py to normalize error messages to things
like `$ENOENT$`. Implement that behavior.

Reviewed By: xavierd

Differential Revision: D16209208

fbshipit-source-id: 3e609cc16442f80b844264f93dce9ea46517458d
2019-07-17 21:11:28 -07:00
Jun Wu
27908b883c testutil/dott: initial framework
Summary:
The testutil/dott module is to be "somehow" compatible with ".t" tests.
At its core, it emulates "bash" syntax using Python functions.

This diff adds the core "sh" syntax to call into Python functions.
The test code can be written as:

  from testutil.dott import sh

  sh % "echo foo" == "foo\n"
  sh % "echo remotefilelog" > ".hg/requires"
  sh % "cat" << "[extensions]\nrebase=" > ".hg/hgrc"

This is similar to ".t" test:

  $ echo foo
  foo
  $ echo remotefilelog > .hg/requires
  $ cat << EOF > .hg/hgrc
  > [extensions]
  > rebase=
  > EOF

And is compat even after black formatting.

Reviewed By: xavierd

Differential Revision: D16172901

fbshipit-source-id: 7bb666e7e1621536ffdd6516542a468ac419d80a
2019-07-17 21:11:28 -07:00
Jun Wu
2232a26c42 testutil: add "eq" assertion with autofix ability
Summary: The "eq" API is similar to `assert_eq!` in Rust, with the autofix ability.

Reviewed By: xavierd

Differential Revision: D16168821

fbshipit-source-id: bf7dcfd24c42dee30c54aeeaa71eccab78a8f0f6
2019-07-17 21:11:27 -07:00
Jun Wu
dd1b0586c0 testutil: add a utility to calculate argument positions
Summary:
The utility is used by a later change which provides the "autofix" feature for
Python code.

Reviewed By: xavierd

Differential Revision: D16168823

fbshipit-source-id: feb55a9e6ba5e78ad0f490cadeeafbcc1306e8ca
2019-07-17 21:11:27 -07:00