anchor.diff:          --zsh contrib/zsh_completion
       '';
   
  -    passthru.tests = {};
  +    passthru.tests = {
  +      mercurial-tests = makeTests { flags = "--with-hg=$MERCURIAL_BASE/bin/hg"; };
  +    };
   
       meta = with lib; {
         description = "A fast, lightweight SCM system for very large distributed projects";
  
positive.code: 
      makeFlags = [ "PREFIX=$(out)" ]
        ++ lib.optional rustSupport "PURE=--rust";
  
      doCheck = stdenv.isLinux;  # tests seem unstable on Darwin
      checkInputs = [
        unzip
        which
        sqlite
        git
        gnupg
      ];
      SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";  # needed for git
      checkPhase = ''
        cat << EOF > tests/blacklists/nix
        # tests enforcing "/usr/bin/env" shebangs, which are patched for nix
        test-run-tests.t
        test-check-shbang.t
  
        # unstable experimental/unsupported features
        # https://bz.mercurial-scm.org/show_bug.cgi?id=6633#c1
        test-git-interop.t
        EOF
  
        # extended timeout necessary for tests to pass on the busy CI workers
        export HGTESTFLAGS="--blacklist blacklists/nix --timeout 1800"
        make check
      '';
  
      postInstall = (lib.optionalString guiSupport ''
        mkdir -p $out/etc/mercurial
  
negative.code:       platforms = platforms.unix;
      };
    };
  
    makeTests = { mercurial ? self, nameSuffix ? "", flags ? "" }: runCommand "${mercurial.pname}${nameSuffix}-tests" {
      inherit (mercurial) src;
  
      SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";  # needed for git
      MERCURIAL_BASE = mercurial;
      nativeBuildInputs = [
        python
        unzip
        which
        sqlite
        git
        gnupg
      ];
  
      postPatch = ''
        patchShebangs .
  
        for f in **/*.{py,c,t}; do
          # not only used in shebangs
          substituteAllInPlace "$f" '/bin/sh' '${stdenv.shell}'
        done
  
        for f in **/*.t; do
          substituteInPlace 2>/dev/null "$f" \
            --replace '*/hg:' '*/*hg*:' \${/* paths emitted by our wrapped hg look like ..hg-wrapped-wrapped */""}
            --replace '"$PYTHON" "$BINDIR"/hg' '"$BINDIR"/hg' ${/* 'hg' is a wrapper; don't run using python directly */""}
        done
      '';
  
      # This runs Mercurial _a lot_ of times.
      requiredSystemFeatures = [ "big-parallel" ];
  
      # Don't run tests if not-Linux or if cross-compiling.
      meta.broken = !stdenv.hostPlatform.isLinux || stdenv.buildPlatform != stdenv.hostPlatform;
    } ''
      addToSearchPathWithCustomDelimiter : PYTHONPATH "${mercurial}/${python.sitePackages}"
  
      unpackPhase
      cd "$sourceRoot"
      patchPhase
  
      cat << EOF > tests/blacklists/nix
      # tests enforcing "/usr/bin/env" shebangs, which are patched for nix
      test-run-tests.t
      test-check-shbang.t
  
      # unstable experimental/unsupported features
      # https://bz.mercurial-scm.org/show_bug.cgi?id=6633#c1
      test-git-interop.t
  
      # doesn't like the extra setlocale warnings emitted by our bash wrappers
      test-locale.t
      EOF
  
      export HGTEST_REAL_HG="${mercurial}/bin/hg"
      # extended timeout necessary for tests to pass on the busy CI workers
      export HGTESTFLAGS="--blacklist blacklists/nix --timeout 1800 -j$NIX_BUILD_CORES ${flags}"
      make check
      touch $out
    '';
  in
    self.overridePythonAttrs (origAttrs: {
      passthru = origAttrs.passthru // rec {
  