aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-08-06 23:32:13 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-08-12 12:33:41 +0300
commit768727f37afa6fbb5082833a4c14c8134ec42122 (patch)
tree8c7b3d85f9735d8585781a45f9e61b15fdaa3530 /tests
parent4c61819dedbc3547bf3f352809ecfb6a95ab8753 (diff)
Add implementation
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/build/.gitignore3
-rw-r--r--tests/build/bootstrap.build8
-rw-r--r--tests/build/root.build12
-rw-r--r--tests/buildfile24
-rw-r--r--tests/git-common.testscript17
-rw-r--r--tests/git-pre-commit-common.testscript13
-rw-r--r--tests/git-pre-commit-copyright-check.testscript25
-rw-r--r--tests/git-pre-commit-version-check.testscript263
-rw-r--r--tests/git-pre-commit.testscript42
10 files changed, 409 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..35ec43f
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,2 @@
+test/
+test-*/
diff --git a/tests/build/.gitignore b/tests/build/.gitignore
new file mode 100644
index 0000000..4a730a3
--- /dev/null
+++ b/tests/build/.gitignore
@@ -0,0 +1,3 @@
+config.build
+root/
+bootstrap/
diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build
new file mode 100644
index 0000000..c9187a6
--- /dev/null
+++ b/tests/build/bootstrap.build
@@ -0,0 +1,8 @@
+# file : tests/build/bootstrap.build
+# license : MIT; see accompanying LICENSE file
+
+project = # Unnamed subproject.
+
+using config
+using dist
+using test
diff --git a/tests/build/root.build b/tests/build/root.build
new file mode 100644
index 0000000..90257ce
--- /dev/null
+++ b/tests/build/root.build
@@ -0,0 +1,12 @@
+# file : tests/build/root.build
+# license : MIT; see accompanying LICENSE file
+
+# Setup the targets that we are testing.
+#
+import git_pre_commit = bdep-util%exe{bdep-git-pre-commit}
+
+import git_pre_commit_version_check = \
+ bdep-util%exe{bdep-git-pre-commit-version-check}
+
+import git_pre_commit_copyright_check = \
+ bdep-util%exe{bdep-git-pre-commit-copyright-check}
diff --git a/tests/buildfile b/tests/buildfile
new file mode 100644
index 0000000..fb17c95
--- /dev/null
+++ b/tests/buildfile
@@ -0,0 +1,24 @@
+# file : tests/buildfile
+# license : MIT; see accompanying LICENSE file
+
+define common: file
+common{*}: extension = testscript
+
+commons = git-common git-pre-commit-common
+
+./: testscript{* -{$commons}} common{$commons}
+
+testscript{git-pre-commit}@./: $git_pre_commit
+{
+ test = $git_pre_commit
+}
+
+testscript{git-pre-commit-version-check}@./: $git_pre_commit_version_check
+{
+ test = $git_pre_commit_version_check
+}
+
+testscript{git-pre-commit-copyright-check}@./: $git_pre_commit_copyright_check
+{
+ test = $git_pre_commit_copyright_check
+}
diff --git a/tests/git-common.testscript b/tests/git-common.testscript
new file mode 100644
index 0000000..aa90f3d
--- /dev/null
+++ b/tests/git-common.testscript
@@ -0,0 +1,17 @@
+# file : tests/git-common.testscript
+# license : MIT; see accompanying LICENSE file
+
+# Set commonly-used variables and create an empty git repository that will be
+# copied by subsequent tests and scope setup commands.
+#
+g = git >! 2>&1
+gp = $g -C prj
+ga = $gp add
+gr = $gp rm
+
++$g init prj &prj/***
+
++$gp config user.name 'Test Script'
++$gp config user.email 'testscript@example.com'
+
+clone_prj = cp --no-cleanup -r ../prj ./ &prj/***
diff --git a/tests/git-pre-commit-common.testscript b/tests/git-pre-commit-common.testscript
new file mode 100644
index 0000000..ae8b9d4
--- /dev/null
+++ b/tests/git-pre-commit-common.testscript
@@ -0,0 +1,13 @@
+# file : tests/git-pre-commit-common.testscript
+# license : MIT; see accompanying LICENSE file
+
+# Set commonly-used variables and configure git to call the hook being tested.
+# Assume that git-common.testscript is already included.
+#
+gc = $gp commit -a --allow-empty-message -m ''
+
+hooks_dir=$~/hooks
++mkdir $hooks_dir
++$gp config core.hooksPath $hooks_dir
+
++ln -s $0 $hooks_dir/pre-commit
diff --git a/tests/git-pre-commit-copyright-check.testscript b/tests/git-pre-commit-copyright-check.testscript
new file mode 100644
index 0000000..f8e51f5
--- /dev/null
+++ b/tests/git-pre-commit-copyright-check.testscript
@@ -0,0 +1,25 @@
+# file : tests/git-pre-commit-copyright-check.testscript
+# license : MIT; see accompanying LICENSE file
+
+.include git-common.testscript git-pre-commit-common.testscript
+
+: basic
+:
+{
+ $clone_prj;
+
+ cat <<EOI >=prj/LICENSE;
+ Copyright (c) 2014-2019 the build2 authors.
+ EOI
+ $ga .;
+
+ $gc 2>>EOE;
+ WARNING: last copyright year in 'LICENSE' is 2019
+ EOE
+
+ date +"%Y" | set year;
+ cat <<"EOI" >=prj/LICENSE;
+ Copyright (c) 2014-$year the build2 authors.
+ EOI
+ $gc
+}
diff --git a/tests/git-pre-commit-version-check.testscript b/tests/git-pre-commit-version-check.testscript
new file mode 100644
index 0000000..28e4efc
--- /dev/null
+++ b/tests/git-pre-commit-version-check.testscript
@@ -0,0 +1,263 @@
+# file : tests/git-pre-commit-version-check.testscript
+# license : MIT; see accompanying LICENSE file
+
+.include git-common.testscript git-pre-commit-common.testscript
+
++bash --version >&2 2>! # For troubleshooting.
+
+: multi-package-project
+:
+{
+ $clone_prj;
+
+ touch prj/TODO;
+ $ga .;
+ $gc; # Initial commit.
+
+ echo '@@' >=prj/TODO;
+ $gc; # No committed packages.manifest.
+
+ cat <<EOI >=prj/packages.manifest;
+ : 1
+ location: libfoo/
+ :
+ location: libbar/
+ :
+ location: libbaz/
+ EOI
+ $ga .;
+
+ $gc 2>>EOE; # packages.manifest is staged.
+ warning: package manifest file libfoo/manifest does not exist
+ warning: package manifest file libbar/manifest does not exist
+ warning: package manifest file libbaz/manifest does not exist
+ EOE
+
+ echo '@@ todo' >=prj/TODO;
+
+ # packages.manifest is committed but there are no package manifests.
+ #
+ $gc 2>>EOE;
+ warning: package manifest file libfoo/manifest does not exist
+ warning: package manifest file libbar/manifest does not exist
+ warning: package manifest file libbaz/manifest does not exist
+ EOE
+
+ mkdir prj/libfoo prj/libbar prj/libbaz;
+ cat <<EOI >=prj/libfoo/manifest;
+ : 1
+ name: libfoo
+ version: 1.2.3-a.1.z
+ summary: Foo
+ EOI
+ cat <<EOI >=prj/libbar/manifest;
+ : 1
+ name: libbar
+ version: 1.2.3
+ summary: Bar
+ EOI
+ cat <<EOI >=prj/libbaz/manifest;
+ : 1
+ name: libbaz
+ version: 0+1
+ summary: Baz
+ EOI
+ $ga .;
+
+ $gc; # Same as above plus the package manifests are
+ # staged.
+
+ echo '@@ TODO' >=prj/TODO;
+
+ $gc; # Packages are committed but the staged change
+ # goes outside the package directories.
+
+ touch prj/libfoo/TODO prj/libbar/TODO prj/libbaz/TODO;
+ $ga libfoo/TODO;
+
+ $gc; # Package with an open version (snapshot) is
+ # changed.
+
+ $ga libbar/TODO;
+
+ $gc 2>>EOE != 0; # Package with a final version is changed.
+ error: changing released package libbar 1.2.3 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ sed -i -e 's/^(version:).+$/\1 1.2.4-a.1.z/' prj/libbar/manifest;
+
+ $gc; # Open package development circle.
+
+ echo '@@' >=prj/libbar/TODO;
+
+ $gc; # Development cycle is open.
+
+ $ga libbaz/TODO;
+
+ $gc 2>>EOE != 0; # Package with a stub version is changed.
+ error: changing released package libbaz 0+1 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ sed -i -e 's/^(version:).+$/\1 0+2/' prj/libbaz/manifest;
+
+ $gc; # Release the stub package revision.
+
+ sed -i -e 's/^(version:).+$/\1 1.2.3/' prj/libfoo/manifest;
+
+ $gc; # Release new version.
+
+ echo '@@ todo' >=prj/libfoo/TODO;
+
+ $gc 2>>EOE != 0; # Package with a final version is changed.
+ error: changing released package libfoo 1.2.3 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ $gr libfoo/manifest &!prj/libfoo/manifest;
+
+ $gc 2>>EOE; # The manifest removal is staged (not a package now).
+ warning: package manifest file libfoo/manifest does not exist
+ EOE
+
+ sed -i -e 's/^(version:).+$/\1 1.2.4/' prj/libbar/manifest;
+
+ $gc 2>>EOE; # Release new version.
+ warning: package manifest file libfoo/manifest does not exist
+ EOE
+
+ echo '@@ todo' >=prj/libbar/TODO;
+
+ $gc 2>>EOE != 0; # Package with a final version is changed.
+ warning: package manifest file libfoo/manifest does not exist
+ error: changing released package libbar 1.2.4 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ cat <<EOI >=prj/packages.manifest;
+ : 1
+ location: libbaz/
+ EOI
+
+ $gc; # The package removal from packages.manifest is
+ # staged, so it's not a package anymore.
+
+ cat <<EOI >=prj/packages.manifest;
+ : 1
+ location: lib/baz/
+ EOI
+ mkdir prj/lib;
+ mv prj/libbaz prj/lib/baz;
+ $ga .;
+
+ $gc 2>>EOE != 0; # Package with a stub version is moved.
+ error: moving released package libbaz 0+2
+ info: use --no-verify git option to suppress
+ EOE
+
+ sed -i -e 's/^(version:).+$/\1 0+3/' prj/lib/baz/manifest;
+
+ $gc # Release the stub package revision.
+}
+
+: single-package-project
+:
+{
+ $clone_prj;
+
+ cat <<EOI >=prj/manifest;
+ : 1
+ name: foo
+ version: 1.2.3
+ summary: Foo
+ EOI
+ touch prj/TODO;
+ $ga .;
+
+ $gc 2>|; # No committed manifest.
+
+ echo '@@' >=prj/TODO;
+
+ $gc 2>>EOE != 0; # Package with a final version is changed.
+ error: changing released package foo 1.2.3 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ sed -i -e 's/^(version:).+$/\1 1.2.4-a.1.123/' prj/manifest;
+
+ $gc; # Open package development circle.
+
+ echo '@@ todo' >=prj/TODO;
+
+ $gc; # Development cycle is open.
+
+ sed -i -e 's/^(version:).+$/\1 1.2.4/' prj/manifest;
+
+ $gc; # Release new version.
+
+ echo '@@ TODO' >=prj/TODO;
+
+ $gc 2>>EOE != 0; # Package with a final version is changed.
+ error: changing released package foo 1.2.4 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+
+ $gr manifest &!prj/manifest;
+
+ # Make sure there is no warning.
+ #
+ $gc 2>:'' # The manifest removal is staged, so it's not a
+ # package anymore.
+}
+
+: warnings
+:
+{
+ +$clone_prj
+
+ : no-name
+ :
+ {
+ $clone_prj;
+
+ cat <<EOI >=prj/manifest;
+ : 1
+ summary: Foo
+ EOI
+ $ga .;
+
+ $gc 2>"warning: package name is missing in ./manifest"
+ }
+
+ : no-version
+ :
+ {
+ $clone_prj;
+
+ cat <<EOI >=prj/manifest;
+ : 1
+ name: libfoo
+ summary: Foo
+ EOI
+ $ga .;
+
+ $gc 2>"warning: package version is missing in ./manifest"
+ }
+
+ : invalid-version
+ :
+ {
+ $clone_prj;
+
+ cat <<EOI >=prj/manifest;
+ : 1
+ name: libfoo
+ version: abc
+ summary: Foo
+ EOI
+ $ga .;
+
+ $gc 2>"warning: package version 'abc' in ./manifest is not a valid standard version"
+ }
+}
diff --git a/tests/git-pre-commit.testscript b/tests/git-pre-commit.testscript
new file mode 100644
index 0000000..8b8f140
--- /dev/null
+++ b/tests/git-pre-commit.testscript
@@ -0,0 +1,42 @@
+# file : tests/git-pre-commit.testscript
+# license : MIT; see accompanying LICENSE file
+
+.include git-common.testscript git-pre-commit-common.testscript
+
+: version-check
+:
+{
+ $clone_prj;
+
+ cat <<EOI >=prj/manifest;
+ : 1
+ name: foo
+ version: 1.2.3
+ summary: Foo
+ EOI
+ touch prj/TODO;
+ $ga .;
+ $gc; # No committed manifest.
+
+ echo '@@' >=prj/TODO;
+
+ $gc 2>>EOE != 0 # Package with a final version is changed.
+ error: changing released package foo 1.2.3 without version increment
+ info: use --no-verify git option to suppress
+ EOE
+}
+
+: copyright-check
+:
+{
+ $clone_prj;
+
+ cat <<EOI >=prj/LICENSE;
+ Copyright (c) 2014-2019 the build2 authors.
+ EOI
+ $ga .;
+
+ $gc 2>>EOE
+ WARNING: last copyright year in 'LICENSE' is 2019
+ EOE
+}