Skip to content

Commit

Permalink
Windows test fixes.
Browse files Browse the repository at this point in the history
* cli_tests now escapes backslashes in windows file path.
* cli_tests all paths are now proper os specific file paths.
* repl_tests removed a test that was previously split out into it's own case.
* large_tests because we're using embedded files we don't need to use os specific paths.
* large_tests removed '\r' added to the end of each line for unmarshalled embedded json

PiperOrigin-RevId: 647362606
  • Loading branch information
evan-gordon authored and copybara-github committed Jun 27, 2024
1 parent c3b3418 commit caaac1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
18 changes: 13 additions & 5 deletions cmd/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"io/fs"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/google/cql/result"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(),
}
}
Expand Down
7 changes: 0 additions & 7 deletions cmd/repl/repl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions tests/largetests/largetests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"encoding/json"
"errors"
"io/fs"
"path/filepath"
"path"
"runtime"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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:")
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit caaac1b

Please sign in to comment.