diff --git a/spec/construct/test_debug_array_user.py b/spec/construct/test_debug_array_user.py new file mode 100644 index 000000000..b7a8238d3 --- /dev/null +++ b/spec/construct/test_debug_array_user.py @@ -0,0 +1,15 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest + +from debug_array_user import _schema + +class TestDebugArrayUser(unittest.TestCase): + def test_debug_array_user(self): + r = _schema.parse_file('src/fixed_struct.bin') + r._read() + + self.assertEqual(r.one_cat.meow, 80) + self.assertEqual(r.array_of_cats[0].meow, 65) + self.assertEqual(r.array_of_cats[1].meow, 67) + self.assertEqual(r.array_of_cats[2].meow, 75) diff --git a/spec/construct/test_debug_switch_user.py b/spec/construct/test_debug_switch_user.py index 9120d4e32..6e6a4bf54 100644 --- a/spec/construct/test_debug_switch_user.py +++ b/spec/construct/test_debug_switch_user.py @@ -7,6 +7,7 @@ class TestDebugSwitchUser(unittest.TestCase): def test_debug_switch_user(self): r = _schema.parse_file('src/nav_parent_switch.bin') + r._read() self.assertEqual(r.code, 1) self.assertEqual(r.data.val, -190) diff --git a/spec/cpp_stl_11/test_debug_array_user.cpp b/spec/cpp_stl_11/test_debug_array_user.cpp index fc78070d2..04fc4ae9f 100644 --- a/spec/cpp_stl_11/test_debug_array_user.cpp +++ b/spec/cpp_stl_11/test_debug_array_user.cpp @@ -1,5 +1,7 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include -#include +#include "debug_array_user.h" #include #include #include @@ -8,14 +10,12 @@ BOOST_AUTO_TEST_CASE(test_debug_array_user) { std::ifstream ifs("src/fixed_struct.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); debug_array_user_t* r = new debug_array_user_t(&ks); - - // --debug implies --no-auto-read r->_read(); - BOOST_CHECK_EQUAL(r->one_cat()->meow(), 0x50); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(0)->meow(), 0x41); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(1)->meow(), 0x43); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(2)->meow(), 0x4b); + BOOST_CHECK_EQUAL(r->one_cat()->meow(), 80); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(0)->meow(), 65); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(1)->meow(), 67); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(2)->meow(), 75); delete r; } diff --git a/spec/cpp_stl_11/test_debug_switch_user.cpp b/spec/cpp_stl_11/test_debug_switch_user.cpp index 795737f3d..93b2b7060 100644 --- a/spec/cpp_stl_11/test_debug_switch_user.cpp +++ b/spec/cpp_stl_11/test_debug_switch_user.cpp @@ -1,4 +1,4 @@ -// runs in debug mode, so the _read() needs to be called manually +// Autogenerated from KST: please remove this line if doing any edits by hand! #include #include "debug_switch_user.h" @@ -6,14 +6,12 @@ #include #include - BOOST_AUTO_TEST_CASE(test_debug_switch_user) { std::ifstream ifs("src/nav_parent_switch.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); debug_switch_user_t* r = new debug_switch_user_t(&ks); r->_read(); - BOOST_CHECK_EQUAL(r->code(), 1); BOOST_CHECK_EQUAL(static_cast(r->data())->val(), -190); diff --git a/spec/cpp_stl_98/test_debug_array_user.cpp b/spec/cpp_stl_98/test_debug_array_user.cpp index fc78070d2..04fc4ae9f 100644 --- a/spec/cpp_stl_98/test_debug_array_user.cpp +++ b/spec/cpp_stl_98/test_debug_array_user.cpp @@ -1,5 +1,7 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include -#include +#include "debug_array_user.h" #include #include #include @@ -8,14 +10,12 @@ BOOST_AUTO_TEST_CASE(test_debug_array_user) { std::ifstream ifs("src/fixed_struct.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); debug_array_user_t* r = new debug_array_user_t(&ks); - - // --debug implies --no-auto-read r->_read(); - BOOST_CHECK_EQUAL(r->one_cat()->meow(), 0x50); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(0)->meow(), 0x41); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(1)->meow(), 0x43); - BOOST_CHECK_EQUAL(r->array_of_cats()->at(2)->meow(), 0x4b); + BOOST_CHECK_EQUAL(r->one_cat()->meow(), 80); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(0)->meow(), 65); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(1)->meow(), 67); + BOOST_CHECK_EQUAL(r->array_of_cats()->at(2)->meow(), 75); delete r; } diff --git a/spec/cpp_stl_98/test_debug_switch_user.cpp b/spec/cpp_stl_98/test_debug_switch_user.cpp index 795737f3d..93b2b7060 100644 --- a/spec/cpp_stl_98/test_debug_switch_user.cpp +++ b/spec/cpp_stl_98/test_debug_switch_user.cpp @@ -1,4 +1,4 @@ -// runs in debug mode, so the _read() needs to be called manually +// Autogenerated from KST: please remove this line if doing any edits by hand! #include #include "debug_switch_user.h" @@ -6,14 +6,12 @@ #include #include - BOOST_AUTO_TEST_CASE(test_debug_switch_user) { std::ifstream ifs("src/nav_parent_switch.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); debug_switch_user_t* r = new debug_switch_user_t(&ks); r->_read(); - BOOST_CHECK_EQUAL(r->code(), 1); BOOST_CHECK_EQUAL(static_cast(r->data())->val(), -190); diff --git a/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugArrayUser.cs b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugArrayUser.cs index 1ff546ff8..684c19b46 100644 --- a/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugArrayUser.cs +++ b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugArrayUser.cs @@ -1,21 +1,22 @@ -using System; +// Autogenerated from KST: please remove this line if doing any edits by hand! + +using NUnit.Framework; namespace Kaitai { - using NUnit.Framework; - [TestFixture] public class SpecDebugArrayUser : CommonSpec { [Test] public void TestDebugArrayUser() { - DebugArrayUser r = DebugArrayUser.FromFile(SourceFile("fixed_struct.bin")); + var r = DebugArrayUser.FromFile(SourceFile("fixed_struct.bin")); r._read(); - Assert.AreEqual(r.OneCat.Meow, 0x50); - Assert.AreEqual(r.ArrayOfCats[0].Meow, 0x41); - Assert.AreEqual(r.ArrayOfCats[1].Meow, 0x43); - Assert.AreEqual(r.ArrayOfCats[2].Meow, 0x4b); + + Assert.AreEqual(r.OneCat.Meow, 80); + Assert.AreEqual(r.ArrayOfCats[0].Meow, 65); + Assert.AreEqual(r.ArrayOfCats[1].Meow, 67); + Assert.AreEqual(r.ArrayOfCats[2].Meow, 75); } } } diff --git a/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugSwitchUser.cs b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugSwitchUser.cs index fa2b13ba8..e0a776190 100644 --- a/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugSwitchUser.cs +++ b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecDebugSwitchUser.cs @@ -1,4 +1,4 @@ -// runs in debug mode, so the _read() needs to be called manually +// Autogenerated from KST: please remove this line if doing any edits by hand! using NUnit.Framework; @@ -13,7 +13,6 @@ public void TestDebugSwitchUser() var r = DebugSwitchUser.FromFile(SourceFile("nav_parent_switch.bin")); r._read(); - Assert.AreEqual(r.Code, 1); Assert.AreEqual(((DebugSwitchUser.One) (r.Data)).Val, -190); } diff --git a/spec/go/debug_array_user_test.go b/spec/go/debug_array_user_test.go index 4ac318623..a1582089f 100644 --- a/spec/go/debug_array_user_test.go +++ b/spec/go/debug_array_user_test.go @@ -1,3 +1,5 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + package spec import ( @@ -27,8 +29,8 @@ func TestDebugArrayUser(t *testing.T) { t.Fatal(err) } - assert.EqualValues(t, 0x50, r.OneCat.Meow) - assert.EqualValues(t, 0x41, r.ArrayOfCats[0].Meow) - assert.EqualValues(t, 0x43, r.ArrayOfCats[1].Meow) - assert.EqualValues(t, 0x4b, r.ArrayOfCats[2].Meow) + assert.EqualValues(t, 80, r.OneCat.Meow) + assert.EqualValues(t, 65, r.ArrayOfCats[0].Meow) + assert.EqualValues(t, 67, r.ArrayOfCats[1].Meow) + assert.EqualValues(t, 75, r.ArrayOfCats[2].Meow) } diff --git a/spec/java/src/io/kaitai/struct/spec/TestDebugArrayUser.java b/spec/java/src/io/kaitai/struct/spec/TestDebugArrayUser.java index 55b86f049..41cb3a3e5 100644 --- a/spec/java/src/io/kaitai/struct/spec/TestDebugArrayUser.java +++ b/spec/java/src/io/kaitai/struct/spec/TestDebugArrayUser.java @@ -1,19 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + package io.kaitai.struct.spec; import io.kaitai.struct.testformats.DebugArrayUser; import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - +import static org.testng.Assert.*; public class TestDebugArrayUser extends CommonSpec { + @Test public void testDebugArrayUser() throws Exception { DebugArrayUser r = DebugArrayUser.fromFile(SRC_DIR + "fixed_struct.bin"); r._read(); - assertEquals(r.oneCat().meow(), 0x50); - assertEquals(r.arrayOfCats().get(0).meow(), 0x41); - assertEquals(r.arrayOfCats().get(1).meow(), 0x43); - assertEquals(r.arrayOfCats().get(2).meow(), 0x4b); + assertIntEquals(r.oneCat().meow(), 80); + assertIntEquals(r.arrayOfCats().get((int) 0).meow(), 65); + assertIntEquals(r.arrayOfCats().get((int) 1).meow(), 67); + assertIntEquals(r.arrayOfCats().get((int) 2).meow(), 75); } } diff --git a/spec/java/src/io/kaitai/struct/spec/TestDebugSwitchUser.java b/spec/java/src/io/kaitai/struct/spec/TestDebugSwitchUser.java index cbc2126b0..d1f03ce71 100644 --- a/spec/java/src/io/kaitai/struct/spec/TestDebugSwitchUser.java +++ b/spec/java/src/io/kaitai/struct/spec/TestDebugSwitchUser.java @@ -1,4 +1,4 @@ -// runs in debug mode, so the _read() needs to be called manually +// Autogenerated from KST: please remove this line if doing any edits by hand! package io.kaitai.struct.spec; diff --git a/spec/javascript/test_debug_array_user.js b/spec/javascript/test_debug_array_user.js index 0a3b293cd..53fc3d8ca 100644 --- a/spec/javascript/test_debug_array_user.js +++ b/spec/javascript/test_debug_array_user.js @@ -1,11 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + var assert = require('assert'); var testHelper = require('testHelper'); -testHelper('DebugArrayUser', 'src/fixed_struct.bin', function(r) { - r._read(); +testHelper('DebugArrayUser', 'src/fixed_struct.bin', function(r, DebugArrayUser) { + r._read(); - assert.equal(r.oneCat.meow, 80); - assert.equal(r.arrayOfCats[0].meow, 65); - assert.equal(r.arrayOfCats[1].meow, 67); - assert.equal(r.arrayOfCats[2].meow, 75); + assert.strictEqual(r.oneCat.meow, 80); + assert.strictEqual(r.arrayOfCats[0].meow, 65); + assert.strictEqual(r.arrayOfCats[1].meow, 67); + assert.strictEqual(r.arrayOfCats[2].meow, 75); }); diff --git a/spec/javascript/test_debug_switch_user.js b/spec/javascript/test_debug_switch_user.js index 9c3c9bfee..159c77c7d 100644 --- a/spec/javascript/test_debug_switch_user.js +++ b/spec/javascript/test_debug_switch_user.js @@ -1,4 +1,4 @@ -// runs in debug mode, so the _read() needs to be called manually +// Autogenerated from KST: please remove this line if doing any edits by hand! var assert = require('assert'); var testHelper = require('testHelper'); diff --git a/spec/ks/debug_array_user.kst b/spec/ks/debug_array_user.kst new file mode 100644 index 000000000..96cfda06a --- /dev/null +++ b/spec/ks/debug_array_user.kst @@ -0,0 +1,12 @@ +id: debug_array_user +data: fixed_struct.bin +debug: true +asserts: + - actual: one_cat.meow + expected: 0x50 + - actual: array_of_cats[0].meow + expected: 0x41 + - actual: array_of_cats[1].meow + expected: 0x43 + - actual: array_of_cats[2].meow + expected: 0x4b \ No newline at end of file diff --git a/spec/ks/debug_switch_user.kst b/spec/ks/debug_switch_user.kst index 01fec2e89..5a505e0d8 100644 --- a/spec/ks/debug_switch_user.kst +++ b/spec/ks/debug_switch_user.kst @@ -1,5 +1,6 @@ id: debug_switch_user data: nav_parent_switch.bin +debug: true asserts: - actual: code expected: 1 diff --git a/spec/lua/test_debug_array_user.lua b/spec/lua/test_debug_array_user.lua new file mode 100644 index 000000000..c1ab5c947 --- /dev/null +++ b/spec/lua/test_debug_array_user.lua @@ -0,0 +1,17 @@ +-- Autogenerated from KST: please remove this line if doing any edits by hand! + +local luaunit = require("luaunit") + +require("debug_array_user") + +TestDebugArrayUser = {} + +function TestDebugArrayUser:test_debug_array_user() + local r = DebugArrayUser:from_file("src/fixed_struct.bin") + r:_read() + + luaunit.assertEquals(r.one_cat.meow, 80) + luaunit.assertEquals(r.array_of_cats[0 + 1].meow, 65) + luaunit.assertEquals(r.array_of_cats[1 + 1].meow, 67) + luaunit.assertEquals(r.array_of_cats[2 + 1].meow, 75) +end diff --git a/spec/lua/test_debug_switch_user.lua b/spec/lua/test_debug_switch_user.lua index 2df402298..29f5eb7a5 100644 --- a/spec/lua/test_debug_switch_user.lua +++ b/spec/lua/test_debug_switch_user.lua @@ -1,4 +1,4 @@ --- runs in debug mode, so _read() needs to be called manually +-- Autogenerated from KST: please remove this line if doing any edits by hand! local luaunit = require("luaunit") diff --git a/spec/nim/tdebug_array_user.nim b/spec/nim/tdebug_array_user.nim new file mode 100644 index 000000000..c505d7f90 --- /dev/null +++ b/spec/nim/tdebug_array_user.nim @@ -0,0 +1,13 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import os, streams, options, sequtils +import ../../compiled/nim/debug_array_user +import auxiliary/test_utils + +let r = DebugArrayUser.fromFile("../../src/fixed_struct.bin") +r._read() + +assert r.oneCat.meow == 80 +assert r.arrayOfCats[0].meow == 65 +assert r.arrayOfCats[1].meow == 67 +assert r.arrayOfCats[2].meow == 75 diff --git a/spec/nim/tdebug_switch_user.nim b/spec/nim/tdebug_switch_user.nim index 4546c213e..9a4577a9c 100644 --- a/spec/nim/tdebug_switch_user.nim +++ b/spec/nim/tdebug_switch_user.nim @@ -5,6 +5,7 @@ import ../../compiled/nim/debug_switch_user import auxiliary/test_utils let r = DebugSwitchUser.fromFile("../../src/nav_parent_switch.bin") +r._read() assert r.code == 1 assert (DebugSwitchUser_One(r.data)).val == -190 diff --git a/spec/perl/TestDebugArrayUser.t b/spec/perl/TestDebugArrayUser.t new file mode 100644 index 000000000..c43940115 --- /dev/null +++ b/spec/perl/TestDebugArrayUser.t @@ -0,0 +1,21 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +package spec::perl::TestDebugArrayUser; + +use strict; +use warnings; +use base qw(Test::Class); +use Test::More; +use DebugArrayUser; + +sub test_debug_array_user: Test(4) { + my $r = DebugArrayUser->from_file('src/fixed_struct.bin'); + $r->_read(); + + is($r->one_cat()->meow(), 80, 'Equals'); + is(@{$r->array_of_cats()}[0]->meow(), 65, 'Equals'); + is(@{$r->array_of_cats()}[1]->meow(), 67, 'Equals'); + is(@{$r->array_of_cats()}[2]->meow(), 75, 'Equals'); +} + +Test::Class->runtests; diff --git a/spec/perl/TestDebugSwitchUser.t b/spec/perl/TestDebugSwitchUser.t index 959a22892..bb46050c5 100644 --- a/spec/perl/TestDebugSwitchUser.t +++ b/spec/perl/TestDebugSwitchUser.t @@ -10,6 +10,7 @@ use DebugSwitchUser; sub test_debug_switch_user: Test(2) { my $r = DebugSwitchUser->from_file('src/nav_parent_switch.bin'); + $r->_read(); is($r->code(), 1, 'Equals'); is($r->data()->val(), -190, 'Equals'); diff --git a/spec/php/DebugArrayUserTest.php b/spec/php/DebugArrayUserTest.php index 3aca51e52..2b2ed46e8 100644 --- a/spec/php/DebugArrayUserTest.php +++ b/spec/php/DebugArrayUserTest.php @@ -1,4 +1,6 @@ _read(); - $this->assertSame(0x50, $r->oneCat()->meow()); - $this->assertSame(0x41, $r->arrayOfCats()[0]->meow()); - $this->assertSame(0x43, $r->arrayOfCats()[1]->meow()); - $this->assertSame(0x4b, $r->arrayOfCats()[2]->meow()); + $this->assertSame(80, $r->oneCat()->meow()); + $this->assertSame(65, $r->arrayOfCats()[0]->meow()); + $this->assertSame(67, $r->arrayOfCats()[1]->meow()); + $this->assertSame(75, $r->arrayOfCats()[2]->meow()); } } diff --git a/spec/php/DebugSwitchUserTest.php b/spec/php/DebugSwitchUserTest.php index 7ce3c58a6..812d3d92b 100644 --- a/spec/php/DebugSwitchUserTest.php +++ b/spec/php/DebugSwitchUserTest.php @@ -1,5 +1,5 @@ _read();") + } } override def runParseExpectError(exception: KSError): Unit = { cppImportList.addKaitai("kaitai/exceptions.h") runParseCommon1() - out.puts(s"$className* r = ${compiler.nullPtr};") - out.puts("BOOST_CHECK_THROW(") - out.inc - out.puts(s"r = new $className(&ks),") - out.puts(compiler.ksErrorName(exception)) - out.dec - out.puts(");") + if (spec.debug) { + out.puts(s"$className* r = new $className(&ks);") + out.puts("BOOST_CHECK_THROW(") + out.inc + out.puts("r->_read(),") + out.puts(compiler.ksErrorName(exception)) + out.dec + out.puts(");") + } else { + out.puts(s"$className* r = ${compiler.nullPtr};") + out.puts("BOOST_CHECK_THROW(") + out.inc + out.puts(s"r = new $className(&ks),") + out.puts(compiler.ksErrorName(exception)) + out.dec + out.puts(");") + } } def runParseCommon1(): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaSG.scala index fe56d3e65..200c93942 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaSG.scala @@ -54,6 +54,9 @@ class JavaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( val needsFinal = spec.asserts.exists(assert => assert.isInstanceOf[TestException]) val finalKeyword = if (needsFinal) "final " else "" out.puts(s"${finalKeyword}$className r = $className.fromFile(SRC_DIR + " + "\"" + spec.data + "\");") + if (spec.debug) { + out.puts("r._read();") + } } override def footer(): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaScriptSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaScriptSG.scala index 18ebfc54a..566d29ff7 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaScriptSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/JavaScriptSG.scala @@ -27,6 +27,9 @@ class JavaScriptSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGene val entryClass = JavaScriptCompiler.type2class(entry) out.puts(s"var $entryClass = require('$entryClass').$entryClass;") } + if (spec.debug) { + out.puts("r._read();") + } } override def runParseExpectError(exception: KSError): Unit = { @@ -34,6 +37,9 @@ class JavaScriptSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGene importList.add("KaitaiStream") out.puts(s"testHelperThrows('$className', 'src/${spec.data}', ${JavaScriptCompiler.ksErrorName(exception)});") + if (spec.debug) { + out.puts("r._read();") + } } override def footer(): Unit = if (spec.exception.isEmpty) { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/LuaSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/LuaSG.scala index 6e26760e4..2821f381d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/LuaSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/LuaSG.scala @@ -31,6 +31,9 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s override def runParse(): Unit = { out.puts(s"""local r = $className:from_file("src/${spec.data}")""") + if (spec.debug) { + out.puts("r:_read()") + } } override def runParseExpectError(exception: KSError): Unit = { @@ -40,7 +43,12 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s case EndOfStreamError => "requested %d+ bytes, but only %d+ bytes available" case _ => LuaCompiler.ksErrorName(exception) } - out.puts(s"""luaunit.assertErrorMsgMatches(".+: $msg", $className.from_file, $className, "src/${spec.data}")""") + if (spec.debug) { + out.puts(s"""local r = $className:from_file("src/${spec.data}")""") + out.puts(s"""luaunit.assertErrorMsgMatches(".+: $msg", r.read, r")""") + } else { + out.puts(s"""luaunit.assertErrorMsgMatches(".+: $msg", $className.from_file, $className, "src/${spec.data}")""") + } } override def footer(): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/NimSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/NimSG.scala index b514e7f11..084ac0082 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/NimSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/NimSG.scala @@ -20,7 +20,10 @@ class NimSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s // Members declared in io.kaitai.struct.testtranslator.specgenerators.BaseGenerator override def fileName(name: String): String = s"t${spec.id}.nim" override def header(): Unit = { - out.puts(s"let r = ${className}.fromFile" + "(\"../../src/" + spec.data + "\")") + out.puts(s"let r = ${className}.fromFile(\"../../src/${spec.data}\")") + if (spec.debug) { + out.puts("r._read()") + } } override def footer(): Unit = { } override def nullAssert(actual: expr): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PHPSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PHPSG.scala index ba3cc25a4..8bbcb6bbb 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PHPSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PHPSG.scala @@ -26,6 +26,9 @@ class PHPSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s override def runParse(): Unit = { out.puts(s"$$r = $className::fromFile(self::SRC_DIR_PATH . '/${spec.data}');") + if (spec.debug) { + out.puts("$r->_read();") + } } override def runParseExpectError(exception: KSError): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PerlSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PerlSG.scala index d1a47624e..3299e58f1 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PerlSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PerlSG.scala @@ -31,6 +31,9 @@ class PerlSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def runParse(): Unit = { out.puts(s"my $$r = $className->from_file('src/${spec.data}');") + if (spec.debug) { + out.puts("$r->_read();") + } } override def runParseExpectError(exception: KSError): Unit = { @@ -38,7 +41,11 @@ class PerlSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( case UndecidedEndiannessError => "Unable to decide on endianness" case EndOfStreamError => "Requested \\d+ bytes, but only \\d+ bytes available" } - out.puts(s"""throws_ok { $className->from_file('src/${spec.data}') } '/^$msg/';""") + out.puts("throws_ok {") + out.inc + runParse() + out.dec + out.puts(s"""} '/^$msg/';""") } override def footer(): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PythonSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PythonSG.scala index dcfd50b76..37ccb97c3 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PythonSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/PythonSG.scala @@ -34,6 +34,9 @@ class PythonSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerato override def runParse(): Unit = { out.puts(s"with $className.from_file('src/${spec.data}') as r:") out.inc + if (spec.debug) { + out.puts("r._read()") + } } override def runParseExpectError(exception: KSError): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RubySG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RubySG.scala index 4b6c87066..d9c1c06b9 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RubySG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RubySG.scala @@ -27,6 +27,9 @@ class RubySG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def runParse(): Unit = { out.puts(s"r = $className.from_file('src/${spec.data}')") + if (spec.debug) { + out.puts("r._read") + } } override def runParseExpectError(exception: KSError): Unit = { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 4cfd6136c..64e535ad6 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -18,7 +18,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( out.puts("extern crate kaitai_struct;") out.puts(s"extern crate rust;") out.puts - + out.puts("use kaitai_struct::KaitaiStruct;") out.puts(s"use rust::$className;") out.puts @@ -29,6 +29,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( out.puts("if let Ok(r) = " + className + "::from_file(\"src/" + spec.data + "\") {") out.inc + if (spec.debug) { + out.puts("r.read().expect(\"cannot read test file\");") + } } override def footer(): Unit = {