Commit 78d798bbe907d632488281c352d306967653b7ca

Authored by YunaiV
1 parent dea5e07e

fix(infra): 修复 windows 代码生成单测换行符差异

yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java
... ... @@ -108,14 +108,16 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest {
108 108 asserts.forEach(assertMap -> {
109 109 String contentPath = (String) assertMap.get("contentPath");
110 110 String filePath = (String) assertMap.get("filePath");
111   - String expected = ResourceUtil.readUtf8Str("codegen/" + path + "/" + contentPath)
112   - .replace("\r\n", "\n");
  111 + String expected = normalizeLineEndings(ResourceUtil.readUtf8Str("codegen/" + path + "/" + contentPath));
113 112 String actual = result.get(filePath);
114   - assertEquals(expected, actual == null ? null : actual.replace("\r\n", "\n"),
115   - filePath + ":不匹配");
  113 + assertEquals(expected, normalizeLineEndings(actual), filePath + ":不匹配");
116 114 });
117 115 }
118 116  
  117 + private static String normalizeLineEndings(String content) {
  118 + return content == null ? null : content.replace("\r\n", "\n").replace("\r", "\n");
  119 + }
  120 +
119 121 // ==================== 调试专用 ====================
120 122  
121 123 /**
... ... @@ -149,10 +151,10 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest {
149 151 + '/' + StrUtil.subBefore(lastFilePath, '.', true);
150 152 asserts.add(MapUtil.<String, String>builder().put("filePath", filePath)
151 153 .put("contentPath", contentPath).build());
152   - FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath);
  154 + FileUtil.writeUtf8String(normalizeLineEndings(fileContent), basePath + "/" + contentPath);
153 155 });
154 156 // 写入 assert.json 文件
155   - FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath + "/assert.json");
  157 + FileUtil.writeUtf8String(normalizeLineEndings(JsonUtils.toJsonPrettyString(asserts)), basePath + "/assert.json");
156 158 }
157 159  
158 160 }
... ...