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

Rust tests #96

Merged
merged 211 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
7a43396
redesign adn adapt rust's generation
revitalyr Jul 19, 2022
999209f
compiled *.ksy from `formats\`
revitalyr Jul 21, 2022
8d92a83
runParseExpectError, finish_panic
revitalyr Jul 21, 2022
ed9d309
genereated from .kst
revitalyr Jul 21, 2022
7152ca2
standard rust structure
revitalyr Jul 22, 2022
5bc4021
standard rust structure
revitalyr Jul 22, 2022
1377aaf
`--force` stores value in `config.outDir`
revitalyr Jul 24, 2022
e0ca664
`crate::formats` instead of `crate::rust`
revitalyr Jul 24, 2022
80deccf
`doTestSpec(..., exactOutDir: Boolean)`
revitalyr Jul 24, 2022
a4fdb7a
gen formats for rust lang only.
Agile86 Jul 27, 2022
27cccd4
gen tests for rust-only and more.
Agile86 Jul 27, 2022
970d47d
run-rust added.
Agile86 Jul 27, 2022
f3e3c86
formats_rust/ dir added.
Agile86 Jul 27, 2022
f13f031
rust updated.
Agile86 Jul 27, 2022
20b8f54
gitignore updated.
Agile86 Jul 27, 2022
905f1f2
rust testtranslator updated.
Agile86 Jul 27, 2022
38a284e
update files if formats dir were changed.
Agile86 Jul 27, 2022
fe40ee2
make specKsDir and formatsDir fields
revitalyr Jul 27, 2022
91d513d
make simple enums working
revitalyr Jul 27, 2022
af75728
if source path isAbsolute() modify `baseDir`
revitalyr Jul 27, 2022
6e591c3
edition = "2021"
revitalyr Jul 27, 2022
475e031
tests' list
revitalyr Jul 27, 2022
49f14b3
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
revitalyr Jul 27, 2022
4b635c1
disable useless warnings for generated code.
Agile86 Jul 28, 2022
a9703e5
disabling of warnings moved to mod.rs
Agile86 Jul 28, 2022
e2f5800
formatting issue fixed.
Agile86 Jul 28, 2022
4461d38
valid_* tests added.
Agile86 Jul 28, 2022
ec00ad1
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
Agile86 Jul 28, 2022
ee619c9
changes reverted.
Agile86 Jul 28, 2022
d3a920b
not verbose to see exceptions
revitalyr Aug 1, 2022
1155e10
./spec_kst_to_all -f ../$EXIST_TESTS_DIR ...
revitalyr Aug 1, 2022
a532706
some enums
revitalyr Aug 1, 2022
6e78944
handle only '*.ksy' files.
Agile86 Aug 2, 2022
f3147a4
new test expr_2 added.
Agile86 Aug 2, 2022
48002dc
parent as option updated.
Agile86 Aug 2, 2022
040084d
tests updated with latest generator.
Agile86 Aug 5, 2022
e3e28af
getSG(..., classSpecs)
revitalyr Aug 7, 2022
262e0a0
add `?` if `attr` is an `instance`
revitalyr Aug 7, 2022
a1b3062
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
revitalyr Aug 7, 2022
8af7899
new tests added (expr_array, float_to_i, floating_points).
Agile86 Aug 8, 2022
998fc6d
correct instance calling (with io).
Agile86 Aug 8, 2022
85f94a0
deref attr depend on type of attr.
Agile86 Aug 8, 2022
11a047b
use translator.detectType(...) to correct references
revitalyr Aug 8, 2022
de7efcd
_parent tests.
Agile86 Aug 9, 2022
c65e653
root test.
Agile86 Aug 9, 2022
7fff527
expr_bytes_cmp test.
Agile86 Aug 9, 2022
57b1ea6
expr_bytes_non_literal added.
Agile86 Aug 9, 2022
21face2
adjust actStr and expStr according their types
revitalyr Aug 9, 2022
a10e6cc
up to date
revitalyr Aug 9, 2022
0c1f3ec
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
revitalyr Aug 9, 2022
6abca99
tests autogeneration fixed (edited tests commited).
Agile86 Aug 10, 2022
9e05011
new tests added.
Agile86 Aug 11, 2022
b5d369f
add `CLIOptions::unitTest`
revitalyr Aug 11, 2022
3624f5e
process `extraImports`, correct enums' comparison,
revitalyr Aug 11, 2022
96eec22
new tests added.
Agile86 Aug 12, 2022
af31e78
ref/deref fixed.
Agile86 Aug 12, 2022
2ccb7d6
options commented, ref for enum fixed.
Agile86 Aug 12, 2022
bf94932
renamed.
Agile86 Aug 12, 2022
1f3124c
more tests.
Agile86 Aug 12, 2022
26ae9b6
doTestSpec(..., options: CLIOptions), remove some warnings
revitalyr Aug 12, 2022
1395c62
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
revitalyr Aug 12, 2022
228e82a
use `options`
revitalyr Aug 12, 2022
25a93f4
deref enums
revitalyr Aug 17, 2022
3db8818
combine tests added.
Agile86 Aug 18, 2022
05ec148
small fixes with enum ref.
Agile86 Aug 18, 2022
ea400c7
more tests added.
Agile86 Aug 20, 2022
6a88157
params test added.
Agile86 Aug 24, 2022
2d3408f
catch params.
Agile86 Aug 24, 2022
fa55096
position tests.
Agile86 Aug 25, 2022
ef2017c
more tests.
Agile86 Aug 25, 2022
71288f4
docref tests added.
Agile86 Aug 25, 2022
3b39506
eos/eof tests.
Agile86 Aug 25, 2022
bc82289
params_def test.
Agile86 Aug 25, 2022
fbee8d9
deref for (EnumType, IntType)
revitalyr Aug 25, 2022
eb9d23f
working tests
revitalyr Aug 25, 2022
d8df75e
Merge branch 'tuning_kst_generation' of https://github.com/Agile86/ka…
revitalyr Aug 25, 2022
2d270d2
enum_import need to be fixed (removed).
Agile86 Aug 27, 2022
e344dfd
added fixed version of test_enum_for_unknown_id.
Agile86 Sep 1, 2022
75da8a1
manually edited test_enum_invalid added.
Agile86 Sep 1, 2022
7c29480
expr_mod test.
Agile86 Sep 1, 2022
4e19b3f
expr_ops_parens tests.
Agile86 Sep 1, 2022
257821f
expr_enum tests.
Agile86 Sep 2, 2022
e7343c8
expr_sizeof_type_0 tests.
Agile86 Sep 2, 2022
0660cac
new tests.
Agile86 Sep 2, 2022
7bd569b
expr_str_encodings test.
Agile86 Sep 3, 2022
a73feb1
more tests.
Agile86 Sep 4, 2022
ab903f2
index_ tests.
Agile86 Sep 4, 2022
817d419
workaround for `test_enum_to_i_class_border_1`
revitalyr Sep 6, 2022
a196cbf
Merge remote-tracking branch 'origin/tuning_kst_generation' into tuni…
revitalyr Sep 6, 2022
164c180
repeat_until_ tests.
Agile86 Sep 9, 2022
609c05a
instance tests.
Agile86 Sep 15, 2022
4e05090
instance_user_array test.
Agile86 Sep 16, 2022
14da7b5
root arg restored for instaince methods.
Agile86 Sep 18, 2022
b4510b6
integer tests.
Agile86 Sep 18, 2022
dbc7474
more tests.
Agile86 Sep 22, 2022
5056595
test_switch_repeat_expr + expr_invalid added.
Agile86 Sep 23, 2022
7ebd02f
no test for this ksy-file.
Agile86 Sep 23, 2022
6a2768b
type_ternery_2nd_falsy.
Agile86 Sep 23, 2022
a68e8e3
switch_manual_enum
Agile86 Sep 23, 2022
d1bfa23
zlib tests.
Agile86 Sep 23, 2022
ed5599c
import tests.
Agile86 Sep 24, 2022
bad8a9b
imports_circular tests.
Agile86 Sep 24, 2022
95dce05
mod formats dup fixed.
Agile86 Sep 24, 2022
fc07a97
test fixed.
Agile86 Sep 24, 2022
dfb69ce
bits tests.
Agile86 Oct 1, 2022
cd4d4c5
endian tests.
Agile86 Oct 5, 2022
9d7531d
debug tests.
Agile86 Oct 6, 2022
d5a6cb1
more bit tests.
Agile86 Oct 6, 2022
bf56de5
test renamed.
Agile86 Oct 6, 2022
79fbd14
more tests.
Agile86 Oct 10, 2022
3b2397f
process_custom tests.
Agile86 Oct 11, 2022
fa028be
leave custom files.
Agile86 Oct 11, 2022
84b47b7
custom helper files added.
Agile86 Oct 11, 2022
1166801
process_repeat_bytes test.
Agile86 Oct 11, 2022
a6861f1
process_repeat_usertype test.
Agile86 Oct 11, 2022
eceb69b
opaque_with_param test.
Agile86 Oct 11, 2022
ab593f1
enums now closer to c++-enums.
Agile86 Oct 12, 2022
da82e61
switch_manual_enum_invalid* tests.
Agile86 Oct 12, 2022
e72f1e4
opaque tests.
Agile86 Oct 13, 2022
ed41543
2 more tests.
Agile86 Oct 16, 2022
c4a5e7a
to_string_custom added.
Agile86 Oct 21, 2022
cc89289
more parent tests.
Agile86 Nov 14, 2022
b71797d
nested_types tests.
Agile86 Nov 16, 2022
82ceb4b
more enum tests.
Agile86 Nov 17, 2022
ae144e5
switch_manual_int_size_eos restored to original.
Agile86 Nov 18, 2022
7fea25f
support of cp437 added.
Agile86 Nov 21, 2022
9b020eb
nested_type_param test added.
Agile86 Nov 21, 2022
126849e
valid_eq_str_encodings tests.
Agile86 Nov 21, 2022
e135f9b
cast_to_imported test added.
Agile86 Nov 24, 2022
f70ab09
Merge remote-tracking branch 'upstream/master' into tuning_kst_genera…
Agile86 Nov 25, 2022
b8abb6f
tests updated.
Agile86 Dec 27, 2022
d1be957
tests fixed.
Agile86 Dec 27, 2022
2cf0d5d
fix need_deref func.
Agile86 Dec 27, 2022
56f3c57
test generation fixed.
Agile86 Dec 31, 2022
0af9ee1
tests updated.
Agile86 Jan 4, 2023
56cd540
let need_deref do all job.
Agile86 Jan 4, 2023
89c99ab
no useless warnings in autogenerated tests.
Agile86 Jan 6, 2023
8aa4975
test_debug_switch_user now autogenerated.
Agile86 Jan 7, 2023
a94e37e
now this test autogenerated.
Agile86 Jan 10, 2023
43a677c
test generation: less warnings.
Agile86 Jan 12, 2023
1d67954
new autogenerated test nav_parent_vs_value_inst added.
Agile86 Jan 13, 2023
4035052
new tests enum_to_i_class_border_1, enum_to_i_class_border_2 added.
Agile86 Jan 19, 2023
b921faa
imports_abs test added.
Agile86 Jan 24, 2023
edc7db5
imports0 added.
Agile86 Jan 24, 2023
8c09d83
allow(overflowing_literals)
Agile86 Jan 26, 2023
7663786
yaml_ints added.
Agile86 Jan 26, 2023
801e04d
recursive_one added.
Agile86 Jan 26, 2023
b3f4b87
tests updated after changes in BytesReader interface.
Agile86 Jan 30, 2023
91f2bd7
io_local_var/io_local_var2 tests.
Agile86 Jan 30, 2023
f08bf90
support .as
Agile86 Feb 1, 2023
6f91d04
switch_cast restored to full test.
Agile86 Feb 1, 2023
1ee5782
cast_nested, cast_to_top, nav_parent2, nav_parent3.
Agile86 Feb 2, 2023
79fb0f3
nav_parent_override.
Agile86 Feb 2, 2023
4ca74bb
more test autogenerated.
Agile86 Feb 2, 2023
1b96b14
useless tests (only from formats_rust) removed.
Agile86 Feb 2, 2023
0522e2e
use importList for global imports.
Agile86 Feb 3, 2023
a2b2421
floating_points test fixed.
Agile86 Feb 5, 2023
0393f87
js_signed_right_shift added.
Agile86 Feb 5, 2023
61e52b7
Rc -> OptRc
Agile86 Feb 9, 2023
8603968
Added rounding to elapsed time to 0.1s to reduce test result diffs
GreyCat Jul 30, 2022
708fc59
Translator: update to consume 0.11-SNAPSHOT compiler
GreyCat Aug 1, 2022
f62f042
Translator: update with zeroCopySubstream to make compatible with mod…
GreyCat Aug 1, 2022
59ead53
Even better nonlatin
GreyCat Aug 7, 2022
a4554a0
Added many_type_validator.ksy: test multiple errors on type validatio…
GreyCat Aug 7, 2022
71fb201
meta_bad_key.ksy: fix error message, adding ks-zero-copy-substream
GreyCat Aug 7, 2022
01f0d3f
attr_invalid_switch_inner.ksy: should only report 1 problem on `/seq/…
GreyCat Aug 7, 2022
583d73a
Added type_unknown_many, showcasing several problems detected in one …
GreyCat Aug 7, 2022
ac2c49e
Merge remote-tracking branch 'origin/master' into rust_basic_support_v2
Agile86 Mar 11, 2023
6e1938a
autogenerated rust tests added.
Agile86 Mar 14, 2023
80ae4f2
use formats that's generated by script.
Agile86 Mar 14, 2023
8208031
don't copy generated formats, that we don't support yet.
Agile86 Mar 14, 2023
aa1d4ed
revert.
Agile86 Mar 14, 2023
da1ffc1
rust formats dir moved.
Agile86 Dec 19, 2023
4a90df8
Merge branch 'master' of https://github.com/kaitai-io/kaitai_struct_t…
Agile86 Feb 16, 2024
0e6254d
Merge branch 'master' into rust_basic_support_v2
generalmimon Apr 17, 2024
90f6893
Revert "`--force` stores value in `config.outDir`"
generalmimon Apr 17, 2024
3719400
Revert "add `CLIOptions::unitTest`", remove its use
generalmimon Apr 17, 2024
c188652
Revert "doTestSpec(..., options: CLIOptions), remove some warnings"
generalmimon Apr 17, 2024
0ad0169
Revert "if source path isAbsolute() modify `baseDir`"
generalmimon Apr 17, 2024
2f3c1a5
Revert "`doTestSpec(..., exactOutDir: Boolean)`"
generalmimon Apr 17, 2024
0ce1363
Revert "make specKsDir and formatsDir fields"
generalmimon Apr 17, 2024
5cd2021
RustSG: generate into `spec/rust/tests/` to match existing specs
generalmimon Apr 17, 2024
2cdfecb
translator/project/build.properties: fix missing final newline
generalmimon Apr 18, 2024
b2b942f
partial_builder: change `create_project` to return `Array<String>`
generalmimon Apr 21, 2024
5e25ef0
Rust: add partial builder, fully implement ci-rust
generalmimon May 5, 2024
6825a33
rust_builder: don't use `--cargo-quiet` when building tests
generalmimon May 6, 2024
1e0517b
move generated tests from base dir to tests subdir.
Agile86 Jun 24, 2024
58aff8e
Revert "move generated tests from base dir to tests subdir."
generalmimon Aug 31, 2024
53e984b
Merge branch 'master' into rust_basic_support_v2
generalmimon Aug 31, 2024
17f73ff
Rust: delete misplaced `spec/rust/*.rs` files
generalmimon May 6, 2024
64aaeed
rust_builder: add test for errors in macro expansions
generalmimon May 8, 2024
dcf7f0c
rust_builder: fix error location detection w.r.t. macro expansion
generalmimon May 8, 2024
d3aecb8
RustSG: simplify by adding support for `?` to handle errors
generalmimon May 8, 2024
8bdfd0c
RustSG: fix nullAssert()
generalmimon Jun 29, 2024
496dd50
RustSG: fix whitespace in generated specs
generalmimon May 9, 2024
b7550ee
RustSG: stop generating `allow` attrs, move them to `spec.rs`
generalmimon Jul 1, 2024
b0bd33e
RustSG: remove unused and flawed text replacements
generalmimon Jul 2, 2024
b338273
Rust: remove incorrect "Autogenerated" comments
generalmimon Jun 30, 2024
16d44c9
Rust: regen positive tests from KST
generalmimon May 10, 2024
5e0eaba
Rust: normalize specs not autogenerated from KST
generalmimon Jun 29, 2024
bf66bbe
Rust: don't suppress the `overflowing_literals` error
generalmimon Jul 1, 2024
04358b9
Rust: delete specs of old removed tests
generalmimon Jul 1, 2024
e1a79bc
Rust: regen recently added positive tests from KST
generalmimon Jul 2, 2024
78b406e
Port NestedTypesImport to Rust
generalmimon Jul 2, 2024
a4d569b
Rust: adapt custom decoders to runtime library changes
generalmimon Sep 1, 2024
855697d
RustSG: add support for asserting specific errors
generalmimon Sep 1, 2024
680639f
Rust: regen negative tests from KST
generalmimon Sep 1, 2024
9cac8ca
Port StrEncodingsEscaping{Enc,ToS} to Rust
generalmimon Sep 1, 2024
42ed477
Rust: print the outputs of failed tests only at the end
generalmimon Sep 1, 2024
5789f07
rust_builder: more reliable recovery from build errors
generalmimon Sep 2, 2024
02cfdee
ci-rust: prepare for running in a Docker container
generalmimon Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ __pycache__/
_*
spec/nim/bin

# Rust compiled code, cargo and rls data
# Rust

## Cargo lockfile and build cache
spec/rust/Cargo.lock
spec/rust/target/

## Files auto-generated by builder/rust_builder.rb
spec/rust/tests/spec.rs
spec/rust/src/formats.rs
10 changes: 8 additions & 2 deletions aggregate/convert_to_json
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,19 @@ when 'java'
),
infile
)
when 'rust'
add_kst_adoption(
reports_to_h(
JUnitXMLParser.new("#{infile}/report.xml"),
BuildFailedParser.new("#{infile}/build_failed_tests.txt")
),
infile
)
when 'lua', 'nim'
add_kst_adoption(
reports_to_h(JUnitXMLParser.new("#{infile}/report.xml")),
infile
)
when 'rust'
reports_to_h(JUnitXMLParser.new(infile))
when 'go', 'perl', 'python', 'construct', 'julia'
add_kst_adoption(
reports_to_h(JUnitXMLParser.new("#{infile}/report.xml")),
Expand Down
3 changes: 3 additions & 0 deletions aggregate/junit_xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def each_test
elsif name =~ /^t(?!est)(.*?)$/
# Nim output
name = underscore_to_ucamelcase($1)
elsif name =~ /^test_.*::test_(.*?)$/
# Rust output
name = underscore_to_ucamelcase($1)
elsif tc.attribute('classname') and tc.attribute('classname').value =~ /^\/(.*?) test$/
# Julia output
name = $1
Expand Down
2 changes: 1 addition & 1 deletion builder/cpp_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create_project(mand_files, disp_files)
(mand_files + disp_files).each { |l| f.puts(l) }
f.puts(")")
}
@disposable_cmake
[@disposable_cmake]
end

def build_project(log_file)
Expand Down
2 changes: 1 addition & 1 deletion builder/csharp_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create_project(mand_files, disp_files)
files_xml = (mand_files + disp_files).map { |x| " <Compile Include=\"#{x}\" />" }.join("\n")
project = tmpl.gsub(/%%%FILES%%%/, files_xml)
File.write(@project_file, project)
@project_file
[@project_file]
end

def build_project(log_file)
Expand Down
2 changes: 1 addition & 1 deletion builder/java_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_project(mand_files, disp_files)
File.open(@project_file, 'w') { |f|
(mand_files + disp_files).each { |l| f.puts "\"#{l}\"" }
}
@project_file
[@project_file]
end

def build_project(log_file)
Expand Down
12 changes: 7 additions & 5 deletions builder/partial_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def command_line(arg)
l1 = list_mandatory_files
l2 = list_disposable_files
log "creating project with #{(l1 + l2).size} files"
fn = create_project(l1, l2)
log "project file created: #{fn.inspect}"
fns = create_project(l1, l2)
log "project files created: #{fns.inspect}"
elsif arg == ['--once']
@max_attempts = 1
exit run
Expand Down Expand Up @@ -78,8 +78,8 @@ def partial_build
attempt_str = @max_attempts ? "#{attempt}/#{@max_attempts}" : attempt

log "creating project with #{disp_files.size}/#{orig_size} files"
fn = create_project(mand_files, disp_files)
log "project file created: #{fn.inspect}"
fns = create_project(mand_files, disp_files)
log "project files created: #{fns.inspect}"

build_log = "#{@test_out_dir}/build-#{attempt}.log"
log "build attempt #{attempt_str} (log: #{build_log})"
Expand Down Expand Up @@ -215,7 +215,9 @@ def list_disposable_files

# Creates a project file, given a list of disposable and mandatory
# files to include in it.
# @return [String] project file name created
# @param mand_files [Enumerable<String>] collection of mandatory files
# @param disp_files [Enumerable<String>] collection of disposable files
# @return [Array<String>] project file names created
def create_project(mand_files, disp_files)
raise NotImplementedError
end
Expand Down
226 changes: 226 additions & 0 deletions builder/rust_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
require 'fileutils'
require 'set'
require 'json'

require_relative 'partial_builder'
require_relative 'shellconfig'

class RustBuilder < PartialBuilder
def initialize
super

base_spec_dir = 'spec/rust'
@base_spec_dir = File.absolute_path(base_spec_dir)

@spec_dir = File.join(@base_spec_dir, 'tests')
@formats_dir = File.join(@base_spec_dir, 'src/formats')
@spec_list_file = File.join(@base_spec_dir, 'tests/spec.rs')
@formats_list_file = File.join(@base_spec_dir, 'src/formats.rs')

test_out_dir = File.join(@config['TEST_OUT_DIR'], 'rust')
@test_out_dir = File.absolute_path(test_out_dir)
end

def list_mandatory_files
[]
end

def list_disposable_files
spec_basenames = Dir.glob('test_*.rs', base: @spec_dir)
format_basenames = Dir.glob('*.rs', base: @formats_dir)

spec_basenames.map { |fn| File.join(@spec_dir, fn) } +
format_basenames.map { |fn| File.join(@formats_dir, fn) }
end

def create_project(mand_files, disp_files)
grouped_files = mand_files.chain(disp_files).group_by { |fn| file_to_kind(fn) }
if grouped_files.key?(nil)
raise "unexpected files that are neither ':spec' or ':format': #{grouped_files[nil].inspect}"
end

File.open(@spec_list_file, 'w') { |f|
f.puts '#![allow(unused_variables)]'
f.puts '#![allow(unused_assignments)]'
grouped_files[:spec].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" }
}
File.open(@formats_list_file, 'w') { |f|
f.puts '#![allow(unused_parens)]'
f.puts '#![allow(dead_code)]'
grouped_files[:format].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" }
}
[@spec_list_file, @formats_list_file]
end

def build_project(log_file)
Dir.chdir(@base_spec_dir) do
# We don't use `cargo check` here (which would seem like a more logical
# choice) because unfortunately it doesn't report all build errors, see
# https://doc.rust-lang.org/cargo/commands/cargo-check.html#description:
#
# > Some diagnostics and errors are only emitted during code generation,
# > so they inherently won't be reported with `cargo check`.
cli = %w[cargo test --no-run --test spec --message-format json]
run_cargo_build({}, cli, log_file).exitstatus
end
end

def parse_failed_build(log_file)
list = []

File.open(log_file, 'r') { |f|
f.each_line { |line|
line.chomp!
# See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
cargo_msg = JSON.parse(line)

# See https://doc.rust-lang.org/cargo/reference/external-tools.html#build-finished:
# > The "build-finished" message is emitted at the end of the build.
#
# > This message can be helpful for tools to know when to stop reading JSON messages.
break if cargo_msg['reason'] == 'build-finished'

next unless cargo_msg['reason'] == 'compiler-message'

# See https://doc.rust-lang.org/rustc/json.html
rustc_msg = cargo_msg['message']
next unless rustc_msg['$message_type'] == 'diagnostic'
next unless rustc_msg['level'] == 'error'

files =
select_rustc_msg_culprit_spans(rustc_msg['spans'])
.map { |span| File.absolute_path(span['file_name'], @base_spec_dir) }

list.concat(files)
}
}

list
end

def file_to_test(path)
kind = file_to_kind(path)
basename = File.basename(path, '.rs')
test_name = kind == :spec ? basename.delete_prefix('test_') : basename
[kind, underscore_to_ucamelcase(test_name)]
end

def run_tests
Dir.chdir(@base_spec_dir) do
cli = %w[cargo nextest run --test spec]
out_log = File.join(@test_out_dir, 'test_run.stdout')
run_and_tee({}, cli, out_log)

# See spec/rust/.config/nextest.toml
src_path = File.join(@base_spec_dir, 'target/nextest/default/junit.xml')
dest_path = File.join(@test_out_dir, 'report.xml')
FileUtils.copy_file(src_path, dest_path)
true
end
end

private

def select_rustc_msg_culprit_spans(spans)
primary_spans =
spans
.select { |span| span['is_primary'] }
.map do |span|
span = span['expansion']['span'] until span['expansion'].nil?
span
end
primary_spans.uniq { |span| span['file_name'] }
end

def file_to_kind(path)
if path_directly_in_dir?(path, @spec_dir)
:spec
elsif path_directly_in_dir?(path, @formats_dir)
:format
end
end

def run_cargo_build(environment, cmd, stdout_file)
log "running command: #{cmd.inspect}, log: #{stdout_file.inspect}"
process_status = nil
FileUtils.mkdir_p(File.dirname(stdout_file))
File.open(stdout_file, 'w') { |f|
Open3.popen3(environment, *cmd) { |_stdin, stdout, _stderr, wait_thread|
while (line = stdout.gets)
line.chomp!
line_summary = summarize_cargo_json_line(line)
puts line_summary unless line_summary.nil?
f.puts line
end
process_status = wait_thread.value
}
}
log "process_status: #{process_status.inspect}"
process_status
end

def summarize_cargo_json_line(line)
begin
# See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
cargo_msg = JSON.parse(line)
rescue JSON::ParserError => e
warn e.full_message
return line
end
reason = cargo_msg['reason']

case reason
when 'compiler-message'
# See https://doc.rust-lang.org/rustc/json.html
rustc_msg = cargo_msg['message']

if rustc_msg['$message_type'] == 'diagnostic'
files =
select_rustc_msg_culprit_spans(rustc_msg['spans'])
.map { |span| "#{span['file_name']}:#{span['line_start']}:#{span['column_start']}" }
code_appendix = rustc_msg['code'].nil? ? '' : "[#{rustc_msg['code']['code']}]"
files_prefix =
if files.empty?
''
else
"#{files.join(', ')}: "
end
"#{files_prefix}#{rustc_msg['level']}#{code_appendix}: #{rustc_msg['message']}"
else
line
end
when 'compiler-artifact', 'build-script-executed'
# "[#{reason}] #{cargo_msg['package_id']}"
nil
when 'build-finished'
"[#{reason}] success: #{cargo_msg['success']}"
else
line
end
end

# Returns +true+ if +path+ is directly contained in the +dir_abs_path+ directory, and
# +false+ otherwise.
#
# The +dir_abs_path+ argument is expected to be normalized as if returned by
# the +File.absolute_path+ method, i.e. directory parts in path separated only
# by +File::SEPARATOR+ (forward slash +/+ on all platforms) and never
# +File::ALT_SEPARATOR+ (backslash +\+ on Windows), multiple consecutive
# slashes collapsed into one, no useless dots (+./+ or +../+ parts), no
# trailing slash, etc.
# @param path [String] relative (to the current directory) or absolute path
# @param dir_abs_path [String] normalized absolute path of the directory
def path_directly_in_dir?(path, dir_abs_path)
abs_path = File.absolute_path(path)
dir_abs_path += File::SEPARATOR
return false unless abs_path.start_with?(dir_abs_path)

path_rel_to_dir = abs_path.delete_prefix(dir_abs_path)
path_basename = File.basename(abs_path)
path_rel_to_dir == path_basename
end

def underscore_to_ucamelcase(s)
s.split(/_/).map { |x| x.capitalize }.join
end
end
3 changes: 3 additions & 0 deletions builder/spec/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Cargo lockfile and build cache
*/spec/rust/Cargo.lock
*/spec/rust/target/
1 change: 1 addition & 0 deletions builder/spec/rust/macro_expansion/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST_OUT_DIR=test_out
9 changes: 9 additions & 0 deletions builder/spec/rust/macro_expansion/spec/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rust"
edition = "2018"
autotests = false

[dependencies]

[[test]]
name = "spec"
3 changes: 3 additions & 0 deletions builder/spec/rust/macro_expansion/spec/rust/src/formats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![allow(unused_parens)]
#![allow(dead_code)]
pub mod empty;
Empty file.
2 changes: 2 additions & 0 deletions builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[macro_export]
macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }
2 changes: 2 additions & 0 deletions builder/spec/rust/macro_expansion/spec/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod formats;
mod helpers;
1 change: 1 addition & 0 deletions builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod test_nested;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rust::our_assert_eq_wrapper;

#[test]
fn test_nested() {
// NOTE: This line intentionally triggers a "can't compare `{integer}` with `{float}`"
// error to check if RustBuilder recovers from it.
our_assert_eq_wrapper!(4, 2.5);
}
Loading