diff --git a/eng/_util/cmd/updatecryptodocs/updatecryptodocs_test.go b/eng/_util/cmd/updatecryptodocs/updatecryptodocs_test.go index 81ea70788ca..9725f19aa54 100644 --- a/eng/_util/cmd/updatecryptodocs/updatecryptodocs_test.go +++ b/eng/_util/cmd/updatecryptodocs/updatecryptodocs_test.go @@ -9,6 +9,8 @@ import ( "path/filepath" "strings" "testing" + + "github.com/microsoft/go/_util/internal/docutil" ) func TestUpdateCryptoDocsReproducible(t *testing.T) { @@ -17,6 +19,7 @@ func TestUpdateCryptoDocsReproducible(t *testing.T) { if err != nil { t.Fatalf("Failed to read checked-in document at %q: %v", checkedInPath, err) } + skipIfCopiedDocument(t, checkedIn) generated, err := generate() if err != nil { @@ -37,6 +40,7 @@ func TestUpdateUserGuideReproducible(t *testing.T) { if err != nil { t.Fatalf("Failed to read checked-in document at %q: %v", checkedInPath, err) } + skipIfCopiedDocument(t, checkedIn) generated, err := generateUserGuide() if err != nil { @@ -50,3 +54,10 @@ func TestUpdateUserGuideReproducible(t *testing.T) { t.Errorf("Generated document does not match checked-in document. Run this command to update:\n pwsh eng/run.ps1 updatecryptodocs") } } + +func skipIfCopiedDocument(t *testing.T, contents []byte) { + t.Helper() + if docutil.IsCopied(contents) { + t.Skip("Document is maintained by automatic copying, not local regeneration.") + } +} diff --git a/eng/_util/internal/docutil/docutil.go b/eng/_util/internal/docutil/docutil.go new file mode 100644 index 00000000000..ae93dfd5945 --- /dev/null +++ b/eng/_util/internal/docutil/docutil.go @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package docutil + +import "strings" + +// IsCopied reports whether contents start with the automatic documentation copy notice. +func IsCopied(contents []byte) bool { + normalized := strings.ReplaceAll(string(contents), "\r\n", "\n") + return strings.HasPrefix(normalized, "\nCopied document.\n", true}, + {"copy_crlf", strings.ReplaceAll(prefix+"\n-->\nCopied document.\n", "\n", "\r\n"), true}, + {"prefix_only", prefix, true}, + {"empty", "", false}, + {"local", "Generated document.\n", false}, + {"partial_prefix", "