Commit 78d798bbe907d632488281c352d306967653b7ca
1 parent
dea5e07e
fix(infra): 修复 windows 代码生成单测换行符差异
Showing
1 changed file
with
8 additions
and
6 deletions
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,14 +108,16 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { | ||
| 108 | asserts.forEach(assertMap -> { | 108 | asserts.forEach(assertMap -> { |
| 109 | String contentPath = (String) assertMap.get("contentPath"); | 109 | String contentPath = (String) assertMap.get("contentPath"); |
| 110 | String filePath = (String) assertMap.get("filePath"); | 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 | String actual = result.get(filePath); | 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,10 +151,10 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { | ||
| 149 | + '/' + StrUtil.subBefore(lastFilePath, '.', true); | 151 | + '/' + StrUtil.subBefore(lastFilePath, '.', true); |
| 150 | asserts.add(MapUtil.<String, String>builder().put("filePath", filePath) | 152 | asserts.add(MapUtil.<String, String>builder().put("filePath", filePath) |
| 151 | .put("contentPath", contentPath).build()); | 153 | .put("contentPath", contentPath).build()); |
| 152 | - FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); | 154 | + FileUtil.writeUtf8String(normalizeLineEndings(fileContent), basePath + "/" + contentPath); |
| 153 | }); | 155 | }); |
| 154 | // 写入 assert.json 文件 | 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 | } |