From 64fa1ca7da69a66bd3c1a30c883654272fc78de7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 16 Apr 2014 18:47:01 +0100 Subject: Add test for simple copyright statement --- copyright-statement-lint | 9 +++++++++ yarns/010-tests.yarn | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/copyright-statement-lint b/copyright-statement-lint index db61ded..5ca8033 100755 --- a/copyright-statement-lint +++ b/copyright-statement-lint @@ -32,6 +32,12 @@ copyright_pattern = re.compile( class CopyrightStatementLint(cliapp.Application): + def add_settings(self): + self.settings.integer( + ['debug-commit-year'], + 'pretend the commit is from YEAR', + metavar='YEAR') + def setup(self): self.errors = False @@ -61,6 +67,9 @@ class CopyrightStatementLint(cliapp.Application): self.statements.append(m) def get_commit_year(self, filename): + if self.settings['debug-commit-year']: + return self.settings['debug-commit-year'] + output = cliapp.runcmd(['git', 'log', '-n1', filename]) for line in output.splitlines(): diff --git a/yarns/010-tests.yarn b/yarns/010-tests.yarn index 72020c0..65adcfc 100644 --- a/yarns/010-tests.yarn +++ b/yarns/010-tests.yarn @@ -16,7 +16,8 @@ the output of the tool is as expected. Scenarios ========= -Simple case: no copyright file. +No copyright file +----------------- SCENARIO no copyright file GIVEN an empty file FOOBAR @@ -24,6 +25,26 @@ Simple case: no copyright file. THEN exit code is 1 AND stderr contains "FOOBAR.*no copyright statement" +Simple copyright statement +-------------------------- + + SCENARIO simple copyright statement + GIVEN a file FOOBAR containing "Copyright 2014 Foo Bar" + + GIVEN commit year is 2013 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2013 not contained" + + GIVEN commit year is 2014 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2015 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2015 not contained" + Implementations =============== @@ -36,6 +57,16 @@ in `$DATADIR` using names given by the user. IMPLEMENTS GIVEN an empty file (\S+) touch "$DATADIR/$MATCH_1" + IMPLEMENTS GIVEN a file (\S+) containing "(.*)" + printf '%s\n' "$MATCH_2" > "$DATADIR/$MATCH_1" + +Pretending what the commit year is +---------------------------------- + + IMPLEMENTS GIVEN commit year is (\d+) + printf '[config]\ndebug-commit-year = %s\n' "$MATCH_1" \ + > "$DATADIR/test.conf" + Running and checking the results of `copyright-statement-lint` -------------------------------------------------------------- @@ -48,6 +79,7 @@ tool fails. # code. Don't want to turn set -e off, so we capture other errors. if "$SRCDIR/copyright-statement-lint" \ --no-default-config "$DATADIR/$MATCH_1" \ + --config "$DATADIR/test.conf" \ > "$DATADIR/stdout" \ 2> "$DATADIR/stderr" then @@ -67,4 +99,5 @@ every scenario is expected to check the exit code. Check stdout/stderr. IMPLEMENTS THEN (\S+) contains "(.*)" + cat "$DATADIR/$MATCH_1" grep "$MATCH_2" "$DATADIR/$MATCH_1" -- cgit v1.2.1 From fefed29ece0719acefb4bc01753ec1f4349f96a9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 16 Apr 2014 18:49:36 +0100 Subject: Add test suite for itemised copyright years --- yarns/010-tests.yarn | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/yarns/010-tests.yarn b/yarns/010-tests.yarn index 65adcfc..ec71561 100644 --- a/yarns/010-tests.yarn +++ b/yarns/010-tests.yarn @@ -45,6 +45,40 @@ Simple copyright statement THEN exit code is 1 AND stderr contains "FOOBAR.*2015 not contained" +Itemised copyright years +------------------------ + + SCENARIO itemised copyright years + GIVEN a file FOOBAR containing "Copyright 1999,2014 Foo Bar" + + GIVEN commit year is 1998 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*1998 not contained" + + GIVEN commit year is 1999 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2000 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2000 not contained" + + GIVEN commit year is 2013 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2013 not contained" + + GIVEN commit year is 2014 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2015 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2015 not contained" + Implementations =============== -- cgit v1.2.1 From 5b3ccf57b5d25547208fcdaae2ab3ec6be86a74b Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 16 Apr 2014 18:50:44 +0100 Subject: Add test for range of copyright years --- yarns/010-tests.yarn | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/yarns/010-tests.yarn b/yarns/010-tests.yarn index ec71561..6456ca1 100644 --- a/yarns/010-tests.yarn +++ b/yarns/010-tests.yarn @@ -79,6 +79,39 @@ Itemised copyright years THEN exit code is 1 AND stderr contains "FOOBAR.*2015 not contained" +Range of copyright years +------------------------ + + SCENARIO range of copyright years + GIVEN a file FOOBAR containing "Copyright 1999-2014 Foo Bar" + + GIVEN commit year is 1998 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*1998 not contained" + + GIVEN commit year is 1999 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2000 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2013 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2014 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2015 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2015 not contained" + + Implementations =============== -- cgit v1.2.1 From 3f6f737c4fbcbd267ed135f968eec181d6ced508 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 16 Apr 2014 18:52:41 +0100 Subject: Add test for combined range and itemised copyright years --- yarns/010-tests.yarn | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/yarns/010-tests.yarn b/yarns/010-tests.yarn index 6456ca1..e2ec72d 100644 --- a/yarns/010-tests.yarn +++ b/yarns/010-tests.yarn @@ -111,6 +111,44 @@ Range of copyright years THEN exit code is 1 AND stderr contains "FOOBAR.*2015 not contained" +Combined itemised and range of copyright years +---------------------------------------------- + + SCENARIO combined itemised and range of copyright years + GIVEN a file FOOBAR containing "Copyright 1999-2000, 2014 Foo Bar" + + GIVEN commit year is 1998 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*1998 not contained" + + GIVEN commit year is 1999 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2000 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2001 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2001 not contained" + + GIVEN commit year is 2013 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2013 not contained" + + GIVEN commit year is 2014 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 0 + + GIVEN commit year is 2015 + WHEN copyright-statement-lint is run against FOOBAR + THEN exit code is 1 + AND stderr contains "FOOBAR.*2015 not contained" + Implementations =============== -- cgit v1.2.1