sapling/tests/test-newercgi.t
Jun Wu 9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00

61 lines
1.5 KiB
Perl

#require no-msys # MSYS will translate web paths as if they were file paths
This is a rudimentary test of the CGI files as of d74fc8dec2b4.
$ hg init test
$ cat >hgweb.cgi <<HGWEB
> #!$PYTHON
> #
> # An example CGI script to use hgweb, edit as necessary
>
> import cgitb
> cgitb.enable()
>
> from edenscm.mercurial import demandimport; demandimport.enable()
> from edenscm.mercurial.hgweb import hgweb
> from edenscm.mercurial.hgweb import wsgicgi
>
> application = hgweb("test", "Empty test repository")
> wsgicgi.launch(application)
> HGWEB
$ chmod 755 hgweb.cgi
$ cat >hgweb.config <<HGWEBDIRCONF
> [paths]
> test = test
> HGWEBDIRCONF
$ cat >hgwebdir.cgi <<HGWEBDIR
> #!$PYTHON
> #
> # An example CGI script to export multiple hgweb repos, edit as necessary
>
> import cgitb
> cgitb.enable()
>
> from edenscm.mercurial import demandimport; demandimport.enable()
> from edenscm.mercurial.hgweb import hgwebdir
> from edenscm.mercurial.hgweb import wsgicgi
>
> application = hgwebdir("hgweb.config")
> wsgicgi.launch(application)
> HGWEBDIR
$ chmod 755 hgwebdir.cgi
$ . "$TESTDIR/cgienv"
$ $PYTHON hgweb.cgi > page1
$ $PYTHON hgwebdir.cgi > page2
$ PATH_INFO="/test/"
$ PATH_TRANSLATED="/var/something/test.cgi"
$ REQUEST_URI="/test/test/"
$ SCRIPT_URI="http://hg.omnifarious.org/test/test/"
$ SCRIPT_URL="/test/test/"
$ $PYTHON hgwebdir.cgi > page3
$ grep -i error page1 page2 page3
[1]