[PATCH] tests: Smarten up git repository testing framework.

  • Done
  • quality assurance status badge
Details
3 participants
  • Attila Lendvai
  • Leo Famulari
  • Mathieu Othacehe
Owner
unassigned
Submitted by
Attila Lendvai
Severity
normal
A
A
Attila Lendvai wrote on 21 Dec 2021 23:32
(address . guix-patches@gnu.org)(name . Attila Lendvai)(address . attila@lendvai.name)
20211221223244.32542-1-attila@lendvai.name
These features will be used in upcoming tests.

* guix/tests/git.scm (with-git-repository): New macro that can be used
multiple times, inside a with-temporary-git-repository.
(populate-git-repository): Extend the DSL with (add "some-noise"), (reset
"[commit hash]"), (checkout "branch" orphan).
* guix/tests/gnupg.scm (key-fingerprint-vector): New procedure.
---
guix/tests/git.scm | 23 +++++++++++++++++++++--
guix/tests/gnupg.scm | 8 ++++++--
2 files changed, 27 insertions(+), 4 deletions(-)

Toggle diff (95 lines)
diff --git a/guix/tests/git.scm b/guix/tests/git.scm
index 69960284d9..76f5a8b937 100644
--- a/guix/tests/git.scm
+++ b/guix/tests/git.scm
@@ -26,6 +26,7 @@ (define-module (guix tests git)
#:use-module (ice-9 control)
#:export (git-command
with-temporary-git-repository
+ with-git-repository
find-commit))
(define git-command
@@ -59,8 +60,9 @@ (define (git command . args)
(apply invoke (git-command) "-C" directory
command args)))))
- (mkdir-p directory)
- (git "init")
+ (unless (directory-exists? (string-append directory "/.git"))
+ (mkdir-p directory)
+ (git "init"))
(let loop ((directives directives))
(match directives
@@ -78,6 +80,9 @@ (define (git command . args)
port)))
(git "add" file)
(loop rest)))
+ ((('add file-name-and-content) rest ...)
+ (loop (cons `(add ,file-name-and-content ,file-name-and-content)
+ rest)))
((('remove file) rest ...)
(git "rm" "-f" file)
(loop rest))
@@ -99,12 +104,18 @@ (define (git command . args)
((('checkout branch) rest ...)
(git "checkout" branch)
(loop rest))
+ ((('checkout branch 'orphan) rest ...)
+ (git "checkout" "--orphan" branch)
+ (loop rest))
((('merge branch message) rest ...)
(git "merge" branch "-m" message)
(loop rest))
((('merge branch message ('signer fingerprint)) rest ...)
(git "merge" branch "-m" message
(string-append "--gpg-sign=" fingerprint))
+ (loop rest))
+ ((('reset to) rest ...)
+ (git "reset" "--hard" to)
(loop rest)))))
(define (call-with-temporary-git-repository directives proc)
@@ -121,6 +132,14 @@ (define-syntax-rule (with-temporary-git-repository directory
(lambda (directory)
exp ...)))
+(define-syntax-rule (with-git-repository directory
+ directives exp ...)
+ "Evaluate EXP in a context where DIRECTORY is (further) populated as
+per DIRECTIVES."
+ (begin
+ (populate-git-repository directory directives)
+ exp ...))
+
(define (find-commit repository message)
"Return the commit in REPOSITORY whose message includes MESSAGE, a string."
(let/ec return
diff --git a/guix/tests/gnupg.scm b/guix/tests/gnupg.scm
index 943fd66077..09f02a2b67 100644
--- a/guix/tests/gnupg.scm
+++ b/guix/tests/gnupg.scm
@@ -35,6 +35,7 @@ (define-module (guix tests gnupg)
read-openpgp-packet
key-fingerprint
+ key-fingerprint-vector
key-id))
(define gpg-command
@@ -82,7 +83,10 @@ (define (read-openpgp-packet file)
(open-bytevector-input-port
(call-with-input-file file read-radix-64))))
+(define key-fingerprint-vector
+ (compose openpgp-public-key-fingerprint
+ read-openpgp-packet))
+
(define key-fingerprint
(compose openpgp-format-fingerprint
- openpgp-public-key-fingerprint
- read-openpgp-packet))
+ key-fingerprint-vector))
--
2.34.0
A
A
Attila Lendvai wrote on 22 Dec 2021 11:28
[PATCH v2 1/2] tests: Smarten up git repository testing framework.
(address . 52722@debbugs.gnu.org)(name . Attila Lendvai)(address . attila@lendvai.name)
20211222102855.21822-1-attila@lendvai.name
* guix/tests/git.scm (with-git-repository): New macro, exported. It can be used
repeatedly inside a WITH-TEMPORARY-GIT-REPOSITORY.
(populate-git-repository): Extend the DSL with (ADD "some-noise"), (RESET
"[commit hash]"), (CHECKOUT "branch" ORPHAN).
---

as requested on IRC, resending it as two commits.

guix/tests/git.scm | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

Toggle diff (70 lines)
diff --git a/guix/tests/git.scm b/guix/tests/git.scm
index 69960284d9..76f5a8b937 100644
--- a/guix/tests/git.scm
+++ b/guix/tests/git.scm
@@ -26,6 +26,7 @@ (define-module (guix tests git)
#:use-module (ice-9 control)
#:export (git-command
with-temporary-git-repository
+ with-git-repository
find-commit))
(define git-command
@@ -59,8 +60,9 @@ (define (git command . args)
(apply invoke (git-command) "-C" directory
command args)))))
- (mkdir-p directory)
- (git "init")
+ (unless (directory-exists? (string-append directory "/.git"))
+ (mkdir-p directory)
+ (git "init"))
(let loop ((directives directives))
(match directives
@@ -78,6 +80,9 @@ (define (git command . args)
port)))
(git "add" file)
(loop rest)))
+ ((('add file-name-and-content) rest ...)
+ (loop (cons `(add ,file-name-and-content ,file-name-and-content)
+ rest)))
((('remove file) rest ...)
(git "rm" "-f" file)
(loop rest))
@@ -99,12 +104,18 @@ (define (git command . args)
((('checkout branch) rest ...)
(git "checkout" branch)
(loop rest))
+ ((('checkout branch 'orphan) rest ...)
+ (git "checkout" "--orphan" branch)
+ (loop rest))
((('merge branch message) rest ...)
(git "merge" branch "-m" message)
(loop rest))
((('merge branch message ('signer fingerprint)) rest ...)
(git "merge" branch "-m" message
(string-append "--gpg-sign=" fingerprint))
+ (loop rest))
+ ((('reset to) rest ...)
+ (git "reset" "--hard" to)
(loop rest)))))
(define (call-with-temporary-git-repository directives proc)
@@ -121,6 +132,14 @@ (define-syntax-rule (with-temporary-git-repository directory
(lambda (directory)
exp ...)))
+(define-syntax-rule (with-git-repository directory
+ directives exp ...)
+ "Evaluate EXP in a context where DIRECTORY is (further) populated as
+per DIRECTIVES."
+ (begin
+ (populate-git-repository directory directives)
+ exp ...))
+
(define (find-commit repository message)
"Return the commit in REPOSITORY whose message includes MESSAGE, a string."
(let/ec return
--
2.34.0
A
A
Attila Lendvai wrote on 22 Dec 2021 11:28
[PATCH v2 2/2] tests: gnupg: Factor out and export KEY-FINGERPRINT-VECTOR.
(address . 52722@debbugs.gnu.org)(name . Attila Lendvai)(address . attila@lendvai.name)
20211222102855.21822-2-attila@lendvai.name
* guix/tests/gnupg.scm (key-fingerprint-vector): New procedure. Export it.
(key-fingerprint): Use it.
---
guix/tests/gnupg.scm | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Toggle diff (27 lines)
diff --git a/guix/tests/gnupg.scm b/guix/tests/gnupg.scm
index 943fd66077..09f02a2b67 100644
--- a/guix/tests/gnupg.scm
+++ b/guix/tests/gnupg.scm
@@ -35,6 +35,7 @@ (define-module (guix tests gnupg)
read-openpgp-packet
key-fingerprint
+ key-fingerprint-vector
key-id))
(define gpg-command
@@ -82,7 +83,10 @@ (define (read-openpgp-packet file)
(open-bytevector-input-port
(call-with-input-file file read-radix-64))))
+(define key-fingerprint-vector
+ (compose openpgp-public-key-fingerprint
+ read-openpgp-packet))
+
(define key-fingerprint
(compose openpgp-format-fingerprint
- openpgp-public-key-fingerprint
- read-openpgp-packet))
+ key-fingerprint-vector))
--
2.34.0
M
M
Mathieu Othacehe wrote on 23 Dec 2021 17:41
Re: bug#52722: [PATCH] tests: Smarten up git repository testing framework.
(name . Attila Lendvai)(address . attila@lendvai.name)(address . 52722-done@debbugs.gnu.org)
87bl17clza.fsf_-_@gnu.org
Toggle quote (3 lines)
> * guix/tests/gnupg.scm (key-fingerprint-vector): New procedure. Export it.
> (key-fingerprint): Use it.

Pushed, thanks!

Mathieu
Closed
L
L
Leo Famulari wrote on 23 Dec 2021 18:40
Re: [bug#52722] [PATCH v2 1/2] tests: Smarten up git repository testing framework.
(name . Attila Lendvai)(address . attila@lendvai.name)(address . 52722@debbugs.gnu.org)
YcS0lk+anvAv5Z5F@jasmine.lan
On Wed, Dec 22, 2021 at 11:28:55AM +0100, Attila Lendvai wrote:
Toggle quote (5 lines)
> * guix/tests/git.scm (with-git-repository): New macro, exported. It can be used
> repeatedly inside a WITH-TEMPORARY-GIT-REPOSITORY.
> (populate-git-repository): Extend the DSL with (ADD "some-noise"), (RESET
> "[commit hash]"), (CHECKOUT "branch" ORPHAN).

This commit introduced some ambiguity while importing the RESET
procedure:

WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)

We need to make sure that the correct reset is imported here. Can you
take a look and make any adjustments, if necessary?
A
A
Attila Lendvai wrote on 23 Dec 2021 22:00
(name . Leo Famulari)(address . leo@famulari.name)(address . 52722@debbugs.gnu.org)
-1PF3BR6MNJyF-1HwyBikuI03CzRN92E6OE0b-MNHyXeG3NUkaHGrKg_55ORoS6-_0FBO3uZgSQNQZH1o0xnl9eWpQ3gmc2joO5VgTSNSuw=@lendvai.name
Toggle quote (5 lines)
> WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)
>
> We need to make sure that the correct reset is imported here. Can you
> take a look and make any adjustments, if necessary?

i wonder why that is only a warning and not a full error.

but anyway, the fix is to only import let/ec. please change the
relevant line to:

#:use-module ((ice-9 control) #:select (let/ec))

can you please commit this without going through the full
patch-submission cycle?

- attila
L
L
Leo Famulari wrote on 24 Dec 2021 00:49
(name . Attila Lendvai)(address . attila@lendvai.name)(address . 52722@debbugs.gnu.org)
YcULEhs9bZxh4jDk@jasmine.lan
On Thu, Dec 23, 2021 at 09:00:10PM +0000, Attila Lendvai wrote:
Toggle quote (15 lines)
> > WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)
> >
> > We need to make sure that the correct reset is imported here. Can you
> > take a look and make any adjustments, if necessary?
>
> i wonder why that is only a warning and not a full error.
>
> but anyway, the fix is to only import let/ec. please change the
> relevant line to:
>
> #:use-module ((ice-9 control) #:select (let/ec))
>
> can you please commit this without going through the full
> patch-submission cycle?

Sure, done as commit ba744faeb104a1132d9f6ed04fc296b23bc09334
?