{"record":{"id":"8add37ee7064e81d","repo":"golang/go","slug":"s-and-s-differ","errorCode":null,"errorMessage":"%s and %s differ","messagePattern":"(.+?) and (.+?) differ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/cmds.go","lineNumber":268,"sourceCode":"\t}\n\n\tdata, err := os.ReadFile(s.Path(name2))\n\tif err != nil {\n\t\treturn err\n\t}\n\ttext2 = string(data)\n\n\tif env {\n\t\ttext1 = s.ExpandEnv(text1, false)\n\t\ttext2 = s.ExpandEnv(text2, false)\n\t}\n\n\tif text1 != text2 {\n\t\tif !quiet {\n\t\t\tdiffText := diff.Diff(name1, []byte(text1), name2, []byte(text2))\n\t\t\ts.Logf(\"%s\\n\", diffText)\n\t\t}\n\t\treturn fmt.Errorf(\"%s and %s differ\", name1, name2)\n\t}\n\treturn nil\n}\n\n// Cp copies one or more files to a new location.\nfunc Cp() Cmd {\n\treturn Command(\n\t\tCmdUsage{\n\t\t\tSummary: \"copy files to a target file or directory\",\n\t\t\tArgs:    \"src... dst\",\n\t\t\tDetail: []string{\n\t\t\t\t\"src can include 'stdout' or 'stderr' to copy from the script's stdout or stderr buffer.\",\n\t\t\t},\n\t\t},\n\t\tfunc(s *State, args ...string) (WaitFunc, error) {\n\t\t\tif len(args) < 2 {\n\t\t\t\treturn nil, ErrUsage\n\t\t\t}","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/cmds.go#L250-L286","documentation":"Thrown by the cmp command in the Go test script framework when two files' contents differ after optional environment-variable expansion. The error includes the file names; if not quiet, a diff is also logged beforehand via s.Logf. This is an assertion-style command — it 'fails' the script when files don't match.","triggerScenarios":"text1 (content of file 1, optionally env-expanded) != text2 (content of file 2, optionally env-expanded). The cmp command reads both files, optionally expands $VAR references, then compares the resulting strings.","commonSituations":"Test script expects a specific output file but the program produced different content. Common in golden-file tests where expected output drifts after code changes, or when environment-variable placeholders don't match actual runtime values.","solutions":["Run the test with -v and examine the logged diff to see exact differences.","If the new output is correct, update the expected/golden file to match.","If env expansion is involved, ensure environment variables are set correctly in the script setup.","Use the -env flag or ensure s.Setenv calls match expected expansion."],"exampleFix":"// Update golden file if output is intentionally different:\n// go test -run TestName -update  # or manually cp actual expected\n\n// Or fix the code path producing wrong output.","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// cmp is an assertion command; handle by examining the diff:\n// In test scripts, this is expected behavior. Use:\n// cmp expected.txt actual.txt\n// If it fails, the script framework logs the diff automatically.\n// To tolerate differences, use a conditional or regenerate golden files.","preventionTips":["Update golden/expected files whenever output intentionally changes.","Use -v flag to see the full diff when cmp fails.","Ensure environment variables used in env-expansion mode are set consistently."],"tags":["script","test-framework","cmp","file-comparison","assertion","go-compiler-internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}