only:testability progress

This commit is contained in:
rusefillc 2023-12-06 10:20:53 -05:00
parent 143d20ceca
commit 01d93eb3f9
8 changed files with 22 additions and 12 deletions

View File

@ -10,6 +10,8 @@ defaultTasks 'shadowJar'
dependencies { dependencies {
api project(':config_definition_base') api project(':config_definition_base')
api project(':trigger-image') api project(':trigger-image')
testImplementation testFixtures(project(':config_definition_base'))
} }
shadowJar { shadowJar {

View File

@ -2,6 +2,7 @@ package com.rusefi.test;
import com.rusefi.BitState; import com.rusefi.BitState;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.ldmp.TestFileCaptor;
import com.rusefi.output.DataLogConsumer; import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.GaugeConsumer; import com.rusefi.output.GaugeConsumer;
import com.rusefi.output.OutputsSectionConsumer; import com.rusefi.output.OutputsSectionConsumer;
@ -53,7 +54,7 @@ public class OutputsTest {
@NotNull @NotNull
private static OutputsSectionConsumer runOriginalImplementation(String test, ReaderStateImpl state) { private static OutputsSectionConsumer runOriginalImplementation(String test, ReaderStateImpl state) {
OutputsSectionConsumer tsProjectConsumer = new OutputsSectionConsumer(null); OutputsSectionConsumer tsProjectConsumer = new OutputsSectionConsumer(null, new TestFileCaptor());
state.readBufferedReader(test, tsProjectConsumer); state.readBufferedReader(test, tsProjectConsumer);
return tsProjectConsumer; return tsProjectConsumer;
} }
@ -70,7 +71,7 @@ public class OutputsTest {
"\n" + "\n" +
"end_struct\n"; "end_struct\n";
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
DataLogConsumer dataLogConsumer = new DataLogConsumer(null); DataLogConsumer dataLogConsumer = new DataLogConsumer(null, new TestFileCaptor());
state.readBufferedReader(test, dataLogConsumer); state.readBufferedReader(test, dataLogConsumer);
assertEquals( assertEquals(
"entry = vvtStatus1_pTerm, \"vvtStatus1_pTerm\", float, \"%.3f\"\n" + "entry = vvtStatus1_pTerm, \"vvtStatus1_pTerm\", float, \"%.3f\"\n" +
@ -103,7 +104,7 @@ public class OutputsTest {
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100); state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello"); state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello");
DataLogConsumer dataLogConsumer = new DataLogConsumer(null); DataLogConsumer dataLogConsumer = new DataLogConsumer(null, new TestFileCaptor());
state.readBufferedReader(test, dataLogConsumer); state.readBufferedReader(test, dataLogConsumer);
assertEquals( assertEquals(
"entry = issue_294_31, \"issue_294_31\", int, \"%d\"\n" + "entry = issue_294_31, \"issue_294_31\", int, \"%d\"\n" +
@ -133,7 +134,7 @@ public class OutputsTest {
"end_struct\n"; "end_struct\n";
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
DataLogConsumer dataLogConsumer = new DataLogConsumer(null); DataLogConsumer dataLogConsumer = new DataLogConsumer(null, new TestFileCaptor());
state.readBufferedReader(test, dataLogConsumer); state.readBufferedReader(test, dataLogConsumer);
assertEquals("\"fuel: base mass\"", state.getVariableRegistry().get("GAUGE_NAME_FUEL_BASE")); assertEquals("\"fuel: base mass\"", state.getVariableRegistry().get("GAUGE_NAME_FUEL_BASE"));
@ -157,7 +158,7 @@ public class OutputsTest {
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("GAUGE_CATEGORY", "Alternator"); state.getVariableRegistry().register("GAUGE_CATEGORY", "Alternator");
DataLogConsumer dataLogConsumer = new DataLogConsumer(null); DataLogConsumer dataLogConsumer = new DataLogConsumer(null, new TestFileCaptor());
GaugeConsumer gaugeConsumer = new GaugeConsumer(null); GaugeConsumer gaugeConsumer = new GaugeConsumer(null);
state.readBufferedReader(test, dataLogConsumer, gaugeConsumer); state.readBufferedReader(test, dataLogConsumer, gaugeConsumer);
assertEquals( assertEquals(

View File

@ -1,5 +1,6 @@
plugins { plugins {
id 'java-library' id 'java-library'
id 'java-test-fixtures'
id 'com.github.johnrengelman.shadow' version "${shadowVersion}" id 'com.github.johnrengelman.shadow' version "${shadowVersion}"
} }

View File

@ -108,9 +108,10 @@ public class LiveDataProcessor {
public int handleYaml(Map<String, Object> data) throws IOException { public int handleYaml(Map<String, Object> data) throws IOException {
JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer(); JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer();
OutputsSectionConsumer outputsSections = new OutputsSectionConsumer(tsOutputsDestination + File.separator + "generated/output_channels.ini"); OutputsSectionConsumer outputsSections = new OutputsSectionConsumer(tsOutputsDestination + File.separator + "generated/output_channels.ini",
fileFactory);
ConfigurationConsumer dataLogConsumer = new DataLogConsumer(tsOutputsDestination + File.separator + "generated/data_logs.ini"); ConfigurationConsumer dataLogConsumer = new DataLogConsumer(tsOutputsDestination + File.separator + "generated/data_logs.ini", fileFactory);
SdCardFieldsContent sdCardFieldsConsumer = new SdCardFieldsContent(); SdCardFieldsContent sdCardFieldsConsumer = new SdCardFieldsContent();

View File

@ -5,10 +5,10 @@ import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState; import com.rusefi.ReaderState;
import com.rusefi.VariableRegistry; import com.rusefi.VariableRegistry;
import com.rusefi.parse.TypesHelper; import com.rusefi.parse.TypesHelper;
import com.rusefi.util.LazyFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.TreeSet; import java.util.TreeSet;
@ -25,11 +25,13 @@ public class DataLogConsumer implements ConfigurationConsumer {
public static final String UNUSED = ConfigStructure.UNUSED_ANYTHING_PREFIX; public static final String UNUSED = ConfigStructure.UNUSED_ANYTHING_PREFIX;
private final String fileName; private final String fileName;
private final LazyFile.LazyFileFactory fileFactory;
private final StringBuilder tsWriter = new StringBuilder(); private final StringBuilder tsWriter = new StringBuilder();
private final TreeSet<String> comments = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); private final TreeSet<String> comments = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
public DataLogConsumer(String fileName) { public DataLogConsumer(String fileName, LazyFile.LazyFileFactory fileFactory) {
this.fileName = fileName; this.fileName = fileName;
this.fileFactory = fileFactory;
} }
@Override @Override
@ -58,7 +60,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
private void writeStringToFile(@Nullable String fileName, StringBuilder writer) throws IOException { private void writeStringToFile(@Nullable String fileName, StringBuilder writer) throws IOException {
if (fileName != null) { if (fileName != null) {
FileWriter fw = new FileWriter(fileName); LazyFile fw = fileFactory.create(fileName);
fw.write(writer.toString()); fw.write(writer.toString());
fw.close(); fw.close();
} }

View File

@ -2,6 +2,7 @@ package com.rusefi.output;
import com.devexperts.logging.Logging; import com.devexperts.logging.Logging;
import com.rusefi.ReaderState; import com.rusefi.ReaderState;
import com.rusefi.util.LazyFile;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -16,11 +17,13 @@ public class OutputsSectionConsumer implements ConfigurationConsumer {
private static final Logging log = getLogging(OutputsSectionConsumer.class); private static final Logging log = getLogging(OutputsSectionConsumer.class);
private final String tsOutputsSectionFileName; private final String tsOutputsSectionFileName;
private final LazyFile.LazyFileFactory fileFactory;
private final TsOutput tsOutput; private final TsOutput tsOutput;
private int sensorTsPosition; private int sensorTsPosition;
public OutputsSectionConsumer(String tsOutputsSectionFileName) { public OutputsSectionConsumer(String tsOutputsSectionFileName, LazyFile.LazyFileFactory fileFactory) {
this.tsOutputsSectionFileName = tsOutputsSectionFileName; this.tsOutputsSectionFileName = tsOutputsSectionFileName;
this.fileFactory = fileFactory;
tsOutput = new TsOutput(false); tsOutput = new TsOutput(false);
} }
@ -40,7 +43,7 @@ public class OutputsSectionConsumer implements ConfigurationConsumer {
if (readerState.isStackEmpty()) { if (readerState.isStackEmpty()) {
if (tsOutputsSectionFileName != null) { if (tsOutputsSectionFileName != null) {
FileWriter fos = new FileWriter(tsOutputsSectionFileName); LazyFile fos = fileFactory.create(tsOutputsSectionFileName);
fos.write(tsOutput.getContent()); fos.write(tsOutput.getContent());
fos.close(); fos.close();
} }