Skip to content

Commit

Permalink
test: add extra tests for -e flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lluissm committed Oct 29, 2023
1 parent c2e57fc commit f2cc068
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SOFTWARE.
package options

import (
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -123,3 +124,11 @@ func TestIgnorePaths(t *testing.T) {
options, _ = Parse(args)
assert.True(t, len(options.Process.IgnorePaths) == 0)
}

func TestHeaderRegex(t *testing.T) {
headerRegexStr := "\"\"\"(.|[\\r\\n])*\"\"\""
headerRegex := regexp.MustCompile(headerRegexStr)
args := []string{"license-header-checker", "-e", headerRegexStr, "license-path", "source-path", "js", "ts"}
options, _ := Parse(args)
assert.Equal(t, headerRegex, options.Process.HeaderRegex)
}
2 changes: 1 addition & 1 deletion pkg/process/process_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestExtractHeader(t *testing.T) {

// Check non-default headers
expected = strings.TrimSpace(testPythonTargetLicense)
pyRegex := regexp.MustCompile(`\"""(.|[\r\n])*\"""`)
pyRegex := regexp.MustCompile(`"""(.|[\r\n])*"""`)

output = extractHeader(pyRegex, testFileWithPythonTargetLicense)
assert.True(t, output == expected)
Expand Down
7 changes: 7 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ expected_output="\
files: license_ok: - sample-project/src/file-with-license.js license_replaced: - sample-project/src/file-with-old-license.cpp - sample-project/test/file-with-old-license.go license_added: - sample-project/src/file-without-license.java options: project_path: sample-project ignore_paths: - src/other extensions: - .java - .js - .cpp - .go flags: - add - replace - verbose license_header: %ssample-project/licenses/current-license.txt totals: license_ok: 1 files license_replaced: 2 files license_added: 1 files elapsed_time: 0ms"
run_test "$flags" "$test_case" "$expected_output"

# add and replace with ignore and custom header regex (and verbose)
flags='-a -r -v -i src/other -e /\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/'
test_case='Testing with -a and -r and -i and -v and -e flags...'
expected_output="\
files: license_ok: - sample-project/src/file-with-license.js license_replaced: - sample-project/src/file-with-old-license.cpp - sample-project/test/file-with-old-license.go license_added: - sample-project/src/file-without-license.java options: project_path: sample-project ignore_paths: - src/other extensions: - .java - .js - .cpp - .go flags: - add - replace - verbose license_header: %ssample-project/licenses/current-license.txt totals: license_ok: 1 files license_replaced: 2 files license_added: 1 files elapsed_time: 0ms"
run_test "$flags" "$test_case" "$expected_output"

delete_sample_project

if (($errors > 0)); then
Expand Down

0 comments on commit f2cc068

Please sign in to comment.