summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:22 +0000
commitce6763317433ca8509f45bd1d471fb4ad2eeffdd (patch)
treea648ad7d54a5d3ffaa8519e7c73ea27541105c9b /testing
parentReleasing debian version 2.21.0-1. (diff)
downloadpre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.tar.xz
pre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.zip
Merging upstream version 3.0.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing')
-rw-r--r--testing/fixtures.py4
-rwxr-xr-xtesting/gen-languages-all30
-rwxr-xr-xtesting/get-coursier.ps111
-rwxr-xr-xtesting/get-coursier.sh34
-rwxr-xr-xtesting/get-dart.sh4
-rwxr-xr-xtesting/get-lua.sh5
-rw-r--r--testing/get-r.ps16
-rwxr-xr-xtesting/get-r.sh9
-rwxr-xr-xtesting/get-swift.sh2
-rw-r--r--testing/language_helpers.py35
-rwxr-xr-xtesting/make-archives2
-rw-r--r--testing/resources/conda_hooks_repo/.pre-commit-hooks.yaml10
-rw-r--r--testing/resources/conda_hooks_repo/environment.yml6
-rw-r--r--testing/resources/coursier_hooks_repo/.pre-commit-channel/echo-java.json8
-rw-r--r--testing/resources/coursier_hooks_repo/.pre-commit-hooks.yaml5
-rw-r--r--testing/resources/dart_repo/.pre-commit-hooks.yaml4
-rw-r--r--testing/resources/dart_repo/bin/hello-world-dart.dart6
-rw-r--r--testing/resources/dart_repo/pubspec.yaml10
-rw-r--r--testing/resources/golang_hooks_repo/golang-hello-world/main.go8
-rw-r--r--testing/resources/lua_repo/.pre-commit-hooks.yaml4
-rwxr-xr-xtesting/resources/lua_repo/bin/hello-world-lua3
-rw-r--r--testing/resources/lua_repo/hello-dev-1.rockspec15
-rw-r--r--testing/resources/perl_hooks_repo/.gitignore7
-rw-r--r--testing/resources/perl_hooks_repo/.pre-commit-hooks.yaml5
-rw-r--r--testing/resources/perl_hooks_repo/MANIFEST4
-rw-r--r--testing/resources/perl_hooks_repo/Makefile.PL10
-rwxr-xr-xtesting/resources/perl_hooks_repo/bin/pre-commit-perl-hello7
-rw-r--r--testing/resources/perl_hooks_repo/lib/PreCommitHello.pm12
-rw-r--r--testing/resources/r_hooks_repo/.pre-commit-hooks.yaml48
-rw-r--r--testing/resources/r_hooks_repo/DESCRIPTION19
-rwxr-xr-xtesting/resources/r_hooks_repo/additional-deps.R2
-rwxr-xr-xtesting/resources/r_hooks_repo/hello-world.R5
-rw-r--r--testing/resources/r_hooks_repo/renv.lock27
-rw-r--r--testing/resources/r_hooks_repo/renv/LICENSE7
-rw-r--r--testing/resources/r_hooks_repo/renv/activate.R440
-rw-r--r--testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml2
-rw-r--r--testing/resources/swift_hooks_repo/.gitignore4
-rw-r--r--testing/resources/swift_hooks_repo/.pre-commit-hooks.yaml6
-rw-r--r--testing/resources/swift_hooks_repo/Package.swift7
-rw-r--r--testing/resources/swift_hooks_repo/Sources/swift_hooks_repo/main.swift1
-rw-r--r--testing/util.py13
41 files changed, 73 insertions, 774 deletions
diff --git a/testing/fixtures.py b/testing/fixtures.py
index 5182a08..79a1160 100644
--- a/testing/fixtures.py
+++ b/testing/fixtures.py
@@ -12,8 +12,8 @@ from pre_commit import git
from pre_commit.clientlib import CONFIG_SCHEMA
from pre_commit.clientlib import load_manifest
from pre_commit.util import cmd_output
-from pre_commit.util import yaml_dump
-from pre_commit.util import yaml_load
+from pre_commit.yaml import yaml_dump
+from pre_commit.yaml import yaml_load
from testing.util import get_resource_path
from testing.util import git_commit
diff --git a/testing/gen-languages-all b/testing/gen-languages-all
deleted file mode 100755
index 05f8929..0000000
--- a/testing/gen-languages-all
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env python3
-from __future__ import annotations
-
-import sys
-
-LANGUAGES = (
- 'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail',
- 'golang', 'lua', 'node', 'perl', 'pygrep', 'python', 'r', 'ruby', 'rust',
- 'script', 'swift', 'system',
-)
-FIELDS = (
- 'ENVIRONMENT_DIR', 'get_default_version', 'health_check',
- 'install_environment', 'run_hook',
-)
-
-
-def main() -> int:
- print(f' # BEGIN GENERATED ({sys.argv[0]})')
- for lang in LANGUAGES:
- parts = [f' {lang!r}: Language(name={lang!r}']
- for k in FIELDS:
- parts.append(f', {k}={lang}.{k}')
- parts.append('), # noqa: E501')
- print(''.join(parts))
- print(' # END GENERATED')
- return 0
-
-
-if __name__ == '__main__':
- raise SystemExit(main())
diff --git a/testing/get-coursier.ps1 b/testing/get-coursier.ps1
deleted file mode 100755
index 42e5635..0000000
--- a/testing/get-coursier.ps1
+++ /dev/null
@@ -1,11 +0,0 @@
-$wc = New-Object System.Net.WebClient
-
-$coursier_url = "https://github.com/coursier/coursier/releases/download/v2.0.5/cs-x86_64-pc-win32.exe"
-$coursier_dest = "C:\coursier\cs.exe"
-$coursier_hash ="d63d497f7805261e1cd657b8aaa626f6b8f7264cdb68219b2e6be9dd882033a9"
-
-New-Item -Path "C:\" -Name "coursier" -ItemType "directory"
-$wc.DownloadFile($coursier_url, $coursier_dest)
-if ((Get-FileHash $coursier_dest -Algorithm SHA256).Hash -ne $coursier_hash) {
- throw "Invalid coursier file"
-}
diff --git a/testing/get-coursier.sh b/testing/get-coursier.sh
index 4c5e955..958e73b 100755
--- a/testing/get-coursier.sh
+++ b/testing/get-coursier.sh
@@ -1,15 +1,29 @@
#!/usr/bin/env bash
-# This is a script used in CI to install coursier
set -euo pipefail
-COURSIER_URL="https://github.com/coursier/coursier/releases/download/v2.0.0/cs-x86_64-pc-linux"
-COURSIER_HASH="e2e838b75bc71b16bcb77ce951ad65660c89bda7957c79a0628ec7146d35122f"
-ARTIFACT="/tmp/coursier/cs"
+if [ "$OSTYPE" = msys ]; then
+ URL='https://github.com/coursier/coursier/releases/download/v2.1.0-RC4/cs-x86_64-pc-win32.zip'
+ SHA256='0d07386ff0f337e3e6264f7dde29d137dda6eaa2385f29741435e0b93ccdb49d'
+ TARGET='/tmp/coursier/cs.zip'
-mkdir -p /tmp/coursier
-rm -f "$ARTIFACT"
-curl --location --silent --output "$ARTIFACT" "$COURSIER_URL"
-echo "$COURSIER_HASH $ARTIFACT" | sha256sum --check
-chmod ugo+x /tmp/coursier/cs
+ unpack() {
+ unzip "$TARGET" -d /tmp/coursier
+ mv /tmp/coursier/cs-*.exe /tmp/coursier/cs.exe
+ cygpath -w /tmp/coursier >> "$GITHUB_PATH"
+ }
+else
+ URL='https://github.com/coursier/coursier/releases/download/v2.1.0-RC4/cs-x86_64-pc-linux.gz'
+ SHA256='176e92e08ab292531aa0c4993dbc9f2c99dec79578752f3b9285f54f306db572'
+ TARGET=/tmp/coursier/cs.gz
+
+ unpack() {
+ gunzip "$TARGET"
+ chmod +x /tmp/coursier/cs
+ echo /tmp/coursier >> "$GITHUB_PATH"
+ }
+fi
-echo '##vso[task.prependpath]/tmp/coursier'
+mkdir -p /tmp/coursier
+curl --location --silent --output "$TARGET" "$URL"
+echo "$SHA256 $TARGET" | sha256sum --check
+unpack
diff --git a/testing/get-dart.sh b/testing/get-dart.sh
index b655e1a..998b9d9 100755
--- a/testing/get-dart.sh
+++ b/testing/get-dart.sh
@@ -5,10 +5,10 @@ VERSION=2.13.4
if [ "$OSTYPE" = msys ]; then
URL="https://storage.googleapis.com/dart-archive/channels/stable/release/${VERSION}/sdk/dartsdk-windows-x64-release.zip"
- echo "##vso[task.prependpath]$(cygpath -w /tmp/dart-sdk/bin)"
+ cygpath -w /tmp/dart-sdk/bin >> "$GITHUB_PATH"
else
URL="https://storage.googleapis.com/dart-archive/channels/stable/release/${VERSION}/sdk/dartsdk-linux-x64-release.zip"
- echo '##vso[task.prependpath]/tmp/dart-sdk/bin'
+ echo '/tmp/dart-sdk/bin' >> "$GITHUB_PATH"
fi
curl --silent --location --output /tmp/dart.zip "$URL"
diff --git a/testing/get-lua.sh b/testing/get-lua.sh
deleted file mode 100755
index 580e247..0000000
--- a/testing/get-lua.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env bash
-set -euo pipefail
-
-# Install the runtime and package manager.
-sudo apt install lua5.3 liblua5.3-dev luarocks
diff --git a/testing/get-r.ps1 b/testing/get-r.ps1
deleted file mode 100644
index e7b7b61..0000000
--- a/testing/get-r.ps1
+++ /dev/null
@@ -1,6 +0,0 @@
-$dir = $Env:Temp
-$urlR = "https://cran.r-project.org/bin/windows/base/old/4.0.4/R-4.0.4-win.exe"
-$outputR = "$dir\R-win.exe"
-$wcR = New-Object System.Net.WebClient
-$wcR.DownloadFile($urlR, $outputR)
-Start-Process -FilePath $outputR -ArgumentList "/S /v/qn"
diff --git a/testing/get-r.sh b/testing/get-r.sh
deleted file mode 100755
index 5d09828..0000000
--- a/testing/get-r.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env bash
-sudo apt install r-base
-# create empty folder for user library.
-# necessary for non-root users who have
-# never installed an R package before.
-# Alternatively, we require the renv
-# package to be installed already, then we can
-# omit that.
-Rscript -e 'dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)'
diff --git a/testing/get-swift.sh b/testing/get-swift.sh
index 3e78082..dfe0939 100755
--- a/testing/get-swift.sh
+++ b/testing/get-swift.sh
@@ -26,4 +26,4 @@ fi
mkdir -p /tmp/swift
tar -xf "$TGZ" --strip 1 --directory /tmp/swift
-echo '##vso[task.prependpath]/tmp/swift/usr/bin'
+echo '/tmp/swift/usr/bin' >> "$GITHUB_PATH"
diff --git a/testing/language_helpers.py b/testing/language_helpers.py
new file mode 100644
index 0000000..f9ae0b1
--- /dev/null
+++ b/testing/language_helpers.py
@@ -0,0 +1,35 @@
+from __future__ import annotations
+
+import os
+from typing import Sequence
+
+import pre_commit.constants as C
+from pre_commit.languages.all import Language
+from pre_commit.prefix import Prefix
+
+
+def run_language(
+ path: os.PathLike[str],
+ language: Language,
+ exe: str,
+ args: Sequence[str] = (),
+ file_args: Sequence[str] = (),
+ version: str = C.DEFAULT,
+ deps: Sequence[str] = (),
+ is_local: bool = False,
+) -> tuple[int, bytes]:
+ prefix = Prefix(str(path))
+
+ language.install_environment(prefix, version, deps)
+ with language.in_env(prefix, version):
+ ret, out = language.run_hook(
+ prefix,
+ exe,
+ args,
+ file_args,
+ is_local=is_local,
+ require_serial=True,
+ color=False,
+ )
+ out = out.replace(b'\r\n', b'\n')
+ return ret, out
diff --git a/testing/make-archives b/testing/make-archives
index 704101f..cec9a9f 100755
--- a/testing/make-archives
+++ b/testing/make-archives
@@ -17,7 +17,7 @@ from typing import Sequence
REPOS = (
('rbenv', 'https://github.com/rbenv/rbenv', '38e1fbb'),
- ('ruby-build', 'https://github.com/rbenv/ruby-build', '98c0337'),
+ ('ruby-build', 'https://github.com/rbenv/ruby-build', '9d92a69'),
(
'ruby-download',
'https://github.com/garnieretienne/rvm-download',
diff --git a/testing/resources/conda_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/conda_hooks_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index a0d274c..0000000
--- a/testing/resources/conda_hooks_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-- id: sys-exec
- name: sys-exec
- entry: python -c 'import os; import sys; print(sys.executable.split(os.path.sep)[-2]) if os.name == "nt" else print(sys.executable.split(os.path.sep)[-3])'
- language: conda
- files: \.py$
-- id: additional-deps
- name: additional-deps
- entry: python
- language: conda
- files: \.py$
diff --git a/testing/resources/conda_hooks_repo/environment.yml b/testing/resources/conda_hooks_repo/environment.yml
deleted file mode 100644
index e23c079..0000000
--- a/testing/resources/conda_hooks_repo/environment.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-channels:
- - conda-forge
- - defaults
-dependencies:
- - python
- - pip
diff --git a/testing/resources/coursier_hooks_repo/.pre-commit-channel/echo-java.json b/testing/resources/coursier_hooks_repo/.pre-commit-channel/echo-java.json
deleted file mode 100644
index 37f401e..0000000
--- a/testing/resources/coursier_hooks_repo/.pre-commit-channel/echo-java.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "repositories": [
- "central"
- ],
- "dependencies": [
- "io.get-coursier:echo:latest.stable"
- ]
-}
diff --git a/testing/resources/coursier_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/coursier_hooks_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index d4a143b..0000000
--- a/testing/resources/coursier_hooks_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-- id: echo-java
- name: echo-java
- description: echo from java
- entry: echo-java
- language: coursier
diff --git a/testing/resources/dart_repo/.pre-commit-hooks.yaml b/testing/resources/dart_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index e0dc5a2..0000000
--- a/testing/resources/dart_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-- id: hello-world-dart
- name: hello world dart
- entry: hello-world-dart
- language: dart
diff --git a/testing/resources/dart_repo/bin/hello-world-dart.dart b/testing/resources/dart_repo/bin/hello-world-dart.dart
deleted file mode 100644
index 5d8d6a6..0000000
--- a/testing/resources/dart_repo/bin/hello-world-dart.dart
+++ /dev/null
@@ -1,6 +0,0 @@
-import 'package:ansicolor/ansicolor.dart';
-
-void main() {
- AnsiPen pen = new AnsiPen()..red();
- print("hello hello " + pen("world"));
-}
diff --git a/testing/resources/dart_repo/pubspec.yaml b/testing/resources/dart_repo/pubspec.yaml
deleted file mode 100644
index bc719d0..0000000
--- a/testing/resources/dart_repo/pubspec.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-environment:
- sdk: '>=2.10.0 <3.0.0'
-
-name: hello_world_dart
-
-executables:
- hello-world-dart:
-
-dependencies:
- ansicolor: ^2.0.1
diff --git a/testing/resources/golang_hooks_repo/golang-hello-world/main.go b/testing/resources/golang_hooks_repo/golang-hello-world/main.go
index 1e3c591..1685743 100644
--- a/testing/resources/golang_hooks_repo/golang-hello-world/main.go
+++ b/testing/resources/golang_hooks_repo/golang-hello-world/main.go
@@ -3,7 +3,9 @@ package main
import (
"fmt"
+ "runtime"
"github.com/BurntSushi/toml"
+ "os"
)
type Config struct {
@@ -11,7 +13,11 @@ type Config struct {
}
func main() {
+ message := runtime.Version()
+ if len(os.Args) > 1 {
+ message = os.Args[1]
+ }
var conf Config
toml.Decode("What = 'world'\n", &conf)
- fmt.Printf("hello %v\n", conf.What)
+ fmt.Printf("hello %v from %s\n", conf.What, message)
}
diff --git a/testing/resources/lua_repo/.pre-commit-hooks.yaml b/testing/resources/lua_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index 767ef97..0000000
--- a/testing/resources/lua_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-- id: hello-world-lua
- name: hello world lua
- entry: hello-world-lua
- language: lua
diff --git a/testing/resources/lua_repo/bin/hello-world-lua b/testing/resources/lua_repo/bin/hello-world-lua
deleted file mode 100755
index 2a0e002..0000000
--- a/testing/resources/lua_repo/bin/hello-world-lua
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env lua
-
-print('hello world')
diff --git a/testing/resources/lua_repo/hello-dev-1.rockspec b/testing/resources/lua_repo/hello-dev-1.rockspec
deleted file mode 100644
index 82486e0..0000000
--- a/testing/resources/lua_repo/hello-dev-1.rockspec
+++ /dev/null
@@ -1,15 +0,0 @@
-package = "hello"
-version = "dev-1"
-
-source = {
- url = "git+ssh://git@github.com/pre-commit/pre-commit.git"
-}
-description = {}
-dependencies = {}
-build = {
- type = "builtin",
- modules = {},
- install = {
- bin = {"bin/hello-world-lua"}
- },
-}
diff --git a/testing/resources/perl_hooks_repo/.gitignore b/testing/resources/perl_hooks_repo/.gitignore
deleted file mode 100644
index 7af9940..0000000
--- a/testing/resources/perl_hooks_repo/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-/MYMETA.json
-/MYMETA.yml
-/Makefile
-/PreCommitHello-*.tar.*
-/PreCommitHello-*/
-/blib/
-/pm_to_blib
diff --git a/testing/resources/perl_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/perl_hooks_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index 11e6f6c..0000000
--- a/testing/resources/perl_hooks_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-- id: perl-hook
- name: perl example hook
- entry: pre-commit-perl-hello
- language: perl
- files: ''
diff --git a/testing/resources/perl_hooks_repo/MANIFEST b/testing/resources/perl_hooks_repo/MANIFEST
deleted file mode 100644
index 4a20084..0000000
--- a/testing/resources/perl_hooks_repo/MANIFEST
+++ /dev/null
@@ -1,4 +0,0 @@
-MANIFEST
-Makefile.PL
-bin/pre-commit-perl-hello
-lib/PreCommitHello.pm
diff --git a/testing/resources/perl_hooks_repo/Makefile.PL b/testing/resources/perl_hooks_repo/Makefile.PL
deleted file mode 100644
index 6c70e10..0000000
--- a/testing/resources/perl_hooks_repo/Makefile.PL
+++ /dev/null
@@ -1,10 +0,0 @@
-use strict;
-use warnings;
-
-use ExtUtils::MakeMaker;
-
-WriteMakefile(
- NAME => "PreCommitHello",
- VERSION_FROM => "lib/PreCommitHello.pm",
- EXE_FILES => [qw(bin/pre-commit-perl-hello)],
-);
diff --git a/testing/resources/perl_hooks_repo/bin/pre-commit-perl-hello b/testing/resources/perl_hooks_repo/bin/pre-commit-perl-hello
deleted file mode 100755
index 9474009..0000000
--- a/testing/resources/perl_hooks_repo/bin/pre-commit-perl-hello
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use PreCommitHello;
-
-PreCommitHello::hello();
diff --git a/testing/resources/perl_hooks_repo/lib/PreCommitHello.pm b/testing/resources/perl_hooks_repo/lib/PreCommitHello.pm
deleted file mode 100644
index c76521c..0000000
--- a/testing/resources/perl_hooks_repo/lib/PreCommitHello.pm
+++ /dev/null
@@ -1,12 +0,0 @@
-package PreCommitHello;
-
-use strict;
-use warnings;
-
-our $VERSION = "0.1.0";
-
-sub hello {
- print "Hello from perl-commit Perl!\n";
-}
-
-1;
diff --git a/testing/resources/r_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/r_hooks_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index b3545d9..0000000
--- a/testing/resources/r_hooks_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,48 +0,0 @@
-# parsing file
-- id: parse-file-no-opts-no-args
- name: Say hi
- entry: Rscript parse-file-no-opts-no-args.R
- language: r
- types: [r]
-- id: parse-file-no-opts-args
- name: Say hi
- entry: Rscript parse-file-no-opts-args.R
- args: [--no-cache]
- language: r
- types: [r]
-## parsing expr
-- id: parse-expr-no-opts-no-args-1
- name: Say hi
- entry: Rscript -e '1+1'
- language: r
- types: [r]
-- id: parse-expr-args-in-entry-2
- name: Say hi
- entry: Rscript -e '1+1' -e '3' --no-cache3
- language: r
- types: [r]
-# real world
-- id: hello-world
- name: Say hi
- entry: Rscript hello-world.R
- args: [blibla]
- language: r
- types: [r]
-- id: hello-world-inline
- name: Say hi
- entry: |
- Rscript -e
- 'stopifnot(
- packageVersion("rprojroot") == "1.0",
- packageVersion("gli.clu") == "0.0.0.9000"
- )
- cat(commandArgs(trailingOnly = TRUE), "from R!\n", sep = ", ")
- '
- args: ['Hi-there']
- language: r
- types: [r]
-- id: additional-deps
- name: Check additional deps
- entry: Rscript additional-deps.R
- language: r
- types: [r]
diff --git a/testing/resources/r_hooks_repo/DESCRIPTION b/testing/resources/r_hooks_repo/DESCRIPTION
deleted file mode 100644
index 0e597a8..0000000
--- a/testing/resources/r_hooks_repo/DESCRIPTION
+++ /dev/null
@@ -1,19 +0,0 @@
-Package: gli.clu
-Title: What the Package Does (One Line, Title Case)
-Type: Package
-Version: 0.0.0.9000
-Authors@R:
- person(given = "First",
- family = "Last",
- role = c("aut", "cre"),
- email = "first.last@example.com",
- comment = c(ORCID = "YOUR-ORCID-ID"))
-Description: What the package does (one paragraph).
-License: `use_mit_license()`, `use_gpl3_license()` or friends to
- pick a license
-Encoding: UTF-8
-LazyData: true
-Roxygen: list(markdown = TRUE)
-RoxygenNote: 7.1.1
-Imports:
- rprojroot
diff --git a/testing/resources/r_hooks_repo/additional-deps.R b/testing/resources/r_hooks_repo/additional-deps.R
deleted file mode 100755
index bc14595..0000000
--- a/testing/resources/r_hooks_repo/additional-deps.R
+++ /dev/null
@@ -1,2 +0,0 @@
-suppressPackageStartupMessages(library("cachem"))
-cat("OK\n")
diff --git a/testing/resources/r_hooks_repo/hello-world.R b/testing/resources/r_hooks_repo/hello-world.R
deleted file mode 100755
index bf8d92f..0000000
--- a/testing/resources/r_hooks_repo/hello-world.R
+++ /dev/null
@@ -1,5 +0,0 @@
-stopifnot(
- packageVersion('rprojroot') == '1.0',
- packageVersion('gli.clu') == '0.0.0.9000'
-)
-cat("Hello, World, from R!\n")
diff --git a/testing/resources/r_hooks_repo/renv.lock b/testing/resources/r_hooks_repo/renv.lock
deleted file mode 100644
index d7d5fdc..0000000
--- a/testing/resources/r_hooks_repo/renv.lock
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "R": {
- "Version": "4.0.3",
- "Repositories": [
- {
- "Name": "CRAN",
- "URL": "https://cloud.r-project.org"
- }
- ]
- },
- "Packages": {
- "renv": {
- "Package": "renv",
- "Version": "0.12.5",
- "Source": "Repository",
- "Repository": "CRAN",
- "Hash": "5c0cdb37f063c58cdab3c7e9fbb8bd2c"
- },
- "rprojroot": {
- "Package": "rprojroot",
- "Version": "1.0",
- "Source": "Repository",
- "Repository": "CRAN",
- "Hash": "86704667fe0860e4fec35afdfec137f3"
- }
- }
-}
diff --git a/testing/resources/r_hooks_repo/renv/LICENSE b/testing/resources/r_hooks_repo/renv/LICENSE
deleted file mode 100644
index 253c5d1..0000000
--- a/testing/resources/r_hooks_repo/renv/LICENSE
+++ /dev/null
@@ -1,7 +0,0 @@
-Copyright 2021 RStudio, PBC
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/testing/resources/r_hooks_repo/renv/activate.R b/testing/resources/r_hooks_repo/renv/activate.R
deleted file mode 100644
index d8d092c..0000000
--- a/testing/resources/r_hooks_repo/renv/activate.R
+++ /dev/null
@@ -1,440 +0,0 @@
-
-local({
-
- # the requested version of renv
- version <- "0.12.5"
-
- # the project directory
- project <- getwd()
-
- # avoid recursion
- if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA)))
- return(invisible(TRUE))
-
- # signal that we're loading renv during R startup
- Sys.setenv("RENV_R_INITIALIZING" = "true")
- on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE)
-
- # signal that we've consented to use renv
- options(renv.consent = TRUE)
-
- # load the 'utils' package eagerly -- this ensures that renv shims, which
- # mask 'utils' packages, will come first on the search path
- library(utils, lib.loc = .Library)
-
- # check to see if renv has already been loaded
- if ("renv" %in% loadedNamespaces()) {
-
- # if renv has already been loaded, and it's the requested version of renv,
- # nothing to do
- spec <- .getNamespaceInfo(.getNamespace("renv"), "spec")
- if (identical(spec[["version"]], version))
- return(invisible(TRUE))
-
- # otherwise, unload and attempt to load the correct version of renv
- unloadNamespace("renv")
-
- }
-
- # load bootstrap tools
- bootstrap <- function(version, library) {
-
- # attempt to download renv
- tarball <- tryCatch(renv_bootstrap_download(version), error = identity)
- if (inherits(tarball, "error"))
- stop("failed to download renv ", version)
-
- # now attempt to install
- status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity)
- if (inherits(status, "error"))
- stop("failed to install renv ", version)
-
- }
-
- renv_bootstrap_tests_running <- function() {
- getOption("renv.tests.running", default = FALSE)
- }
-
- renv_bootstrap_repos <- function() {
-
- # check for repos override
- repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA)
- if (!is.na(repos))
- return(repos)
-
- # if we're testing, re-use the test repositories
- if (renv_bootstrap_tests_running())
- return(getOption("renv.tests.repos"))
-
- # retrieve current repos
- repos <- getOption("repos")
-
- # ensure @CRAN@ entries are resolved
- repos[repos == "@CRAN@"] <- "https://cloud.r-project.org"
-
- # add in renv.bootstrap.repos if set
- default <- c(CRAN = "https://cloud.r-project.org")
- extra <- getOption("renv.bootstrap.repos", default = default)
- repos <- c(repos, extra)
-
- # remove duplicates that might've snuck in
- dupes <- duplicated(repos) | duplicated(names(repos))
- repos[!dupes]
-
- }
-
- renv_bootstrap_download <- function(version) {
-
- # if the renv version number has 4 components, assume it must
- # be retrieved via github
- nv <- numeric_version(version)
- components <- unclass(nv)[[1]]
-
- methods <- if (length(components) == 4L) {
- list(
- renv_bootstrap_download_github
- )
- } else {
- list(
- renv_bootstrap_download_cran_latest,
- renv_bootstrap_download_cran_archive
- )
- }
-
- for (method in methods) {
- path <- tryCatch(method(version), error = identity)
- if (is.character(path) && file.exists(path))
- return(path)
- }
-
- stop("failed to download renv ", version)
-
- }
-
- renv_bootstrap_download_impl <- function(url, destfile) {
-
- mode <- "wb"
-
- # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715
- fixup <-
- Sys.info()[["sysname"]] == "Windows" &&
- substring(url, 1L, 5L) == "file:"
-
- if (fixup)
- mode <- "w+b"
-
- utils::download.file(
- url = url,
- destfile = destfile,
- mode = mode,
- quiet = TRUE
- )
-
- }
-
- renv_bootstrap_download_cran_latest <- function(version) {
-
- repos <- renv_bootstrap_download_cran_latest_find(version)
-
- message("* Downloading renv ", version, " from CRAN ... ", appendLF = FALSE)
-
- info <- tryCatch(
- utils::download.packages(
- pkgs = "renv",
- repos = repos,
- destdir = tempdir(),
- quiet = TRUE
- ),
- condition = identity
- )
-
- if (inherits(info, "condition")) {
- message("FAILED")
- return(FALSE)
- }
-
- message("OK")
- info[1, 2]
-
- }
-
- renv_bootstrap_download_cran_latest_find <- function(version) {
-
- all <- renv_bootstrap_repos()
-
- for (repos in all) {
-
- db <- tryCatch(
- as.data.frame(
- x = utils::available.packages(repos = repos),
- stringsAsFactors = FALSE
- ),
- error = identity
- )
-
- if (inherits(db, "error"))
- next
-
- entry <- db[db$Package %in% "renv" & db$Version %in% version, ]
- if (nrow(entry) == 0)
- next
-
- return(repos)
-
- }
-
- fmt <- "renv %s is not available from your declared package repositories"
- stop(sprintf(fmt, version))
-
- }
-
- renv_bootstrap_download_cran_archive <- function(version) {
-
- name <- sprintf("renv_%s.tar.gz", version)
- repos <- renv_bootstrap_repos()
- urls <- file.path(repos, "src/contrib/Archive/renv", name)
- destfile <- file.path(tempdir(), name)
-
- message("* Downloading renv ", version, " from CRAN archive ... ", appendLF = FALSE)
-
- for (url in urls) {
-
- status <- tryCatch(
- renv_bootstrap_download_impl(url, destfile),
- condition = identity
- )
-
- if (identical(status, 0L)) {
- message("OK")
- return(destfile)
- }
-
- }
-
- message("FAILED")
- return(FALSE)
-
- }
-
- renv_bootstrap_download_github <- function(version) {
-
- enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE")
- if (!identical(enabled, "TRUE"))
- return(FALSE)
-
- # prepare download options
- pat <- Sys.getenv("GITHUB_PAT")
- if (nzchar(Sys.which("curl")) && nzchar(pat)) {
- fmt <- "--location --fail --header \"Authorization: token %s\""
- extra <- sprintf(fmt, pat)
- saved <- options("download.file.method", "download.file.extra")
- options(download.file.method = "curl", download.file.extra = extra)
- on.exit(do.call(base::options, saved), add = TRUE)
- } else if (nzchar(Sys.which("wget")) && nzchar(pat)) {
- fmt <- "--header=\"Authorization: token %s\""
- extra <- sprintf(fmt, pat)
- saved <- options("download.file.method", "download.file.extra")
- options(download.file.method = "wget", download.file.extra = extra)
- on.exit(do.call(base::options, saved), add = TRUE)
- }
-
- message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE)
-
- url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version)
- name <- sprintf("renv_%s.tar.gz", version)
- destfile <- file.path(tempdir(), name)
-
- status <- tryCatch(
- renv_bootstrap_download_impl(url, destfile),
- condition = identity
- )
-
- if (!identical(status, 0L)) {
- message("FAILED")
- return(FALSE)
- }
-
- message("OK")
- return(destfile)
-
- }
-
- renv_bootstrap_install <- function(version, tarball, library) {
-
- # attempt to install it into project library
- message("* Installing renv ", version, " ... ", appendLF = FALSE)
- dir.create(library, showWarnings = FALSE, recursive = TRUE)
-
- # invoke using system2 so we can capture and report output
- bin <- R.home("bin")
- exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R"
- r <- file.path(bin, exe)
- args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(library), shQuote(tarball))
- output <- system2(r, args, stdout = TRUE, stderr = TRUE)
- message("Done!")
-
- # check for successful install
- status <- attr(output, "status")
- if (is.numeric(status) && !identical(status, 0L)) {
- header <- "Error installing renv:"
- lines <- paste(rep.int("=", nchar(header)), collapse = "")
- text <- c(header, lines, output)
- writeLines(text, con = stderr())
- }
-
- status
-
- }
-
- renv_bootstrap_prefix <- function() {
-
- # construct version prefix
- version <- paste(R.version$major, R.version$minor, sep = ".")
- prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-")
-
- # include SVN revision for development versions of R
- # (to avoid sharing platform-specific artefacts with released versions of R)
- devel <-
- identical(R.version[["status"]], "Under development (unstable)") ||
- identical(R.version[["nickname"]], "Unsuffered Consequences")
-
- if (devel)
- prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r")
-
- # build list of path components
- components <- c(prefix, R.version$platform)
-
- # include prefix if provided by user
- prefix <- Sys.getenv("RENV_PATHS_PREFIX")
- if (nzchar(prefix))
- components <- c(prefix, components)
-
- # build prefix
- paste(components, collapse = "/")
-
- }
-
- renv_bootstrap_library_root_name <- function(project) {
-
- # use project name as-is if requested
- asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE")
- if (asis)
- return(basename(project))
-
- # otherwise, disambiguate based on project's path
- id <- substring(renv_bootstrap_hash_text(project), 1L, 8L)
- paste(basename(project), id, sep = "-")
-
- }
-
- renv_bootstrap_library_root <- function(project) {
-
- path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA)
- if (!is.na(path))
- return(path)
-
- path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA)
- if (!is.na(path)) {
- name <- renv_bootstrap_library_root_name(project)
- return(file.path(path, name))
- }
-
- file.path(project, "renv/library")
-
- }
-
- renv_bootstrap_validate_version <- function(version) {
-
- loadedversion <- utils::packageDescription("renv", fields = "Version")
- if (version == loadedversion)
- return(TRUE)
-
- # assume four-component versions are from GitHub; three-component
- # versions are from CRAN
- components <- strsplit(loadedversion, "[.-]")[[1]]
- remote <- if (length(components) == 4L)
- paste("rstudio/renv", loadedversion, sep = "@")
- else
- paste("renv", loadedversion, sep = "@")
-
- fmt <- paste(
- "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.",
- "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.",
- "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.",
- sep = "\n"
- )
-
- msg <- sprintf(fmt, loadedversion, version, remote)
- warning(msg, call. = FALSE)
-
- FALSE
-
- }
-
- renv_bootstrap_hash_text <- function(text) {
-
- hashfile <- tempfile("renv-hash-")
- on.exit(unlink(hashfile), add = TRUE)
-
- writeLines(text, con = hashfile)
- tools::md5sum(hashfile)
-
- }
-
- renv_bootstrap_load <- function(project, libpath, version) {
-
- # try to load renv from the project library
- if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE))
- return(FALSE)
-
- # warn if the version of renv loaded does not match
- renv_bootstrap_validate_version(version)
-
- # load the project
- renv::load(project)
-
- TRUE
-
- }
-
- # construct path to library root
- root <- renv_bootstrap_library_root(project)
-
- # construct library prefix for platform
- prefix <- renv_bootstrap_prefix()
-
- # construct full libpath
- libpath <- file.path(root, prefix)
-
- # attempt to load
- if (renv_bootstrap_load(project, libpath, version))
- return(TRUE)
-
- # load failed; inform user we're about to bootstrap
- prefix <- paste("# Bootstrapping renv", version)
- postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "")
- header <- paste(prefix, postfix)
- message(header)
-
- # perform bootstrap
- bootstrap(version, libpath)
-
- # exit early if we're just testing bootstrap
- if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA)))
- return(TRUE)
-
- # try again to load
- if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) {
- message("* Successfully installed and loaded renv ", version, ".")
- return(renv::load())
- }
-
- # failed to download or load renv; warn the user
- msg <- c(
- "Failed to find an renv installation: the project will not be loaded.",
- "Use `renv::activate()` to re-initialize the project."
- )
-
- warning(paste(msg, collapse = "\n"), call. = FALSE)
-
-})
diff --git a/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml
index 364d47d..c97939a 100644
--- a/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml
+++ b/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml
@@ -2,5 +2,5 @@
name: Ruby Hook
entry: ruby_hook
language: ruby
- language_version: 3.1.0
+ language_version: 3.2.0
files: \.rb$
diff --git a/testing/resources/swift_hooks_repo/.gitignore b/testing/resources/swift_hooks_repo/.gitignore
deleted file mode 100644
index 02c0875..0000000
--- a/testing/resources/swift_hooks_repo/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-.DS_Store
-/.build
-/Packages
-/*.xcodeproj
diff --git a/testing/resources/swift_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/swift_hooks_repo/.pre-commit-hooks.yaml
deleted file mode 100644
index c08df87..0000000
--- a/testing/resources/swift_hooks_repo/.pre-commit-hooks.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-- id: swift-hooks-repo
- name: Swift hooks repo example
- description: Runs the hello world app generated by swift package init --type executable (binary called swift_hooks_repo here)
- entry: swift_hooks_repo
- language: swift
- files: \.(swift)$
diff --git a/testing/resources/swift_hooks_repo/Package.swift b/testing/resources/swift_hooks_repo/Package.swift
deleted file mode 100644
index 04976d3..0000000
--- a/testing/resources/swift_hooks_repo/Package.swift
+++ /dev/null
@@ -1,7 +0,0 @@
-// swift-tools-version:5.0
-import PackageDescription
-
-let package = Package(
- name: "swift_hooks_repo",
- targets: [.target(name: "swift_hooks_repo")]
-)
diff --git a/testing/resources/swift_hooks_repo/Sources/swift_hooks_repo/main.swift b/testing/resources/swift_hooks_repo/Sources/swift_hooks_repo/main.swift
deleted file mode 100644
index f7cf60e..0000000
--- a/testing/resources/swift_hooks_repo/Sources/swift_hooks_repo/main.swift
+++ /dev/null
@@ -1 +0,0 @@
-print("Hello, world!")
diff --git a/testing/util.py b/testing/util.py
index e807f04..b6c3804 100644
--- a/testing/util.py
+++ b/testing/util.py
@@ -6,7 +6,6 @@ import subprocess
import pytest
-from pre_commit import parse_shebang
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
@@ -42,22 +41,10 @@ def cmd_output_mocked_pre_commit_home(
return ret, out.replace('\r\n', '\n'), None
-skipif_cant_run_coursier = pytest.mark.skipif(
- os.name == 'nt' or parse_shebang.find_executable('cs') is None,
- reason="coursier isn't installed or can't be found",
-)
skipif_cant_run_docker = pytest.mark.skipif(
os.name == 'nt' or not docker_is_running(),
reason="Docker isn't running or can't be accessed",
)
-skipif_cant_run_lua = pytest.mark.skipif(
- os.name == 'nt',
- reason="lua isn't installed or can't be found",
-)
-skipif_cant_run_swift = pytest.mark.skipif(
- parse_shebang.find_executable('swift') is None,
- reason="swift isn't installed or can't be found",
-)
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')