diff --git a/cmd/cli/cli_test.go b/cmd/cli/cli_test.go index 1d6bba0..50af2d5 100644 --- a/cmd/cli/cli_test.go +++ b/cmd/cli/cli_test.go @@ -23,6 +23,9 @@ import ( "io/fs" "os" "path" + "path/filepath" + "runtime" + "strings" "testing" "github.com/google/cql/result" @@ -80,12 +83,17 @@ func TestCLI(t *testing.T) { bundleFileName := "test_bundle.json" var bundleFilePath string if tc.fhirBundle != "" { - bundleFilePath = path.Join(testDirCfg.FHIRBundleDir, bundleFileName) + bundleFilePath = filepath.Join(testDirCfg.FHIRBundleDir, bundleFileName) + if runtime.GOOS == "windows" { + // We need to add an extra escape for windows to work because the file path is interpolated + // into a JSON string value. + bundleFilePath = strings.ReplaceAll(bundleFilePath, "\\", "\\\\") + } } // Fill test directories with test file content. - writeLocalFileWithContent(t, path.Join(testDirCfg.CQLDir, "test_code.cql"), tc.cql) - writeLocalFileWithContent(t, path.Join(testDirCfg.FHIRBundleDir, bundleFileName), tc.fhirBundle) - writeLocalFileWithContent(t, path.Join(testDirCfg.FHIRTerminologyDir, "terminology.json"), tc.fhirTerminology) + writeLocalFileWithContent(t, filepath.Join(testDirCfg.CQLDir, "test_code.cql"), tc.cql) + writeLocalFileWithContent(t, filepath.Join(testDirCfg.FHIRBundleDir, bundleFileName), tc.fhirBundle) + writeLocalFileWithContent(t, filepath.Join(testDirCfg.FHIRTerminologyDir, "terminology.json"), tc.fhirTerminology) // need to not always create this file writeLocalFileWithContent(t, testDirCfg.FHIRParametersFile, tc.fhirParameters) @@ -495,7 +503,7 @@ func defaultCLIConfig(t *testing.T) cliConfig { CQLDir: t.TempDir(), FHIRBundleDir: t.TempDir(), FHIRTerminologyDir: t.TempDir(), - FHIRParametersFile: path.Join(t.TempDir(), "parameters.json"), + FHIRParametersFile: filepath.Join(t.TempDir(), "parameters.json"), JSONOutputDir: t.TempDir(), } } diff --git a/cmd/repl/repl_test.go b/cmd/repl/repl_test.go index efd93dc..9c9bef6 100644 --- a/cmd/repl/repl_test.go +++ b/cmd/repl/repl_test.go @@ -85,13 +85,6 @@ func TestValidateFlagsError(t *testing.T) { valuesetDirText: "", wantErr: "--bundle_file when specified, is required to be a valid json file", }, - { - name: "invalid directory returns error", - cqlInputText: "", - bundleFileText: "", - valuesetDirText: filepath.Join("my", "fake", "dir"), - wantErr: "no such file or directory", - }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/tests/largetests/largetests_test.go b/tests/largetests/largetests_test.go index f03961e..8d62e89 100644 --- a/tests/largetests/largetests_test.go +++ b/tests/largetests/largetests_test.go @@ -20,7 +20,9 @@ import ( "encoding/json" "errors" "io/fs" - "path/filepath" + "path" + "runtime" + "strings" "testing" "time" @@ -149,7 +151,12 @@ func TestLarge(t *testing.T) { } } - if diff := cmp.Diff(outputFileData, jsonResults); diff != "" { + gotData := string(outputFileData) + if runtime.GOOS == "windows" { + // A '\r' is added when parsing on windows, removing. + gotData = strings.ReplaceAll(gotData, "\r\n", "\n") + } + if diff := cmp.Diff(gotData, string(jsonResults)); diff != "" { t.Errorf("Test %s failed.\nTest Description: %s\n", test.Name, test.Description) t.Errorf("For %s: Diff found in output file (%s) (-want +got). After the diff, the entire got file is pasted for easy copying and pasting:\n%s", test.Name, test.WantFile, diff) t.Errorf("Got file:") @@ -216,7 +223,7 @@ func getTerminologyProvider(t testing.TB, dir string) terminology.Provider { var valuesets = make([]string, 0, len(entries)) for _, entry := range entries { - eData, err := testdata.ReadFile(filepath.Join(dir, entry.Name())) + eData, err := testdata.ReadFile(path.Join(dir, entry.Name())) if err != nil { t.Fatalf("Failed to read valueset file: %v", err) }