Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows test fixes. #30

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading